数据库运维
记录DBA学习成长历程

innobackupex 增量备份(incremental)案例

1.删掉原来备份

rm -rf /data/backup/*
mysql [(none)]>show master status \G
mysql [(none)]>restart master;
mysql [(none)]>show master status;

2.模拟数据变化(全备之前)

mysql [(none)]>create database test charset utf8;
mysql [(none)]>use test;
mysql [test]>create table t1(id int);
mysql [test]>insert into t1 values(1),(2),(3);
mysql [test]>commit;

3.全备(周日)

innobackupex --user=root --password=123456 --no-timestamp /data/backup/full 
>&/tmp/xbk_full.log

4.模拟周一数据变化

use test;
create table t2(id int);
insert into t2 values(1),(2),(3);
commit;

5.第一次增量备份(周一)

innobackupex --user=root --password=123456 --no-timestamp --incremental /data/backup/inc1 
--incremental-basedir=/data/backup/full &>/tmp/inc1.log
检查备份日志
cat /tmp/inc1.log
对比全备lsn号
[root@xiaoyong backup]# cat full/xtrabackup_checkpoints
backup_type = full-backuped
to_lsn = 299557468
last_lsn = 299557477-9=增量备份的from_lsn
[root@xiaoyong backup]# cat inc1/xtrabackup_checkpoints
backup_type = incremental
from_lsn = 299557468
last_lsn = 299563113

6.模拟周二数据

use test;
create table t3(id int);
insert into t3 values(1),(2),(3);commit;

7.周二增量备份

innobackupex --user=root --password=123456 --no-timestamp --incremental /data/backup/inc2 
--incremental-basedir=/data/backup/inc1 &>/tmp/inc2.log

8.模拟周三数据变化

use test;
create table t4(id int);
insert into t4 values(1),(2),(3);
commit;
drop database test;

恢复方案

增量不能单独恢复,增量必须按照LSN号码顺序合并到全备
恢复到周三误drop之前的数据状态
恢复思路:
1. 挂出维护页,停止当天的自动备份脚本
2. 检查备份:周日full+周一inc1+周二inc2,周三的完整二进制日志
3. 进行备份整理(细节),截取关键的二进制日志(从备份——误删除之前),所有备份必须要--apply-log进行整理备份,
部分备份需要只redo不undo(--redo-only)
4. 测试库进行备份恢复及日志恢复
5. 应用进行测试无误,开启业务
6. 此次工作的总结

恢复过程

1. 挂出维护页,停止当天的自动备份脚本
2. 检查备份:周日full+周一inc1+周二inc2,周三的完整二进制日志
(1) 全备的整理
innobackupex --apply-log --redo-only /data/backup/full
(2) 合并inc1到full中
innobackupex --apply-log --redo-only --incremental-dir=/data/backup/inc1 /data/backup/full
检查是否成功:last_lsn一致
[root@xiaoyong backup]# cat full/xtrabackup_checkpoints
last_lsn = 299563113
[root@xiaoyong backup]# cat inc1/xtrabackup_checkpoints
last_lsn = 299563113
(3) 合并inc2到full中
innobackupex --apply-log --incremental-dir=/data/backup/inc2 /data/backup/full
检查是否成功:last_lsn一致
[root@xiaoyong backup]# cat full/xtrabackup_checkpoints
last_lsn = 299568740
[root@xiaoyong backup]# cat inc2/xtrabackup_checkpoints
last_lsn = 299568740
(4) 最后一次整理全备
[root@db01 backup]# innobackupex --apply-log /data/backup/full
3. 截取周二 23:00 到drop 之前的 binlog 
(1)判断起点
cat inc2/xtrabackup_binlog_info
mysql-bin.000001 1751 1a98cc29-14f2-11eb-86f2-000c29159620:1-8
(2)判断终点
mysql [(none)]>mysql [(none)]>show binlog events in 'mysql-bin.000001';
| mysql-bin.000001 | 2176 | Gtid | 6 | 2241 | SET @@SESSION.GTID_NEXT= '1a98cc29-14f2-11eb-86f2-000c29159620:11' |
| mysql-bin.000001 | 2241 | Query | 6 | 2333 | drop database test 
(3)截取二进制日志
mysqlbinlog --skip-gtids --include-gtids='1a98cc29-14f2-11eb-86f2-000c29159620:9-10' /data/binlog/mysql-bin.000001 
>/data/backup/binlog.sql
4. 进行恢复
(1)准备新环境
cd /data/3307/data/
rm -rf *
(2)xbk数据恢复
cp -a /data/backup/full/* /data/3307/data
授权并启动数据库
chown -R mysql.mysql /data
systemctl start mysqld3307
恢复二进制日志
mysql -uroot -p -S /data/3307/mysql.sock
set sql_log_bin=0;
source /data/backup/binlog.sql

 

赞(0)
MySQL学习笔记 » innobackupex 增量备份(incremental)案例