# 备份脚本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 {} \;