首页 > 数据库 > MySQL > MySQL数据恢复——MyFlash恢复工具
概述 :
1. 如果 binlog 日志保留,可以闪回到任意时间
2. 可以针对实例、数据库、表及指定的 DML 语句进行回滚
3. 性能优于 binlog2sql 、 mysqlbinlog
限制:
1.binlog 格式必须为 row, 且 binlog_row_image=full
2. 仅支持 5.6 与 5.7
3. 只能回滚 DML (增、删、改)
1.安装:
unzipMyFlash-master.zip mvMyFlash-master/usr/local/MyFlash/ gcc-wpkg-config--cflags--libsglib-2.0source/binlogParseGlib.c-obinary/flashback
2.参数介绍:
[root@10-31-1-119MyFlash]# cd binary/ [root@10-31-1-119binary]# ./flashback --help Usage: flashback[OPTION?] HelpOptions: -h, --helpShowhelpoptions ApplicationOptions: --databaseNamesdatabaseNametoapply. ifmultiple, seperatebycomma(,) --tableNamestableNametoapply. ifmultiple, seperatebycomma(,) --start-positionstartposition --stop-positionstopposition --start-datetimestarttime(format%Y-%m-%d%H:%M:%S) --stop-datetimestoptime(format%Y-%m-%d%H:%M:%S) --sqlTypessqltypetofilter. supportINSERT, UPDATE,DELETE. ifmultiple, seperatebycomma(,) --maxSplitSizemaxfilesizeaftersplit, theuintisM --binlogFileNamesbinlogfilestoprocess. ifmultiple, seperatebycomma(,) --outBinlogFileNameBaseoutputbinlogfilenamebase --logLevelloglevel, availableoptionisdebug,warning,error --include-gtidsgtidstoprocess --exclude-gtidsgtidstoskip
--databaseNames: 需要闪回的数据库名称,如果有多个数据库,用逗号”,”隔开。
--tableNames:要闪回的表名称,如果有多个表,用逗号”,”隔开。
--start-position:闪回的起始位置,如不指定,从文件开始处回滚。
--stop-position: 闪回的终止位置,如不指定,回滚到文件结尾。
--start-datetime:闪回的开始时间。
--stop-datetime: 闪回的终止时间。
--sqlTypes:指定需要回滚的sql类型,支持INSERT、UPDATE、DELETE,多个类型使用逗号”,”分开。
--maxSplitSize:对文件进行固定尺寸的切割,以防止单次应用binlog尺寸较大,对线上造成压力。
--binlogFileNames: 指定需要回滚的binlog文件,美团文档说目前只支持单个binlog文件,经测试已经支持多个binlog文件同时闪回。
--outBinlogFileNameBase:指定输出的binlog文件前缀,如不指定,则默认为binlog_output_base.flashback。
logLevel:仅供开发者使用,默认级别为error级别。在生产环境中不要修改这个级别,否则输出过多。
include-gtids:指定需要回滚的gtid,支持gtid的单个和范围两种形式。
exclude-gtids:指定不需要回滚的gtid,用法同include-gtids。
3.使用方法:
(1).回滚整个文件:
./flashback--binlogFileNames=haha.000041mysqlbinlogbinlog_output_base.flashback|mysql-h<host>-u<user>-p
(2).回滚该文件中的所有insert语句:
/flashback--sqlTypes='INSERT'--binlogFileNames=haha.000041 mysqlbinlogbinlog_output_base.flashback|mysql-h<host>-u<user>-p
(3).回滚大文件:
回滚
./flashback--binlogFileNames=haha.000042
切割大文件
./flashback--maxSplitSize=1--binlogFileNames=binlog_output_base.flashback
应用
mysqlbinlogbinlog_output_base.flashback.000001|mysql-h<host>-u<user>-p
...
mysqlbinlogbinlog_output_base.flashback.<N>|mysql-h<host>-u<user>-p
4.使用案例:
mysql>selectcount(*) frome; +----------+ |count(*) | +----------+ |107| +----------+ mysql>deletefrome; QueryOK, 107rowsaffected(0.00sec) mysql>flushlogs; QueryOK, 0rowsaffected(0.00sec)
查看binlog信息,定位delete误删时间点:(可将误删除SQL在binlog中过滤)
mysqlbinlog--base64-output=decode-rows-vv/mysql/app/data/mysql_bin.000118|more
起始时间点:1341
stop position:(该删除语句后第一个commit时间点8573)
执行恢复:
./flashback--binlogFileNames=/mysql/app/data/mysql_bin.000118 --start-position=1341--stop-position=8573 --databaseNames=test--tableNames=e --sqlTypes='DELETE' --outBinlogFileNameBase=test_tb
随后会生成test_tb.flashback文件
查看该文件:
mysqlbinlog --base64-output=decode-rows -vv test_tb.flashback | more
恢复:
mysqlbinlog--no-defaultstest_tb.flashback|mysql-uroot-p123456
查看:
mysql>selectcount(*) frome; +----------+ |count(*) | +----------+ |107| +----------+
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/70013625/viewspace-3026218/ ,如需转载,请注明出处,否则将追究法律责任。