xtrabackup8.0周增量备份脚本
下面是脚本内容
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| #!/bin/bash yum -y install wget lrzsz >>/dev/null #今天 Date_today=$(date "+%w")
#昨天
Yester_day=$(date "+%w" -d '1 day ago')
#七天前
Sevendays_ago=$(date "+%w" -d '7 day ago')
#今天星期几 week=`date +%w` mysqluser="root" mysqlpass="123.Shui!!" mysqlcon=/etc/my.cnf host="192.168.224.11"
first=`date "+%Y-%m-%d"`
if [ $first = 2020-07-21 ];then yum install -y https://repo.percona.com/yum/percona-release-latest.noarch.rpm &>/dev/null percona-release enable-only tools release yum install -y percona-xtrabackup-80 qpress &> /dev/null
mkdir -p /mysqlbackup/{wanquan,zengliang}
fi
#判断今天是不是周日 如果是周日进行全量备份
if [ $week -eq 0 ];then
rm -rf /mysqlbackup/wanquan/$Sevendays_ago >>/dev/null
xtrabackup --backup --default-file=${mysqlcon} --target-dir=/mysqlbackup/wanquan/$Date_today --user=${mysqluser} --host=${host} --password=${mysqlpass} if [ $? -eq 0 ];then
rm -rf /mysqlbackup/zengliang/*
fi
else
dir=`ls /mysqlbackup/zengliang/ | wc -l | awk '{print $1}'`
if [ $dir -eq 0 ];then xtrabackup --backup --default-file=${mysqlcon} --target-dir=/mysqlbackup/zengliang/$Date_today --incremental-basedir=/mysqlbackup/wanquan/`ls /mysqlbackup/wanquan/` --user=${mysqluser} --host=${host} --password=${mysqlpass}
else xtrabackup --backup --default-file=${mysqlcon} --target-dir=/mysqlbackup/zengliang/$Date_today --incremental-basedir=/mysqlbackup/zengliang/${Yester_day} --user=${mysqluser} --host=${host} --password=${mysqlpass}
fi
fi
|
这脚本只适合本地安装本地备份,不适合docker安装的