一個簡單的腳本,僅供參考。謝謝!
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
innobackupex --user=root --password='QianFeng@123' $contents
if [[ $? -eq 0 ]]; then
shopt -s extglob
delete_past
rm -rf $contents2*
echo "週一完整備份成功"
fi
elif [[ $week = Tue ]]; then
innobackupex --user=root --password='QianFeng@123' --incremental $contents2 --incremental-basedir=$contents$see_file
echo "週二增量備份成功"
elif [[ $week = Wed ]]; then
innobackupex --user=root --password='QianFeng@123' --incremental $contents2 --incremental-basedir=$contents2$see_file2
echo "週三增量備份成功"
elif [[ $week = Thu ]]; then
innobackupex --user=root --password='QianFeng@123' --incremental $contents2 --incremental-basedir=$contents2$see_file2
echo "週四增量備份成功"
elif [[ $week = Fri ]]; then
innobackupex --user=root --password='QianFeng@123' --incremental $contents2 --incremental-basedir=$contents2$see_file2
echo "週五增量備份成功"
elif [[ $week = Sat ]]; then
innobackupex --user=root --password='QianFeng@123' --incremental $contents2 --incremental-basedir=$contents2$see_file2
echo "週六增量備份成功"
elif [[ $week = Sun ]]; then
innobackupex --user=root --password='QianFeng@123' --incremental $contents2 --incremental-basedir=$contents2$see_file2
echo "週日增量備份成功"
else
echo "備份失敗請手動檢查"
fi