我开发了以下脚本来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
此致
答案 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}
答案 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。