码迷,mamicode.com
首页 > 数据库 > 详细

Crontab定时备份数据库

时间:2017-04-12 18:38:46      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:exec   database   ror   rms   erro   定时备份   local   color   div   

1.创建一个shell脚本文件

cd usr

mkdir dabackup

vim backup.sh

echo "-----------------------------" >> /usr/dbbackup/dbbackup.log
echo `date +%Y%m%d`"erms Database backup start" >> /usr/dbbackup/dbbackup.log
/usr/local/mysql/bin/msyqldump -uroot -ppwd erms >>/usr/dbbackup/backup_`date +%Y%m%d`.sql

if [ $? -eq 0 ];then
        if [ -f "/usr/dabackup/backup_`date +%Y%m%d`.sql"  ];then
     tar -czf /usr/dabackup/backup_`date +%Y%m%d`
echo `date +%Y%m%d`"erms Database backup success" >> /usr/dbbackup/dbbackup.log else echo `date +%Y%m%d`"erms Database backup fail!" >> /usr/dbbackup/dbbackup.log fi else echo `date +%Y%m%d`"erms Database backup error" >> /usr/dbbackup/dbbackup.log fi echo "-----------------------------" >> /usr/dbbackup/dbbackup.log find /usr/dbbackup/ -mtime +7 -name backup_\* -exec rm -rf {} \;

更改backup.sh文件权限 chmod 755 /usr/dabackup/backup.sh

2.添加到定时任务

每天凌晨3点半备份一次

crontab -e

30 3 * * * /usr/dbbackup/backup.sh

 

Crontab定时备份数据库

标签:exec   database   ror   rms   erro   定时备份   local   color   div   

原文地址:http://www.cnblogs.com/freelyflying/p/6700532.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!