mysql5.7_xtraBackup_备份脚本

僤鯓⒐⒋嵵緔 提交于 2020-02-26 01:51:46

# 备份脚本XtraBackup.sh:

#!/bin/bash
# filename : XtraBackup.sh
# Author : 00000
day=date +%w
dt=date +%Y%m%d
lastday=date -d '1 days ago' +%Y%m%d
user=backupuser
log=backuplog.date +%Y%m%d

case $day in
0)
# Monday Relatively Sunday's incremental backup
sudo innobackupex --defaults-file=/etc/my.cnf --login-path=$user --no-timestamp --incremental --backup --incremental-basedir=/data/backup/xtrainc$lastday /data/backup/xtrainc$dt > /tmp/$log 2>&1
;;
1)
# Sunday Full backup
sudo find /data/backup/ -name "xtra_" -mtime +6 -exec rm -rf {} \;
sudo innobackupex --defaults-file=/etc/my.cnf --login-path=$user --no-timestamp --backup /data/backup/xtrabase$dt > /tmp/$log 2>&1
;;
2)
# Saturday Compared with Friday's incremental backup
sudo innobackupex --defaults-file=/etc/my.cnf --login-path=$user --no-timestamp --incremental --backup --incremental-basedir=/data/backup/xtrabase$lastday /data/backup/xtrainc$dt > /tmp/$log 2>&1
;;
3)
# Tuesday Compared with Monday's incremental backup
sudo innobackupex --defaults-file=/etc/my.cnf --login-path=$user --no-timestamp --incremental --backup --incremental-basedir=/data/backup/xtrainc$lastday /data/backup/xtrainc$dt > /tmp/$log 2>&1
;;
4)
# Friday Compared with Thursday's incremental backup
sudo innobackupex --defaults-file=/etc/my.cnf --login-path=$user --no-timestamp --incremental --backup --incremental-basedir=/data/backup/xtrainc$lastday /data/backup/xtrainc$dt > /tmp/$log 2>&1
;;
5)
# Wednesday Full backup
sudo find /data/backup/ -name "xtra_
" -mtime +6 -exec rm -rf {} \;
sudo innobackupex --defaults-file=/etc/my.cnf --login-path=$user --no-timestamp --backup /data/backup/xtrabase$dt > /tmp/$log 2>&1
;;
6)
# Thursday Relatively Wednesday's incremental backup
sudo innobackupex --defaults-file=/etc/my.cnf --login-path=$user --no-timestamp --incremental --backup --incremental-basedir=/data/backup/xtrabase$lastday /data/backup/xtrainc$dt > /tmp/$log 2>&1
;;
esac
sudo find /tmp -mtime +6 -type f -name 'backuplog.*' -exec rm -rf {} \;

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!