mysql 自动定时备份

MargaritaMc 9年前

来自: http://my.oschina.net/mellen/blog/635001


backup.sh

 

echo "======start备份并压缩=========="

dump_path="/jk/mysql_db_backup"

filename="$(date +"%Y-%m-%d_%H-%M-%S")"

mysqldump -h192.168.2.17 bda -uroot -p123456 | gzip > $dump_path/$filename.sql.gz

echo "======end==========="

ls mysql_db_backup

echo "======del删除30天前的备份=============="

find ./mysql_db_backup -mtime +30 -name “*.gz" -exec rm -rf {} \;

echo "=======end================"

 

 

设置定时任务:

vi /etc/crontab

01 1 * * * root /home/backup.sh

重启 service crond start