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)
  • 相关阅读:
    Hihocoder 1275 扫地机器人 计算几何
    CodeForces 771C Bear and Tree Jumps 树形DP
    CodeForces 778D Parquet Re-laying 构造
    CodeForces 785E Anton and Permutation 分块
    CodeForces 785D Anton and School
    CodeForces 785C Anton and Fairy Tale 二分
    Hexo Next 接入 google AdSense 广告
    如何统计 Hexo 网站的访问地区和IP
    Design and Implementation of Global Path Planning System for Unmanned Surface Vehicle among Multiple Task Points
    通过ODBC接口访问人大金仓数据库
  • 原文地址:https://www.cnblogs.com/nanxiang/p/15767845.html
Copyright © 2011-2022 走看看