GithubHelp home page GithubHelp logo

wangjiemin / my2fback Goto Github PK

View Code? Open in Web Editor NEW
37.0 4.0 21.0 10.26 MB

my2fback 是基于Golang开发的快速解析与闪回MySQL/MariaDB binlog 工具, 也支持解析relaylog

Home Page: https://jiemin.wang

Go 100.00%

my2fback's Introduction

简介

闪回大概介绍想了解的,请阅读。

my2fback 实现了基于row格式binlog的回滚闪回功能,让误删除或者误更新数据,可以不停机不使用备份而快速回滚误操作。也可以解释binlog(支持非row格式binlog)生成易读的SQL。

安装与使用

my2fback 连接数据库帐号的权限:

  • MySQL5.6/MariaDB10.1/MariaDB10.2版本
mysql> GRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT, PROCESS ON *.* TO 'user'@'localhost' IDENTIFIED BY 'xxxxxx';
  • MySQL5.7版本
mysql> CREATE USER 'user'@'localhost' IDENTIFIED BY 'xxxxxx';
mysql> GRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT, PROCESS ON *.* TO 'user'@'localhost';

版本

  • 以上功能均可指定任意的单库多库, 单表多表, 任意时间点, 任意binlog位置。
  • 支持mysql5.5及以上,也支持MariaDB的binlog, 支持传统复制的binlog, 也支持GTID的binlog。
  • 支持直接指定文件路径的binlog, 也支持主从复制, my2fback 作为从库从主库拉binlog来过解释。

限制

  • 使用回滚/闪回功能时,binlog格式必须为row,且binlog_row_image=full, 其它功能支持非row格式binlog
  • 只能回滚DML, 不能回滚DDL
  • 支持V4格式的binlog, V3格式的没测试过,测试与使用结果显示,mysql5.1,mysql5.5, mysql5.6与mysql5.7的binlog均支持
  • 支持指定-tl时区来解释binlog中time/datetime字段的内容。开始时间-sdt与结束时间-edt也会使用此指定的时区,
    • 但注意此开始与结束时间针对的是binlog event header中保存的unix timestamp。结果中的额外的datetime时间信息都是binlog event header中的unix timestamp
  • decimal字段使用float64来表示, 但不损失精度
  • 所有字符类型字段内容按golang的utf8(相当于mysql的utf8mb4)来表示

TODO

  • file方式解析binlog
  • file方式回滚binlog
  • repl方式解析binlog
  • repl方式回滚binlog
  • DML统计信息
  • 大事务与长事务统计信息
  • DDL统计信息
  • 测试

my2fback's People

Contributors

wangjiemin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

my2fback's Issues

好像不支持import tablespace discard tablespace语句解析

time="2019-07-19_18:11:13" level=error errcode=2 errmsg="error to parse sql: ALTER TABLE homestay_order DISCARD TABLESPACE: line 1 column 34 near \"DISCARD TABLESPACE\" "

error to parse sql from query event, binlog=(0242123310-mysql-bin.000002, 15133259), time=2019-06-21_10:37:16, sql=ALTER TABLE homestay_order DISCARD TABLESPACE

解析binlog报错:errmsg="error to parse sql: XA START X

您好:
当进行binlog解析的时候报错,请问怎么解决:
level=error errcode=2 errmsg="error to parse sql: XA START X'3137322e31362e352e38362e746d31323935343030303236',X'3137322e31362e352e38362e746d373938323234',1096044365: line 1 column 2 near "XA START X'3137322e31362e352e38362e746d31323935343030303236',X'3137322e31362e352e38362e746d373938323234',1096044365" "
error to parse sql from query event, binlog=(binlog_mysqlbin.001914, 180214904), time=2022-02-17_17:06:10, sql=XA START X'3137322e31362e352e38362e746d31323935343030303236',X'3137322e31362e352e38362e746d373938323234',1096044365

image

解析命令:
time /home/mysql/test_slave/mysql_dumpder/backup/scripts/my2fback -m file -w 2sql -M mysql -t 6
-H xxxxxx -u innobackuper -p 'Inno!backuper1234' -P 3308 -dbs op -e -f -d -r 20 -k -b 100 -l 10 -o /home/mysql/test_slave/mysql_dumpder/backup/scripts/binlog/temp
/home/mysql/test_slave/mysql_dumpder/backup/scripts/binlog/binlog_mysqlbin.001914

建议输出列和标题对齐

binlog            starttime           stoptime            startpos   stoppos    inserts  updates  deletes  database        table               
0242123310-mysql-bin.000002 2019-03-04_18:47:46 2019-03-04_18:47:46 3098       3272       2        0        0        test            t11                 
0242123310-mysql-bin.000002 2019-05-06_18:32:38 2019-05-06_18:32:38 17293      308784     1        0        0        mgr_zyx_2       meta_snapshot       
0242123310-mysql-bin.000002 2019-05-06_18:36:41 2019-05-06_18:36:41 311626     1889426    1        0        0        mgr_zyx         meta_snapshot       
0242123310-mysql-bin.000002 2019-05-06_18:39:41 2019-05-06_18:39:58 1890490    8325444    16478    0        0        config_center   t_table_topic    

建议像这个shell脚本一样增加汇总统计

https://gitee.com/mo-shan/analysis_binlog.git

Table                                                       Last Time                     Insert(s)      Update(s)      Delete(s)      
moshan.flush_                                               190311 9:28:54                0              3475           0              
ultrax.dis_common_syscache                                  190312 11:31:53               0              231            0              
ultrax.dis_common_cron                                      190312 11:31:53               0              194            0              
ultrax.dis_common_session                                   190312 10:38:56               6              170            5              
ultrax.dis_forum_forum                                      190312 9:19:10                0              129            0              
moshan.money                                                190311 9:28:37                29             80             0              
ultrax.dis_common_onlinetime                                190312 10:38:42               0              48             0              
ultrax.dis_forum_thread                                     190312 10:38:56               4              47             0              
ultrax.dis_common_member_count                              190312 10:38:53               0              47             0              
ultrax.dis_common_credit_rule_log                           190312 10:38:53               0              38             0              
ultrax.dis_forum_post                                       190312 9:24:30                4              34             0              
ultrax.dis_common_member_status                             190312 9:04:42                0              20             0              
moshan.history_                                             190308 9:28:25                0              10             0              
ice_db.server_setting_tmp                                   190304 10:34:19               564            8              0              
ultrax.dis_common_process                                   190312 11:31:53               201            7              201            
ultrax.dis_common_setting                                   190312 9:04:42                0              7              0              
moshan.tmp_table                                            190304 17:17:21               0              7              0              
ultrax.dis_ucenter_failedlogins                             190306 10:07:11               0              4              0              
ultrax.dis_common_member_field_home                         190311 14:54:47               0              4              0              
ultrax.dis_forum_threadcalendar                             190312 9:09:56                2              2              0              
ultrax.dis_forum_attachment                                 190306 11:46:56               2              2              0              
moshan.use_date                                             190304 17:12:22               0              1              0              
ultrax.dis_forum_threadhot                                  190312 9:09:56                4              0              0              
ultrax.dis_forum_threaddisablepos                           190311 14:54:47               1              0              0              
ultrax.dis_forum_statlog                                    190312 9:04:42                304            0              0              
ultrax.dis_forum_sofa                                       190311 14:54:47               4              0              0              
ultrax.dis_forum_post_tableid                               190311 14:54:47               4              0              0              
ultrax.dis_forum_newthread                                  190311 14:54:47               4              0              6              
ultrax.dis_forum_attachment_unused                          190306 11:46:56               2              0              2              
ultrax.dis_forum_attachment_8                               190306 11:46:56               1              0              0              
ultrax.dis_forum_attachment_0                               190306 11:46:29               1              0              0              
ultrax.dis_common_statuser                                  190311 11:40:44               4              0              4              
ultrax.dis_common_searchindex                               190312 10:38:53               28             0              0              
ultrax.dis_common_member_action_log                         190311 14:54:47               4              0              4              
test.ttt                                                    190303 11:43:36               2              0              0              
test.t_test                                                 190308 16:52:35               4              0              0              
test.t_message_list                                         190313 9:30:16                307544         0              0              
test.t_message_content_lately                               190313 9:30:16                307544         0              0              
test.admin_user                                             190308 11:51:50               3              0              3              


Trans(total)                                                Insert(s)                     Update(s)      Delete(s)      
312619                                                      616270                        4565           225            
root /data/git/analysis_binlog/res >> 

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.