[MySQL 6.0 体验] 集群(cluster)+复制(replicate) -- 备份、恢复
6. 备份、恢复
6.1. 备份
集群的备份很简单,只需在管理节点上执行START BACKUP 即可:
ndb_mgm> START BACKUP Waiting for completed, this may take several minutes Node 3: Backup 4 started from node 1 Node 3: Backup 4 started from node 1 completed StartGCP: 7847 StopGCP: 7850 #Records: 1736024 #LogRecords: 0 Data: 41649824 bytes Log: 0 bytes
6.2. 恢复
来做个实际的测试,在SQL节点上先制造一些数据出来:
mysql> show tables; +----------------+ | Tables_in_test | +----------------+ | a | +----------------+ 1 row in set (0.01 sec) mysql> show create table a; +-------+-------------------------------------------------------------------------------------------+ | Table | Create Table | +-------+-------------------------------------------------------------------------------------------+ | a | CREATE TABLE `a` ( `id` int(11) DEFAULT NULL ) ENGINE=ndbcluster DEFAULT CHARSET=latin1 | +-------+-------------------------------------------------------------------------------------------+ 1 row in set (0.01 sec) mysql> select count(*) from a; +----------+ | count(*) | +----------+ | 1733965 | +----------+ 1 row in set (0.03 sec) mysql> checksum table a; +--------+------------+ | Table | Checksum | +--------+------------+ | test.a | 1641855839 | +--------+------------+ 1 row in set (11.61 sec)
然后用上面提到的方法进行备份后,删除该表的数据:
mysql> truncate table a; Query OK, 0 rows affected (0.68 sec)
接下来在2个数据节点上分别执行以下命令恢复数据:
/usr/local/mysql/bin/ndb_restore -n 3 -b 5 -r data/BACKUP/BACKUP-3 Nodeid = 3 Backup Id = 5 backup path = data/BACKUP/BACKUP-5 Opening file 'data/BACKUP/BACKUP-5/BACKUP-5.3.ctl' File size 8120 bytes Ndb version in backup files: ndb-6.2.6 Connected to ndb!! Opening file 'data/BACKUP/BACKUP-5/BACKUP-5-0.3.Data' File size 20809008 bytes _____________________________________________________ Processing data in table: sys/def/NDB$EVENTS_0(1) fragment 0 _____________________________________________________ Processing data in table: test/def/a(5) fragment 0 _____________________________________________________ Processing data in table: mysql/def/ndb_apply_status(4) fragment 0 _____________________________________________________ Processing data in table: mysql/def/NDB$BLOB_2_3(3) fragment 0 _____________________________________________________ Processing data in table: sys/def/SYSTAB_0(0) fragment 0 _____________________________________________________ Processing data in table: mysql/def/ndb_schema(2) fragment 0 Opening file 'data/BACKUP/BACKUP-5/BACKUP-5.3.log' File size 44 bytes Restored 866287 tuples and 0 log entries NDBT_ProgramExit: 0 - OK
再在SQL节点上查一下:
mysql> select count(*) from a; +----------+ | count(*) | +----------+ | 866287 | +----------+ 1 row in set (0.00 sec)
然后在另一个数据节点上执行恢复。
/usr/local/mysql/bin/ndb_restore -n 4 -b 5 -r data/BACKUP/BACKUP-3 Nodeid = 4 Backup Id = 5 backup path = data/BACKUP/BACKUP-5 Opening file 'data/BACKUP/BACKUP-5/BACKUP-5.4.ctl' File size 8120 bytes Ndb version in backup files: ndb-6.2.6 Connected to ndb!! Opening file 'data/BACKUP/BACKUP-5/BACKUP-5-0.4.Data' File size 20841232 bytes _____________________________________________________ Processing data in table: sys/def/NDB$EVENTS_0(1) fragment 1 _____________________________________________________ Processing data in table: test/def/a(5) fragment 1 _____________________________________________________ Processing data in table: mysql/def/ndb_apply_status(4) fragment 1 _____________________________________________________ Processing data in table: mysql/def/NDB$BLOB_2_3(3) fragment 1 _____________________________________________________ Processing data in table: sys/def/SYSTAB_0(0) fragment 1 _____________________________________________________ Processing data in table: mysql/def/ndb_schema(2) fragment 1 Opening file 'data/BACKUP/BACKUP-5/BACKUP-5.4.log' File size 44 bytes Restored 867678 tuples and 0 log entries NDBT_ProgramExit: 0 – OK
再来查一次看看:
mysql> checksum table a; +--------+------------+ | Table | Checksum | +--------+------------+ | test.a | 1641855839 | +--------+------------+ 1 row in set (11.62 sec)
恢复完毕。
最近评论