簡單的web備份指令碼
阿新 • • 發佈:2019-02-17
#!/bin/bash DATE=`date +%Y-%m-%d` day=5 #backsource=/data1/webdata backsource=/data1/webdata backuppath=/data1/backup/WebBackup webs="web1 web2 web3" if [ ! -d $backuppath ]; then mkdir -p $backuppath fi cd $backuppath backupname=Web_Backup_$DATE for web in $webs; do tar -C $backsource -zcvf $web.tar.gz $web if [ "$?" == "0" ] then echo "$DATE $web backuped" >> $backuppath/backupweb.log else echo "$DATE $web backup failed" >> $backuppath/backupweb.log exit 0 fi done tar -jcvf $backupname.tar.bz2 *.tar.gz if [ "$?" == "0" ] then echo "$DATE Packaging complete" >> $backuppath/backupweb.log else echo "$DATE Packaging failed" >> $backuppath/backupweb.log exit 0 fi rm -f *.tar.gz delname=Web_Backup_$(date -d "$day day ago" +%Y-%m-%d).tar.bz2 rm -f $delname