2014-07-24 103 views
-1

我制定以下腳本的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

你如何確保/tmp/logs/servicemix.log.*不會包含今天的文件? – JochenJung

+0

我會讓它在00:05工作 – ImranRazaKhan

回答

-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

+0

'-ctime'是改變時間。我認爲這是最好的選擇。 – RedX

+0

@ jm666這就是我寫的。改變時間...我不明白你的評論。 – RedX

+0

@ jm666這就是爲什麼我的答案中的第一行被更改或創建?如果創建時間比'ctime'有問題。你說得對。 – RedX

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" 
0

1.Replace

mkdir $Yesterday 

線用

mkdir -p /tmp/logs/${Yesterday} 
  • gzip壓縮你有文件移動了 當您移動servicemix * fil時es,不要gzip應用程序*文件