可以加在cortab 中在每天凌晨1点,备份打包一下MYSQL的数据库。
设定计划任务
-------------------------------------------------------------------------------------------------------------------------
#crontab -e
0 1 * * * /usr/local/src/backmysql.sh
-------------------------------------------------------------------------------------------------------------------------
backmysql.sh 的文件源码,可以配置备份目录。数据库名 mysqlhotcopy所在的目录,以及避免磁盘空间不足删除30日前的备份。
-------------------------------------------------------------------------------------------------------------------------
#!/bin/bash
# yum -y install perl-DBD-MySQL //if mysqlhotcopy can't be runing ,install it
backdir="/usr/local/backup/"
mysqlbindir="/usr/local/mysql/bin/"
backdatabase="cms"
keepdays=30
${mysqlbindir}mysqlhotcopy ${backdatabase} ${backdir}
tar zcvfP ${backdir}${backdatabase}_db_$(date +"%Y%m%d" --date="-1 day").tar ${backdir}${backdatabase}
rm -rf ${backdir}${backdatabase}
rm -rf ${backdir}${backdatabase}_db_$(date +"%Y%m%d" --date="-${keepdays} day").tar