原标题:MySQL 闪回工具 MyFlash-爱可生
前言
MyFlash 是美团点评开源的一个 MySQL 闪回工具,可以用来回滚 MySQL 中的 DML 操作,恢复到某时刻的数据。本文将简单地介绍 MySQL 闪回工具 MyFlash 的使用。
限制
MyFlash 工具存在如下限制:
binlog 格式必须为 row,且 binlog_row_image = full
仅支持 5.6 与 5.7 版本的 MySQL
只能回滚 DML( 增、删、改 )操作
下载安装
下载 MyFlash 安装包,将安装包安装于 /data 目录下,编译之前,先安装依赖包。
[root@10-186-62-22 ~ ]# cd /data
[root@10-186-62-22 data]# wget https://github.com/Meituan-Dianping/MyFlash/archive/master.zip
[root@10-186-62-22 data]# unzip master.zip
Archive: master.zip
b128c0faaf1a657d09238b7cda1c2a80ad599909
creating: MyFlash-master/
extracting: MyFlash-master/.gitignore
inflating: MyFlash-master/License.md
inflating: MyFlash-master/README.md
creating: MyFlash-master/binary/
inflating: MyFlash-master/binary/flashback
inflating: MyFlash-master/binary/mysqlbinlog20160408
inflating: MyFlash-master/binlog_output_base.flashback
inflating: MyFlash-master/build.sh
creating: MyFlash-master/doc/
extracting: MyFlash-master/doc/FAQ.md
extracting: MyFlash-master/doc/Function.md
inflating: MyFlash-master/doc/INSTALL.md
inflating: MyFlash-master/doc/TestCase.md
inflating: MyFlash-master/doc/how_to_use.md
creating: MyFlash-master/source/
inflating: MyFlash-master/source/binlogParseGlib.c
creating: MyFlash-master/source/mysqlHelper/
extracting: MyFlash-master/source/mysqlHelper/mysqlHelper.c
creating: MyFlash-master/source/network/
inflating: MyFlash-master/source/network/network.c
creating: MyFlash-master/testbinlog/
inflating: MyFlash-master/testbinlog/haha.000005
inflating: MyFlash-master/testbinlog/haha.000007
inflating: MyFlash-master/testbinlog/haha.000008
inflating: MyFlash-master/testbinlog/haha.000009
inflating: MyFlash-master/testbinlog/haha.000041
[root@10-186-62-22 data]# mv MyFlash-master MyFlash
[root@10-186-62-22 data]# cd MyFlash/
[root@10-186-62-22 MyFlash]# yum install gcc glib2-devel -y
[root@10-186-62-22 MyFlash]# gcc -w `pkg-config --cflags --libs glib-2.0` source/binlogParseGlib.c -o binary/flashback
用法
flashback [OPTION...]
常用参数说明:
--databaseNames
指定需要回滚的数据库名。多个数据库可以用 “,” 隔开。如果不指定该参数,相当于指定了所有数据库。
--tableNames
指定需要回滚的表名。多个表可以用 “,” 隔开。如果不指定该参数,相当于指定了所有表。
--start-position
指定回滚开始的位置。如不指定,从文件的开始处回滚。请指定正确的有效的位置,否则无法回滚。
--stop-position
指定回滚结束的位置。如不指定,回滚到文件结尾。请指定正确的有效的位置,否则无法回滚。
--start-datetime
指定回滚的开始时间。注意格式必须是 %Y-%m-%d %H:%M:%S。如不指定,则不限定时间。
--stop-datetime
指定回滚的结束时间。注意格式必须是 %Y-%m-%d %H:%M:%S。如不指定,则不限定时间。
--sqlTypes
指定需要回滚的 sql 类型。目前支持的过滤类型是 INSERT, UPDATE, DELETE。多个类型可以用 “,” 隔开。
--maxSplitSize
指定解析分割后文件最大大小,单位为 M。
--binlogFileNames
指定需要回滚的 binlog 文件ÿ