Crontab定时备份数据库
时间:2021-07-01 10:21:17
帮助过:14人阅读
"-----------------------------" >> /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