一个简单的脚本,仅供参考。谢谢!
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