壓縮備份
檔名加上日期
超過兩天自動刪除(自行修改範圍)
#/bin/bash # ================== 設定區 ===================================== user=account_name passwd=account_password back_path=back_dst_folder db_name=dbname # ================================================================= back_time=`date +%Y%m%d_%H%M%S` back_filename=$back_path$db_name$back_time del_time=`date -d "2 day ago" +"%Y%m%d"` del_backfile=$back_path$db_name$del_time mysqldump -u $user -p$passwd wordpress > $back_filename.bak tar -zcPf $back_filename.tar.gz $back_filename.bak rm -f $back_filename.bak if [ -e $back_filename.tar.gz ];then rm -rf $del_backfile*.gz echo "database[$db_name] backup success! " else echo "database[$db_name] backup failed!" fi