备份昨天文件夹中的文件

时间:2014-07-24 08:11:08

标签: bash shell solaris

我开发了以下脚本来gzip目录中的昨天文件,任何改进建议

Yesterday=`TZ=GMT+24 date +%d-%b-%y`;
mkdir $Yesterday
mv /tmp/logs/servicemix.log.* /tmp/logs/$Yesterday
for File in /tmp/logs/$Yesterday/app.log.*;
do gzip $File;
done

此致

3 个答案:

答案 0 :(得分:0)

使用以下代码行

TIME=`date +"%b-%d-%y"` # This Command will add date in Backup File Name.
now=$(date +"%T")
FILENAME="filename-$TIME:$now.tar.gz"      # Here i define Backup file name format.
SRCDIR="/home"              # Location of Important Data Directory (Source of backup).
DESDIR="/home/user/backup"     # Destination of backup file. 
tar -cpzf $DESDIR/$FILENAME $SRCDIR #creating backup as tar file
echo
echo "Backup finished"

答案 1 :(得分:0)

1.Replace

mkdir $Yesterday

通过

mkdir -p /tmp/logs/${Yesterday}
  1. gzip您移动的文件 当您移动servicemix *文件时,请不要gzip app * files

答案 2 :(得分:-1)

他们昨天改变或创造了吗?使用find和正确的修饰符。

Yesterday=`TZ=GMT+24 date +%d-%b-%y`;
mkdir $Yesterday

# -1 is equal to last 24 hours
# ctime is for last inode modified time. If you need creation date you need a different modifier. See attached link.
find -ctime -1 -exec mv '{}' "$yesterday/" \;

但是this is i think pretty much the best option: Use 'find' to determine files modified yesterday