文档首页
MySQL 8.4 参考手册
8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

MySQL 8.4 参考手册 / 25 MySQL NDB 集群 8.4 / 25.7 NDB 集群复制 / 25.7.9 使用 NDB Cluster 复制进行 NDB Cluster 备份
中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 96%

25.7.9 使用 NDB Cluster 复制的 NDB 集群备份25.7.9 NDB Cluster Backups With NDB Cluster Replication

本节讨论使用 NDB 集群复制进行备份和从备份中恢复的操作。我们假设复制服务器已按照前文所述进行配置(参见 第 25.7.5 节,“为 NDB 集群准备复制”,以及紧随其后的各节)。在完成这些操作之后,进行备份并从中恢复的步骤如下:This section discusses making backups and restoring from them using NDB Cluster replication. We assume that the replication servers have already been configured as covered previously (see Section 25.7.5, “Preparing the NDB Cluster for Replication”, and the sections immediately following). This having been done, the procedure for making a backup and then restoring from it is as follows:

  1. 备份可以通过两种不同的方法启动。There are two different methods by which the backup may be started.

    • 方法 A. 这种方法要求在启动复制过程之前,源服务器上已经启用了集群备份过程。可以通过在 [mysql_cluster] 的 my.cnf file 部分中加入以下行来实现,其中 management_host 是源集群 NDB 管理服务器的 IP 地址或主机名,port 是管理服务器的端口号:Method A.  This method requires that the cluster backup process was previously enabled on the source server, prior to starting the replication process. This can be done by including the following line in a [mysql_cluster] section in the my.cnf file, where management_host is the IP address or host name of the NDB management server for the source cluster, and port is the management server's port number:

      ndb-connectstring=management_host[:port]
      
      Note

      只有在未使用默认端口(1186)的情况下才需要指定端口号。有关 NDB 集群中端口和端口分配的更多信息,请参阅 第 25.3.3 节,“NDB 集群的初始配置”。The port number needs to be specified only if the default port (1186) is not being used. See Section 25.3.3, “Initial Configuration of NDB Cluster”, for more information about ports and port allocation in NDB Cluster.

      在这种情况下,可以通过在复制源上执行此语句来启动备份: In this case, the backup can be started by executing this statement on the replication source:

      shellS> ndb_mgm -e "START BACKUP"
      
    • 方法 B. 如果 my.cnf 文件没有指定管理主机的位置,你可以在 NDB 管理客户端中通过 START BACKUP 命令传递此信息来启动备份过程。可以按如下方式操作,其中 management_host 和 port 是管理服务器的主机名和端口号:Method B.  If the my.cnf file does not specify where to find the management host, you can start the backup process by passing this information to the NDB management client as part of the START BACKUP command. This can be done as shown here, where management_host and port are the host name and port number of the management server:

      shellS> ndb_mgm management_host:port -e "START BACKUP"
      

      在我们之前概述的场景中(参见第 25.7.5 节,“为复制准备 NDB 集群”),将按如下方式执行:In our scenario as outlined earlier (see Section 25.7.5, “Preparing the NDB Cluster for Replication”), this would be executed as follows:

      shellS> ndb_mgm rep-source:1186 -e "START BACKUP"
      
  2. 将集群备份文件复制到正在上线的副本。每个运行源集群的 ndbd 进程的系统上都有集群备份文件,所有这些文件必须复制到副本上以确保恢复成功。备份文件可以复制到副本管理主机所在计算机的任何目录,只要 MySQL 和 NDB 二进制文件在该目录有读取权限。在本例中,我们假设这些文件已被复制到目录 /var/BACKUPS/BACKUP-1。Copy the cluster backup files to the replica that is being brought on line. Each system running an ndbd process for the source cluster has cluster backup files located on it, and all of these files must be copied to the replica to ensure a successful restore. The backup files can be copied into any directory on the computer where the replica's management host resides, as long as the MySQL and NDB binaries have read permissions in that directory. In this case, we assume that these files have been copied into the directory /var/BACKUPS/BACKUP-1.

    While it is not necessary that the replica cluster have the same number of data nodes as the source, it is highly recommended this number be the same. It is necessary that the replication process is prevented from starting when the replica server starts. You can do this by starting the replica with --skip-replica-start.

  3. 在复制集群上创建源集群中存在且需要复制的任何数据库。Create any databases on the replica cluster that are present on the source cluster and that are to be replicated.

    Important

    必须在副本集群中的每个 SQL 节点上执行对应于每个要复制的数据库的 CREATE DATABASE(或 CREATE SCHEMA)语句。A CREATE DATABASE (or CREATE SCHEMA) statement corresponding to each database to be replicated must be executed on each SQL node in the replica cluster.

  4. 使用 mysql 客户端中的此语句重置副本集群:Reset the replica cluster using this statement in the mysql client:

    mysqlR> RESET REPLICA;
    
  5. 现在,您可以在副本上使用 ndb_restore 命令依次对每个备份文件启动集群恢复过程。对于第一个备份文件,需要包括 -m 选项以恢复集群元数据,如下所示:You can now start the cluster restoration process on the replica using the ndb_restore command for each backup file in turn. For the first of these, it is necessary to include the -m option to restore the cluster metadata, as shown here:

    shellR> ndb_restore -c replica_host:port -n node-id \
            -b backup-id -m -r dir
    

    dir is the path to the directory where the backup files have been placed on the replica. For the ndb_restore commands corresponding to the remaining backup files, the -m option should 在多线程系统中 be used.dir is the path to the directory where the backup files have been placed on the replica. For the ndb_restore commands corresponding to the remaining backup files, the -m option should not be used.

    要从一个具有四个数据节点的源集群(如图所示,见第 25.7 节,“NDB 集群复制”)进行恢复,并且备份文件已复制到目录/var/BACKUPS/BACKUP-1,在副本上执行的正确命令顺序可能如下所示:For restoring from a source cluster with four data nodes (as shown in the figure in Section 25.7, “NDB Cluster Replication”) where the backup files have been copied to the directory /var/BACKUPS/BACKUP-1, the proper sequence of commands to be executed on the replica might look like this:

    shellR> ndb_restore -c replica-host:1186 -n 2 -b 1 -m \
            -r ./var/BACKUPS/BACKUP-1
    shellR> ndb_restore -c replica-host:1186 -n 3 -b 1 \
            -r ./var/BACKUPS/BACKUP-1
    shellR> ndb_restore -c replica-host:1186 -n 4 -b 1 \
            -r ./var/BACKUPS/BACKUP-1
    shellR> ndb_restore -c replica-host:1186 -n 5 -b 1 -e \
            -r ./var/BACKUPS/BACKUP-1
    
    Important

    在此示例中,最后一次调用 ndb_restore 时使用的 -e(或 --restore-epoch)选项是必须的,以确保 epoch 被写入副本的 mysql.ndb_apply_status 表。没有这些信息,副本无法与源正确同步。(参见 第 25.5.23 节,“ndb_restore — 恢复 NDB 集群备份”。)The -e (or --restore-epoch) option in the final invocation of ndb_restore in this example is required to make sure that the epoch is written to the replica's mysql.ndb_apply_status table. Without this information, the replica cannot synchronize properly with the source. (See Section 25.5.23, “ndb_restore — Restore an NDB Cluster Backup”.)

  6. 现在你需要从副本的 ndb_apply_status 表中获取最新的周期(如 第 25.7.8 节,“使用 NDB 集群复制实现故障切换” 中所讨论):Now you need to obtain the most recent epoch from the ndb_apply_status table on the replica (as discussed in Section 25.7.8, “Implementing Failover with NDB Cluster Replication”):

    mysqlR> SELECT @latest:=MAX(epoch)
            FROM mysql.ndb_apply_status;
    
  7. 使用在上一步中获取的 @latest 作为周期值,你可以从源端的 mysql.ndb_binlog_index 表中获取正确二进制日志文件 @file 中的正确起始位置 @pos。这里显示的查询从逻辑恢复位置之前应用的最后一个周期的 Position 和 File 列中获取这些信息:Using @latest as the epoch value obtained in the previous step, you can obtain the correct starting position @pos in the correct binary log file @file from the mysql.ndb_binlog_index table on the source. The query shown here gets these from the Position and File columns from the last epoch applied before the logical restore position:

    mysqlS> SELECT
         ->     @file:=SUBSTRING_INDEX(File, '/', -1),
         ->     @pos:=Position
         -> FROM mysql.ndb_binlog_index
         -> WHERE epoch > @latest
         -> ORDER BY epoch ASC LIMIT 1;
    

    如果当前没有复制流量,您可以通过在源端运行 SHOW BINARY LOG STATUS 来获取类似信息,并使用输出中 Position 列显示的值,对于在 File 列中所有文件显示的具有最大后缀值的文件名。在这种情况下,您必须确定这是哪个文件,并在下一步手动提供名称或通过脚本解析输出。In the event that there is currently no replication traffic, you can get similar information by running SHOW BINARY LOG STATUS on the source and using the value shown in the Position column of the output for the file whose name has the suffix with the greatest value for all files shown in the File column. In this case, you must determine which file this is and supply the name in the next step manually or by parsing the output with a script.

  8. 使用上一步中获得的值,您现在可以在副本的mysql客户端中发出相应的命令。使用以下CHANGE REPLICATION SOURCE TO语句:Using the values obtained in the previous step, you can now issue the appropriate in the replica's mysql client. Use the following CHANGE REPLICATION SOURCE TO statement:

    mysqlR> CHANGE REPLICATION SOURCE TO
         ->     SOURCE_LOG_FILE='@file',
         ->     SOURCE_LOG_POS=@pos;
    
  9. 现在副本知道从哪个二进制日志文件的哪个位置开始读取源数据,您可以使用此语句使副本开始复制:Now that the replica knows from what point in which binary log file to start reading data from the source, you can cause the replica to begin replicating with this statement:

    mysqlR> START REPLICA;

要在第二个复制通道上执行备份和恢复,只需重复这些步骤,适当地用次要源和副本的主机名及 ID 替换主源和副本的主机名及 ID,并在其上运行前述语句即可。To perform a backup and restore on a second replication channel, it is necessary only to repeat these steps, substituting the host names and IDs of the secondary source and replica for those of the primary source and replica servers where appropriate, and running the preceding statements on them.

有关执行集群备份以及从备份恢复集群的更多信息,请参见 第 25.6.8 节,“NDB 集群的在线备份”。For additional information on performing Cluster backups and restoring Cluster from backups, see Section 25.6.8, “Online Backup of NDB Cluster”.