編輯 腳本文件
[python]
1.db_user="root"
2.db_passwd="123456" 3.db_host="localhost" 4.backup_dir="/usr/local/apache2/htdocs/backup" 5.time="$(date +"%Y%m%d%H%M")" 6.MYSQL="/usr/local/mysql/bin/mysql" 7.MYSQLDUMP="/usr/local/mysql/bin/mysqldump" 8.MKDIR="/bin/mkdir" 9.RM="/bin/rm" 10.MV="/bin/mv" 11.GZIP="/bin/gzip" 12.test ! -w $backup_dir && echo "Error: $backup_dir is un-writeable." && exit 0 13.test ! -d "$backup_dir/$time" && $MKDIR -p "$backup_dir/$time" 14.all_db="$($MYSQL -u $db_user -h $db_host -p$db_passwd -Bse 'show databases')" 15.
16.for db in $all_db 17. do
18. $MYSQLDUMP "--default-character-set=gbk" -u $db_user -h $db_host -p$db_passwd $db | $GZIP -9 > "$backup_dir/$time/$db.gz" 19. done
20. exit 0; 設(shè)置定時任務(wù)
使用crontab -e命令編輯定時任務(wù)列表
[html]
1.15 3 * * * sh /usr/scripts/mysql_backup.sh
表示每天凌晨3點15分執(zhí)行該腳本進行數(shù)據(jù)庫備份 本文出自:億恩科技【mszdt.com】
服務(wù)器租用/服務(wù)器托管中國五強!虛擬主機域名注冊頂級提供商!15年品質(zhì)保障!--億恩科技[ENKJ.COM]
|