mysql xtrabackup增量備份 mysql 增量備份策略 周一全備,其他增量備份,根據業務需要,設定保留日期,如保留一月。 增量備份步驟; 1 創建全備 2 根據全備目錄,創建增量備份 3 第二次增量備份根據第一次增量備份目錄,依次類推 下面是今天寫的增量備份腳本,先在自己的測試機上跑幾天。
#!/bin/sh begintime=`date +"%Y-%m-%d %H:%M:%S"` format_time=`date +"%Y-%m-%d_%H:%M:%S"` week=`date +%w` port=3306 #ip= backdir=/backup file_cnf=/etc/my.cnf user_name=root passwd= out_log=$datadir/xtraback_log_$format_time time_cost=$backdir/xtraback_time.txt if [ ! -d "$backdir" ]; then mkdir -p $backdir fi if [ -d "$backdir/rec5" ];then rm -rf $backdir-bak mv $backdir $backdir-bak mkdir $backdir fi #full backup if [ ! -d "$backdir/full" ];then echo "#####start full backup at $begintime to directory full" >>$time_cost innobackupex --defaults-file=$file_cnf --no-lock --no-timestamp --user=$user_name --port=3306 $backdir/full 1>$out_log-full 2>&1 tar -zcvf $backdir/full.tar.gz $backdir/full break; elif [ ! -d "$backdir/rec0" ];then echo "######start 0 incremental backup at $begintime to directory rec0" >>$time_cost innobackupex --default-file=$file_cnf --no-lock --no-timestamp --user=$user_name --port=$port --incremental --incremental-basedir=$backdir/full $backdir/rec0 1> $out_log-rec0 2>&1 break; elif [ ! -d "$backdir/rec1" ];then echo "#######start 1 incremental backup at $begintime to directory rec1" >>$time_cost innobackupex --defaults-file=$file_cnf --no-lock --no-timestamp --user=$user_name --port=port --incremental --incremental-basedir=$backdir/full $backdir/rec1 1>$out_log-rec1 2>&1 break; elif [ ! -d "$backdir/rec2" ]; then echo "######start 2 incremental backup at $begintime to directory rec2" >>$time_cost innobackupex --defaults-file=$file_cnf --no-lock --no-timestamp --user=$user_name --port=port --incremental --incremental-basedir=$backdir/rec1 $backdir/rec2 1> $out_log-rec2 2>&1 break; elif [ ! -d "$backdir/rec3" ]; then echo "#######start 3 incremental backup at $begintime to directory rec3" >$time_cost innobackupex --defaults-file=$file_cnf --no-lock --no-timestamp --user=root --port=port --incremental --incremental-basedir=$/backdir/rec2 $backdir/rec3 1> $out_log-rec3 2>&1 break; elif [! -d "$backdir/rec4" ];then echo "########start 4 incremental backup at $begintime to directory rec4" >>$time_cost innobackupex --defaults-file=$file_cnf --no-lock --no-timestamp --user=root --port=port --incremental --incremental-basedir=$backdir/rec4 1> $out_log-rec4 2>&1 break; elif [ ! -d "$backdir/rec5" ];then echo "#######start 5 incremental backup at $begintime to directory rec5" >>$time_cost \ innobackupex --defaults-file=$file_cnf --no-lock --no-timestamp --user=$user_name --port=port --incremental --incremental-basedir=$backdir/rec4 $backdir/rec5 1> $out_log-rec5 2>&1 break; fi
還原步驟 1 關閉實例 2 應用日志,如有增量,先恢復全備,然後再逐個恢復增量日志 3 copy數據到目錄 4 修改數據文件權限,chown、chmod 5 啟動