欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

mysql xtrabackup增量备份_MySQL

程序员文章站 2022-04-09 22:49:03
...
bitsCN.com

mysql xtrabackup增量备份

mysql 增量备份策略 周一全备,其他增量备份,根据业务需要,设定保留日期,如保留一月。

增量备份步骤;

1 创建全备

2 根据全备目录,创建增量备份

3 第二次增量备份根据第一次增量备份目录,依次类推

下面是今天写的增量备份脚本,先在自己的测试机上跑几天。

#!/bin/shbegintime=`date +"%Y-%m-%d %H:%M:%S"`format_time=`date +"%Y-%m-%d_%H:%M:%S"`week=`date +%w`port=3306#ip=backdir=/backupfile_cnf=/etc/my.cnfuser_name=rootpasswd=out_log=$datadir/xtraback_log_$format_timetime_cost=$backdir/xtraback_time.txtif [ ! -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 启动

bitsCN.com
相关标签: mysql