原创

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

正文到此结束
本文目录