备份脚本每天凌晨3点通过crontab执行一次,需要注意的是prepare的文件都是加了--redo-only参数的,直接用的话需prepare一次最后的增备文件(不加redo-only)。
#!/bin/bash##1.每周一、三、五凌晨3点基于上次增备做一次增量备份,并对本次备份文件做prepare合并到之前的prepare文件中
##2.每周日凌晨3点全备
##3.此脚本每天凌晨3点执行,删除超过30天的全备user=root
password=Test123456
database=test_db
host=192.168.1.201
cnf=/etc/my.cnf
week=`date +'%w'`
ibf=/xtrabackup/incremental_backup_folder
wbf=/xtrabackup/whole_backup_folder
ipf=/xtrabackup/incremental_prepare_folder
bi=/xtrabackup/backup.info
#上一次的增量备份文件
incremental=`ls $ibf -ltr |tail -1|awk '{print $NF}'`
date=`date +'%Y-%m-%d %H:%M:%S'`
echo " " >> $bi
echo "==============================$date===================================" >> $bicase $week in
[1,3,5])if [ "$incremental" = "0" ]; thenthen#第一次先做全备innobackupex --defaults-file=$cnf --user=$user --password=$password --host=$host --database=$database $ibf &>> $bicp -R $ibf/* $ipf#prepareinnobackupex --apply-log --redo-only --use-memory=2G $ipf/* &>> $bielse#增量备份innobackupex --defaults-file=$cnf --user=$user --password=$password --host=$host --incremental $ibf --incremental-basedir=$incremental &>> $bi#prepareinnobackupex --apply-log --redo-only --use-memory=2G $ipf/* --incremental-dir=$incremental &>> $bifi echo "Today is the $week day of the week,backup successful!" >> $bi
;;
7)#全备innobackupex --defaults-file=$cnf --user=$user --password=$password --host=$host --database=$database $wbf &>> $biecho "Today is the $week day of the week,backup successful!" >> $bi
;;
*)echo "Today is the $week day of the week,not backup!" >> $bi
;;
esac#删除超过30天的全备
find $wbf -mtime +30 -exec rm -rf {} \;