• MySQL 8.0 Clone 备份恢复演练


    前言

    上一篇文章中,我们介绍了使用 Clone 插件进行备份,相关的恢复流程将在本篇文章介绍。

    MySQL 8.0 Clone Plugin 详解

    恢复增量数据的方法,使用的是伪装为 relay log 通过多线程复制加速恢复的方式,之前有写过一个案例。

    MySQL 通过 MTS 多线程恢复增量日志备份

    1. 恢复目标

    OSS 中下载全量备份及 Binlog 备份,测试 Clone 备份的全量备份恢复与增量恢复,将数据恢复到一个新实例。

    2. 环境说明

    主机MySQL 版本用途
    172.16.104.568.0.32Clone 源库
    172.16.104.578.0.32Clone 恢复的目标库

    3. 克隆数据

    在 Clone 之前我们先查看一下演示表中有多少行数据:

    root@mysql 17:08:  [op_service_db]>select count(*) from task_queue;
    +----------+
    | count(*) |
    +----------+
    |    36280 |
    +----------+
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    执行 Clone 操作:

    CLONE LOCAL DATA DIRECTORY = '/data/clone_bak/20231106';
    
    • 1

    结束后,向测试表中写入 10w 行数据:

    mysql_random_data_load -h172.16.104.56 -u'my' -p'112233' --max-threads=10 op_service_db task_queue 100000
    
    • 1

    将 Clone 文件 scp 到 57 的目标实例:

    scp -r ./20231106/ root@172.16.104.57:/data
    
    • 1

    还有期间的 Binlog 文件也 scp 到目标实例:

    scp /data/mysql_80/logs/mysql-bin.000001 root@172.16.104.57:/data
    
    • 1

    演示只有一个 Binlog 如果有多个 Binlog 操作也比较简单,注册步骤添加多个文件即可。

    4. 恢复全量数据

    使用 clone 出来的数据替换 57 节点的数据目录,操作前需要停掉 MySQL。

    # 删除源目录
    rm -rf /data/mysql_80/data
    # 替换
    mv ./20231106 /data/mysql_80/data
    # 修改属组
    chown -R mysql:mysql /data/mysql_80/
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    然后启动 MySQL 数据库。

    5. 注册增量日志

    这块主要是把需要跑的增量 Binlog 文件名,修改为 relay log 的格式。

    # 将 binlog 文件,按照 relay log 格式写入到 index 文件中
    cat mysql-relay.index
    
    /data/mysql_80/logs/mysql-relay.000001
    
    • 1
    • 2
    • 3
    • 4

    6. 应用增量日志

    创建复制通道:

    change master to 
        master_host='localhost',
        master_port=3306,
        MASTER_AUTO_POSITION=0,
        RELAY_LOG_FILE='mysql-relay.000001',
        RELAY_LOG_POS=4;
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    查看 GTID 点位信息:

    root@mysql 17:39:  [(none)]>show master status\G
    *************************** 1. row ***************************
                 File: mysql-bin.000001
             Position: 14808235
         Binlog_Do_DB: 
     Binlog_Ignore_DB: 
    Executed_Gtid_Set: eccc6b43-b0fc-11ed-8e74-fa0e3cc40b00:1-38
    eccc6b43-b0fc-11ed-8e74-fa0e3cc40b00:38
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    设置 SQL 线程,应用 eccc6b43-b0fc-11ed-8e74-fa0e3cc40b00:38 之后的 Event 操作。

    start slave until SQL_AFTER_GTIDS ='eccc6b43-b0fc-11ed-8e74-fa0e3cc40b00:38';
    
    • 1

    启动 SQL 线程:

    start slave sql_thread;
    
    • 1

    可以通过 show slave status\G 查看进度:

    Executed_Gtid_Set: 1b03028c-76f7-11ee-ac46-faa7cd9c6a00:1-4,
    eccc6b43-b0fc-11ed-8e74-fa0e3cc40b00:1-138
    
    • 1
    • 2

    至此,Clone 结束后写入的增量数据已经通过 Binlog 恢复到新实例:

    root@mysql 17:43:  [op_service_db]>select count(*) from task_queue;
    +----------+
    | count(*) |
    +----------+
    |   136280 |
    +----------+
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    后记

    基于 MySQL 8.0 克隆插件,我研发了一套自动化备份系统,可以管理线下所有 MySQL 集群的 Clone 备份和 Binlog 备份。

    在这里插入图片描述

    感兴趣可以看看,欢迎提问题提需求,欢迎 Pull Requests!

    https://github.com/COOH-791/mysql_clone_backup/tree/main

  • 相关阅读:
    flink1.15源码笔记
    C++中string对象之间比较、char*之间比较
    字符串函数----篇章(1)
    J2_jsp数据传递与保存
    jenkins安装
    第十三章 初识jQuery
    Out of memory,realloc failed
    我又和redis超时杠上了
    【综述】推荐系统偏差问题 & 去偏最新研究进展(Bias and Debias in Recommender System)
    DataBinding 高级用法
  • 原文地址:https://blog.csdn.net/qq_42768234/article/details/134287983