mysql定时压缩备份及定时删除过时备份
备份及清理shell文件:
vi /app/backup/backupmysql.sh
#!/bin/sh
currdir=`pwd`
backupdir=$currdir/dump_his
currdate=`date +%Y%m%d`
echo "`date +%c` BACKUP BEGIN..." >> backup.log;
mysqldump --skip-lock-tables --single-transaction --flush-logs --hex-blob --master-data=2 -hIPaddress -P3306 -uroot -pXXX DATABASENAME > $backupdir/yqy$currdate.dump;
cd $backupdir
#tar dump
tar -cvf $currdate.tar *$currdate.dump;
gzip $currdate.tar;
rm -rf *$currdate.dump;
cd $currdir
#save dump for 15 days
find $backupdir -name "*.tar.gz" -type f -mtime +15 -exec rm -rf {} \;
echo "`date +%c` BACKUP SUCESS!" >> backup.log;
Centos:定时每天凌晨3天执行bakmysql.sh文件:
vi /var/spool/cron/root
0 3 * * * cd /app/backup;./bakmysql.sh > /dev/null 2&1
ubuntu18
vim /etc/crontab 定时每天下午3天30分执行backupmysql.sh文件:
30 15 * * * root cd /app/mysql/backup;./bakmysql.sh > /dev/null 2&1
正文到此结束
- 本文标签: 暂无相关标签
- 本文链接: https://www.jimmy2k.top/article/276
- 版权声明: 本文由JimmyZ的个人博客原创发布,转载请遵循《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》许可协议授权