cd /data/MyFlash-master
gcc -w -g `pkg-config --cflags glib-2.0`source/binlogParseGlib.c
-o /data/flashback /usr/lib64/libglib-2.0.so -lrt
参数解析:
/data/MyFlash/source/binlogParseGlib.c:myflash c源码文件位置
/data/flashback:编译完成myflash的可执行文件位置
/usr/lib64/libglib-2.0.so:glib2.0的lib文件位置
pkg-config --cflags glib-2.0:标明使用的glib版本
./flashback --help
Usage:
flashback [OPTION...]
Help Options:
-?, --help Show help options
Application Options:
--databaseNames databaseName to apply. if multiple,
seperate by comma(,)
#指定需要回滚的数据库名称。多个数据库名称可以使用","隔开,如果不指定该参数,
#相当于指定所有数据库
--tableNames tableName to apply. if multiple,
seperate by comma(,)
#指定需要回滚的表名。多个表可以用","隔开。如果不指定该参数,相当于指定所有表。
--start-position start position
#指定回滚的开始位置。如不指定,从文件的开始处进行回滚。如指定,
#请指定正确有效的位置,否则无法回滚。
--stop-position stop position
#指定回滚结束的位置。如不指定,回滚到文件结束位置。如指定,
#请指定正确有效的位置,否则无法回滚。
--start-datetime start time (format %Y-%m-%d %H:%M:%S)
#指定回滚开始的时间。注意格式为:%Y-%m-%d %H:%M:%S。如不指定,
#则不限定时间。建议使用指定时间方式。
--stop-datetime stop time (format %Y-%m-%d %H:%M:%S)
#指定回滚结束的时间。注意格式为:%Y-%m-%d %H:%M:%S。如不指定,
#则不限定时间。建议使用指定时间方式。
--sqlTypes sql type to filter . support INSERT, UPDATE ,DELETE.
if multiple, seperate by comma(,)
#指定需要回滚的sql类型。目前支持的过滤类型是INSERT, UPDATE ,DELETE。
#多个类型可以用","隔开。注意过滤类型要大写。
--maxSplitSize max file size after split, the uint is M
#指定该参数,对文件进行固定尺寸的分割(单位为M),
#过滤条件有效,但不进行回滚操作。
#该参数主要用来将大的binlog文件切割,防止单次应用的binlog尺寸过大,
#对线上造成压力
--binlogFileNames binlog files to process. if multiple,
seperate by comma(,)
#指定需要回滚的binlog文件,目前只支持单个文件,后续会增加多个文件支持
--outBinlogFileNameBase output binlog file name base
#指定输出的binlog文件前缀,如不指定,
#则默认为binlog_output_base.flashback
--logLevel log level, available option is debug,warning,error
#仅供开发者使用,默认级别为error级别。在生产环境中不要修改这个级别,
#否则输出过多
--include-gtids gtids to process
#指定需要回滚的gtid,支持gtid的单个和范围两种形式。
--exclude-gtids gtids to skip
#指定不需要回滚的gtid,用法同include-gtids。
1.回滚整个文件
./flashback --binlogFileNames=haha.000041
mysqlbinlog binlog_output_base.flashback | mysql -h<host>
-u<user> -p
2.回滚该文件中的所有insert语句
./flashback --sqlTypes='INSERT' --binlogFileNames=haha.000041
mysqlbinlog binlog_output_base.flashback | mysql -h<host>
-u<user> -p
3.回滚大文件
回滚:
./flashback --binlogFileNames=haha.000042
切割大文件:
./flashback --maxSplitSize=1 --binlogFileNames=
binlog_output_base.flashback
应用:
mysqlbinlog binlog_output_base.flashback.000001 | mysql -h<host>
-u<user> -p
...
mysqlbinlog binlog_output_base.flashback.<N> | mysql -h<host>
-u<user> -p
#!/bin/bash
echo `date` "start recovery"
file_path=/root/myflash/binary/
cd /root/myflash/binary
./flashback --databaseNames xx --tableNames Test
--sqlTypes delete
--binlogFileNames=/opt/mysql/mysql-bin.000003
./flashback --maxSplitSize=15 --binlogFileNames=
binlog_output_base.flashback
arr=`find ${file_path} -name "binlog_output_base.0*"|sort -n`
for i in ${arr}
do
mysqlbinlog --skip-gtids ${i} | mysql -S /opt/mysql/mysql.sock
done
echo `date` "end recovery"