1.数据库全备
#!/bin/sh
v_user="root"
v_password="mysql"
backup_date=`date +%Y%m%d%H%M`
v_user="root"
v_password="mysql"
backup_date=`date +%Y%m%d%H%M`
MysqlDir=/usr/local/mysql/bin
BackupDir=/data/mysql
Full_Backup=$BackupDir/Full_backup
mkdir -p $Full_Backup/$backup_date
Full_Backup=$BackupDir/Full_backup
mkdir -p $Full_Backup/$backup_date
echo '========='$(date +"%Y-%m-%d %H:%M:%S")'=========='"BEGIN">>$Full_Backup/$backup_date/full_backup.log
$MysqlDir/mysqldump -u$v_user -p$v_password --single-transaction --flush-logs --all-databases>$Full_Backup/$backup_date/full_backup.sql
$MysqlDir/mysqldump -u$v_user -p$v_password --single-transaction --flush-logs --all-databases>$Full_Backup/$backup_date/full_backup.sql
gzip $Full_Backup/$backup_date/full_backup.sql
echo '=========='$(date +"%Y-%m-%d %H:%M:%S")'=========='"FINISH">>$Full_Backup/$backup_date/full_backup.log
echo '=========='$(date +"%Y-%m-%d %H:%M:%S")'=========='"FINISH">>$Full_Backup/$backup_date/full_backup.log
2.删除30天前备份文件
echo "`date +'%Y-%m-%d %H:%M:%S'` remove full_backup_files 30 days ago"|tee -a /data/mysql/remove_backup_files.log && find /data/mysql/Full_backup -name "full_backup.*" -mtime +30 -type f| tee -a /data/mysql/remove_backup_files.log | xargs rm -f 2>&1
3.定时任务设置
#每天1点定时执行全库备份
0 1 * * * /data/mysql/full_backup.sh
0 1 * * * /data/mysql/full_backup.sh
#每天1点30分定时删除30天前备份文件
30 1 * * * /data/mysql/remove_backup_files.sh
30 1 * * * /data/mysql/remove_backup_files.sh
参考链接:https://blog.csdn.net/songxixi/article/details/8787647?depth_1-utm_source=distribute.pc_relevant_right.none-task&utm_source=distribute.pc_relevant_right.none-task