zoukankan      html  css  js  c++  java
  • mariadb数据库基于时间点恢复

    模拟ceshi库写入数据

    mysql> create database ceshi;
    Query OK, 1 row affected (0.01 sec)
    
    mysql> use ceshi;
    Database changed
    mysql> create table t1(id int primary key);
    Query OK, 0 rows affected (0.01 sec)
    
    mysql> insert into t1 select 1;
    Query OK, 1 row affected (0.00 sec)
    Records: 1  Duplicates: 0  Warnings: 0
    
    mysql> insert into t1 select 2;
    Query OK, 1 row affected (0.01 sec)
    Records: 1  Duplicates: 0  Warnings: 0
    
    mysql> insert into t1 select 3;
    Query OK, 1 row affected (0.00 sec)
    Records: 1  Duplicates: 0  Warnings: 0

    mydumper 备份数据

    mydumper -u root -p 123456 -h 127.0.0.1 --regex '^(?!(information_schema|performance_schema|sys))' -c -o /root/bak
    备份中包含mysql库,我们可以不用恢复
    rm -rf /root/bak/mysql*

    继续模拟ceshi库写入数据,直到最后将t1表同时

    mysql> insert into t1 select 4;
    Query OK, 1 row affected (0.01 sec)
    Records: 1  Duplicates: 0  Warnings: 0
    
    mysql> insert into t1 select 5;
    Query OK, 1 row affected (0.00 sec)
    Records: 1  Duplicates: 0  Warnings: 0
    
    mysql> insert into t1 select 6;
    Query OK, 1 row affected (0.01 sec)
    Records: 1  Duplicates: 0  Warnings: 0
    
    mysql> drop table t1;
    Query OK, 0 rows affected (0.01 sec)

    分析binlog,找到删除时间点,可以看到是08:30:55删除的(时间是UTC时区),我们需要恢复到 08:30:55 之前的位点,也就是 mysql-bin.000001,2158

    # bin/mysqlbinlog -vv mysql-bin.000001 
    ----------------------------------------------------------
    #220105  8:30:50 server id 194207  end_log_pos 2127 CRC32 0xab43d17e    Write_rows: table id 21 flags: STMT_END_F
    
    BINLOG '
    OlfVYROf9gIALgAAACkIAAAAABUAAAAAAAEABWNlc2hpAAJ0MQABAwAAFEcsuw==
    OlfVYRef9gIAJgAAAE8IAAAAABUAAAAAAAEAAf/+BgAAAH7RQ6s=
    '/*!*/;
    ### INSERT INTO `ceshi`.`t1`
    ### SET
    ###   @1=6 /* INT meta=0 nullable=0 is_null=0 */
    # Number of rows: 1
    # at 2127
    #220105  8:30:50 server id 194207  end_log_pos 2158 CRC32 0xeede276c    Xid = 164
    COMMIT/*!*/;
    # at 2158
    #220105  8:30:55 server id 194207  end_log_pos 2200 CRC32 0xa0098b6d    GTID 0-194207-11 ddl
    /*!100001 SET @@session.gtid_seq_no=11*//*!*/;
    # at 2200
    #220105  8:30:55 server id 194207  end_log_pos 2309 CRC32 0x59844e79    Query   thread_id=9     exec_time=0     error_code=0
    SET TIMESTAMP=1641371455/*!*/;
    DROP TABLE `t1` /* generated by server */
    /*!*/;

    新建一个mariadb实例(过程省略)

    1、使用myloader命令将数据恢复到新实例上
    myloader -u root -p '' -h 127.0.0.1 -P 3307 -d /root/bak
    cat metcdata 查看备份位点 Log: mysql-bin.000001,1549
    2、增量恢复,change master搭备库方式
    change master to master_host='127.0.0.1',master_port=3306,master_user='root',master_password='123456',master_log_file='mysql-bin.000001',master_log_pos=1549;
    本来想为了加快速度,只回放 ceshi 库 t1表 的binlog。算了,mariadb不支持,就这样同步吧。
    start slave until MASTER_LOG_FILE='mysql-bin.000001',MASTER_LOG_POS=2158;
    
    
    数据都回来了
    mysql> select * from t1;
    +----+
    | id |
    +----+
    |  1 |
    |  2 |
    |  3 |
    |  4 |
    |  5 |
    |  6 |
    +----+
    6 rows in set (0.00 sec)
  • 相关阅读:
    RestTemplate方法总结
    服务器上获取不到header中设置的自定义的属性值
    记录一次 事务问题 的处理
    java 集合按照 数值排序,如果数值一致 按照名字首字母排序
    mysql中按照中文首字母A-Z排序
    java 关于小数 换算整数 的一点想法
    mysql 根据身份证查询 年龄 性别
    MySQL普通索引(BTREE索引)以及最左前缀匹配
    net.sf.json的常用api
    Object划分
  • 原文地址:https://www.cnblogs.com/nanxiang/p/15767845.html
Copyright © 2011-2022 走看看