-- 2019-08-09 11:01:54之前的数据条数chengqm-3306>>select count(*) from mytest.mytest where ctime < '2019-08-09 11:01:54';+----------+| count(*) |+----------+| 161 |+----------+1 row in set (0.00 sec) -- 所有数据条数chengqm-3306>>select count(*) from mytest.mytest;+----------+| count(*) |+----------+| 180 |+----------+1 row in set (0.00 sec)
然后执行恢复
# 全量恢复[mysql@mysql-test ~]$ mysql -S /tmp/mysql.sock < backup.sql # 应用增量日志[mysql@mysql-test ~]$ mysql -S /tmp/mysql.sock < backup_inc.sql
检查数据
chengqm-3306>>select count(*) from mytest.mytest;+----------+| count(*) |+----------+| 161 |+----------+1 row in set (0.00 sec) chengqm-3306>>select * from mytest.mytest order by id desc limit 5;+-----+---------------------+| id | ctime |+-----+---------------------+|161| 2019-08-09 11:01:53 || 160 |2019-08-09 11:01:52||159| 2019-08-09 11:01:51 || 158 |2019-08-09 11:01:50||157| 2019-08-09 11:01:49 |+-----+---------------------+5 rows in set (0.00 sec)
[mysql@mysql-test ~]$ mysql -S /tmp/mysql.sock < backup.sql
全量恢复后状态
chgnqm-3306>>show tables;+------------------+| Tables_in_mytest |+------------------+| a || b |+------------------+2 rows in set (0.00 sec) chgnqm-3306>>select count(*) from a;+----------+| count(*) |+----------+| 71 |+----------+1 row in set (0.00 sec)
5 恢复增量数据
[mysql@mysql-test ~]$ mysql -S /tmp/mysql.sock < backup_inc_1.sql[mysql@mysql-test ~]$ mysql -S /tmp/mysql.sock < backup_inc_2.sql
恢复后状态,可以看到已经跳过了 drop 语句
chgnqm-3306>>show tables;+------------------+| Tables_in_mytest |+------------------+| a || b |+------------------+2 rows in set (0.00 sec) chgnqm-3306>>select count(*) from a;+----------+| count(*) |+----------+| 274 |+----------+1 row in set (0.00 sec)
chengqm-3307>>show slave status \G;...Slave_IO_Running: YesSlave_SQL_Running: Yes...1 row in set (0.00 sec) chengqm-3307>>show tables;+------------------+| Tables_in_mytest |+------------------+| a || b |+------------------+2 rows in set (0.00 sec)
闪回 闪回操作就是反向操作,比如执行了 delete from a where id=1,闪回就会执行对应的插入操作 insert into a (id,...) values(1,...),用于误操作数据,只对 DML 语句有效,且要求 binlog 格式设为 ROW。本章介绍两个比较好用的开源工具 binlog2sql binlog2sql 是大众点评开源的一款用于解析 binlog 的工具,可以用于生成闪回语句,项目地址 binlog2sql(https://sourl.cn/ZuNJPN) 安装