#=================================================
#EveryDay Backup Mysql and 7day delete tar
#var 0.2
#Date 2014/04/16
#=================================================
#backup Mysql by date
filename=$(date +%Y%m%d)
dirname=$(date +%Y%m)
mysqldump -u root -ppwd dbname --add-drop-table --add-locks > /dirname/$filename.sql
#tar filename
tar zcvf /dirname/$filename.tar.gz /dirname/$filename.sql
#remove filename.sql
rm -rf /dirname/$filename.sql
#delete 7day files
deldate=$(date -d ' 7 days ago' +%Y%m%d)
rm -rf /dirname/$deldate.tar.gz
沒有留言:
張貼留言