標籤:split 指定 完成 clu 必須 檔案的 簡介 美團 upd
簡介:MyFlash是由美團點評公司技術工程部開發維護的一個復原DML操作的工具。該工具通過解析v4版本的binlog,完成復原操作。相對已有的復原工具,其增加了更多的過濾選項,讓復原更加容易。
安裝:
git clone https://github.com/Meituan-Dianping/MyFlash.git
cd MyFlash
gcc -w pkg-config --cflags --libs glib-2.0 source/binlogParseGlib.c -o binary/flashback
cd binary
./flashback --help --查看協助
使用:
下面的這些參數是可以任意組合的。
* 1.databaseNames
指定需要復原的資料庫名。多個資料庫可以用“,”隔開。如果不指定該參數,相當於指定了所有資料庫。
- 2.tableNames
指定需要復原的表名。多個表可以用“,”隔開。如果不指定該參數,相當於指定了所有表。
- 3.start-position
指定復原開始的位置。如不指定,從檔案的開始處復原。請指定正確的有效位置,否則無法復原
- 4.stop-position
指定復原結束的位置。如不指定,復原到檔案結尾。請指定正確的有效位置,否則無法復原
- 5.start-datetime
指定復原的開始時間。注意格式必須是 %Y-%m-%d %H:%M:%S。 如不指定,則不限定時間
- 6.stop-datetime
指定復原的結束時間。注意格式必須是 %Y-%m-%d %H:%M:%S。 如不指定,則不限定時間
- 7.sqlTypes
指定需要復原的sql類型。目前支援的過濾類型是INSERT, UPDATE ,DELETE。多個類型可以用“,”隔開。
- 8.maxSplitSize
一旦指定該參數,對檔案進行固定尺寸的分割(單位為M),過濾條件有效,但不進行復原操作。該參數主要用來將大的binlog檔案切割,防止單次應用的binlog尺寸過大,對線上造成壓力
- 9.binlogFileNames
指定需要復原的binlog檔案,目前只支援單個檔案,後續會增加多個檔案支援
- 10.outBinlogFileNameBase
指定輸出的binlog檔案首碼,如不指定,則預設為binlog_output_base.flashback
- 11.logLevel
僅供開發人員使用,預設層級為error層級。在生產環境中不要修改這個層級,否則輸出過多
- 12.include-gtids
指定需要復原的gtid,支援gtid的單個和範圍兩種形式。
- 13.exclude-gtids
指定不需要復原的gtid,用法同include-gtids
測試:
/root/test/MyFlash/binary/flashback --binlogFileNames=/mysqllog/mysql-bin.000011 --start-datetime="2018-01-04 13:50:00" --stop-datetime="2018-01-04 14:35:00" --databaseNames=test --tableNames=test_tb --sqlTypes=‘UPDATE‘,‘DELETE‘ --outBinlogFileNameBase=test_tb
mysqlbinlog --no-defaults --base64-output=decode-rows -vv binlog_output_base.flashback --查看復原sql
mysqlbinlog --no-defaults binlog_output_base.flashback |mysql -uroot -pyourpass --執行恢複
可以在.bash_profile增加
alias flashback="/root/test/MyFlash/binary/flashback"
以後即可這樣使用
flashback --binlogFileNames=/mysqllog/mysql-bin.000011 --start-datetime="2018-01-04 13:50:00" --stop-datetime="2018-01-04 14:35:00" --databaseNames=test --tableNames=test_tb --sqlTypes=‘UPDATE‘,‘DELETE‘ --outBinlogFileNameBase=test_tb
MyFlash 復原mysql binlog