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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章