我制定以下腳本的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
問候
我制定以下腳本的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
問候
是他們改變或創建的昨天?使用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。
使用以下代碼
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.Replace
mkdir $Yesterday
線用
mkdir -p /tmp/logs/${Yesterday}
你如何確保/tmp/logs/servicemix.log.*不會包含今天的文件? – JochenJung
我會讓它在00:05工作 – ImranRazaKhan