Mysql-xtrabackup备份脚本

一个简单的脚本,仅供参考。谢谢!

#!/bin/bash
#*****************************************************************************************
#Author:xianglinboy
#Date:2020-05-01
#*****************************************************************************************
#定义目录变量
week=$(date +%a)
contents=/xtrabackup/complete/
contents2=/xtrabackup/increment/
see_file=$(ls -tr $contents | tail -1)
see_file2=$(ls -tr $contents2 | tail -1)
#定义函数,删除目录下除最后一个文件以为的所有文件
shopt -s extglob
delete_past(){
	cd $contents
	rm -rf !(`ls -tr | tail -1`)
}
#条件判断,按星期来判断
if [[ $week = Mon ]]; then
	#statements
	innobackupex --user=root --password='QianFeng@123' $contents
	if [[ $? -eq 0 ]]; then
		#statements	
		shopt -s extglob
		delete_past
		rm -rf $contents2*
		echo "周一完整备份成功"
	fi
elif [[ $week = Tue ]]; then
		#statements
	innobackupex --user=root --password='QianFeng@123' --incremental $contents2 --incremental-basedir=$contents$see_file
	echo "周二增量备份成功"
elif [[ $week = Wed ]]; then
		#statements
	innobackupex --user=root --password='QianFeng@123' --incremental $contents2 --incremental-basedir=$contents2$see_file2
	echo "周三增量备份成功"
elif [[ $week = Thu ]]; then
		#statements
	innobackupex --user=root --password='QianFeng@123' --incremental $contents2 --incremental-basedir=$contents2$see_file2
	echo "周四增量备份成功"
elif [[ $week = Fri ]]; then
		#statements
	innobackupex --user=root --password='QianFeng@123' --incremental $contents2 --incremental-basedir=$contents2$see_file2
	echo "周五增量备份成功"
elif [[ $week = Sat ]]; then
		#statements
	innobackupex --user=root --password='QianFeng@123' --incremental $contents2 --incremental-basedir=$contents2$see_file2
	echo "周六增量备份成功"
elif [[ $week = Sun ]]; then
		#statements
	innobackupex --user=root --password='QianFeng@123' --incremental $contents2 --incremental-basedir=$contents2$see_file2
	echo "周日增量备份成功"
else
	echo "备份失败请手动检查"
fi

猜你喜欢

转载自blog.csdn.net/weixin_46299169/article/details/105916944