4.6.2.3 部分恢复——丢失的图像

可以使用 MySQL Cluster Manager 执行 MySQL NDB Cluster 的部分恢复——也就是说,从一个或多个数据节点的备份映像不可用的备份中恢复。如果我们希望恢复 mycluster到备份编号 6,这是必需的,因为此备份的映像仅适用于节点 1,如mcmlist backups客户端的输出所示:

mcm> list backups mycluster;
+----------+--------+---------+---------------------+--------+---------+
| BackupId | NodeId | Host    | Timestamp           | Parts  | Comment |
+----------+--------+---------+---------------------+--------+---------+
| 1        | 1      | tonfisk | 2020-12-04 12:03:52 | 1      |         |
| 1        | 2      | tonfisk | 2020-12-04 12:03:52 | 1      |         |
| 2        | 1      | tonfisk | 2020-12-04 12:04:15 | 1      |         |
| 2        | 2      | tonfisk | 2020-12-04 12:04:15 | 1      |         |
| 3        | 1      | tonfisk | 2020-12-04 12:17:41 | 1      |         |
| 3        | 2      | tonfisk | 2020-12-04 12:17:41 | 1      |         |
| 4        | 1      | tonfisk | 2020-12-12 14:24:35 | 1      |         |
| 4        | 2      | tonfisk | 2020-12-12 14:24:35 | 1      |         |
| 5        | 1      | tonfisk | 2020-12-12 14:31:31 | 1      |         |
| 5        | 2      | tonfisk | 2020-12-12 14:31:31 | 1      |         |
| 6        | 1      | tonfisk | 2020-12-12 14:32:09 | 1      |         |
+----------+--------+---------+---------------------+--------+---------+
11 rows in set (0.08 sec)

要仅恢复我们有图像的那些节点(在本例中,仅节点 1),我们可以 --skip-nodeid 在执行restore cluster命令时使用该选项。此选项会导致在执行还原时跳过一个或多个节点。假设 mycluster已清除数据(如本节前面所述),我们可以执行跳过节点 2 的恢复,如下所示:

mcm> restore cluster --backupid=6 --skip-nodeid=2 mycluster;
+--------------------------------+
| Command result                 |
+--------------------------------+
| Restore completed successfully |
+--------------------------------+
1 row in set (17.06 sec)

因为我们从恢复过程中排除了节点 2,所以没有数据分发给它。为了使 MySQL NDB Cluster 数据在部分恢复后分发到任何此类排除或跳过的节点,有必要通过在mysql客户端中为集群中的每个 表执行 ALTER ONLINE TABLE ... REORGANIZE PARTITION语句来手动重新分发数据。要从mysql客户端获取表 列表,您可以使用多个 语句或一个查询,例如: NDBNDBSHOW TABLES

SELECT CONCAT('' TABLE_SCHEMA, '.', TABLE_NAME)
    FROM INFORMATION_SCHEMA.TABLES
    WHERE ENGINE='ndbcluster';

您可以使用刚刚显示的查询的更详细版本生成必要的 SQL 语句,例如此处使用的查询:

mysql> SELECT
    ->     CONCAT('ALTER ONLINE TABLE `', TABLE_SCHEMA,
    ->            '`.`', TABLE_NAME, '` REORGANIZE PARTITION;')
    ->     AS Statement
    -> FROM INFORMATION_SCHEMA.TABLES
    -> WHERE ENGINE='ndbcluster';
+--------------------------------------------------------------------------+
| Statement                                                                |
+--------------------------------------------------------------------------+
| ALTER ONLINE TABLE `mysql`.`ndb_apply_status` REORGANIZE PARTITION;      |
| ALTER ONLINE TABLE `mysql`.`ndb_index_stat_head` REORGANIZE PARTITION;   |
| ALTER ONLINE TABLE `mysql`.`ndb_index_stat_sample` REORGANIZE PARTITION; |
| ALTER ONLINE TABLE `db1`.`n1` REORGANIZE PARTITION;                      |
| ALTER ONLINE TABLE `db1`.`n2` REORGANIZE PARTITION;                      |
| ALTER ONLINE TABLE `db1`.`n3` REORGANIZE PARTITION;                      |
| ALTER ONLINE TABLE `test`.`n1` REORGANIZE PARTITION;                     |
| ALTER ONLINE TABLE `test`.`n2` REORGANIZE PARTITION;                     |
| ALTER ONLINE TABLE `test`.`n3` REORGANIZE PARTITION;                     |
| ALTER ONLINE TABLE `test`.`n4` REORGANIZE PARTITION;                     |
+--------------------------------------------------------------------------+
10 rows in set (0.09 sec)