測試start backupnode
#############################################mysql
//備份概念sql
1.備份時當前數據庫的一個快照,備份包含下面三部分shell
A.metadata:數據庫的定義和結構數據庫
B.table records:存儲在表中到數據測試
C.transaction log: 記錄數據存儲的時間this
2.每一個備份存儲在全部的節點上,備份文件由三個文件組成:spa
BACKUP-backup_id.node_id.ctlrest
BACKUP-backup_id-0.node_id.dataorm
BACKUP-backup_id.node_id.log
3.backup_id標識每一次備份,node_id表示建立備份文件的節點
//start backup語法
START BACKUP [backup_id] [wait_option] [snapshot_option]
backup_id:大於等於1的整數,不能重複
wait_option:WAIT {STARTED | COMPLETED}
wait started:等待直到備份啓動 默認
wait completed :等待備份完成
snapshot_option:
SNAPSHOTSTART | SNAPSHOTEND
SNAPSHOTSTART:匹配備份開始時集羣的狀態
SNAPSHOTEND: 備份反映備份完成時集羣到狀態 默認
//備份操做
1.在管理節點上進行
ndb_mgm> start backup 7 wait completed snapshotstart
Waiting for completed, this may take several minutes
Node 2: Backup 7 started from node 1
Node 2: Backup 7 started from node 1 completed
StartGCP: 4696 StopGCP: 4699
#Records: 2073 #LogRecords: 0
Data: 54164 bytes Log: 0 bytes
2.在node=3上查看數據節點備份文件
/data/backup/BACKUP/BACKUP-6
shell> ll
-rw-r--r-- 1 root root 14056 2月 28 09:54 BACKUP-6-0.3.Data
-rw-r--r-- 1 root root 25616 2月 28 09:54 BACKUP-6.3.ctl
-rw-r--r-- 1 root root 52 2月 28 09:54 BACKUP-6.3.log
-----------------------------------------------------------
測試ndb_restore
###################################################
1.環境介紹
管理節點:154
四臺 data/sql節點:154/155/156/157
2.cluster當前狀態
[ndbd(NDB)] 4 node(s)
id=2 @10.10.54.154 (mysql-5.5.35 ndb-7.2.15, Nodegroup: 0, *)
id=3 @10.10.54.155 (mysql-5.5.35 ndb-7.2.15, Nodegroup: 0)
id=4 @10.10.54.156 (mysql-5.5.35 ndb-7.2.15, Nodegroup: 1)
id=5 @10.10.54.157 (mysql-5.5.35 ndb-7.2.15, Nodegroup: 1)
[ndb_mgmd(MGM)] 1 node(s)
id=1 @10.10.54.154 (mysql-5.5.35 ndb-7.2.15)
[mysqld(API)] 8 node(s)
id=7 @10.10.54.154 (mysql-5.5.35 ndb-7.2.15)
id=9 @10.10.54.155 (mysql-5.5.35 ndb-7.2.15)
id=10 @10.10.54.156 (mysql-5.5.35 ndb-7.2.15)
id=11 @10.10.54.157 (mysql-5.5.35 ndb-7.2.15)
id=12 (not connected, accepting connect from any host)
id=13 (not connected, accepting connect from any host)
id=14 (not connected, accepting connect from any host)
id=15 (not connected, accepting connect from any host)
3.全部數據節點上數據庫狀態
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| employees |
| mysql |
| ndb_2_fs |
| ndbinfo |
| performance_schema |
| test |
+--------------------+
//管理機:先建立新數據庫和表,而後執行備份命令
1.建立測試數據
mysql> create database d1;
mysql> use d1;
mysql> create table d1_t1(id int NOT NULL) engine=ndb;
mysql> create table d1_t2(id int NOT NULL) engine=ndb;
mysql> insert into d1_t1 values(1),(2);
mysql> insert into d1_t2 values(1),(2);
mysql> show tables;
+--------------+
| Tables_in_d1 |
+--------------+
| d1_t1 |
| d1_t2 |
+--------------+
2.執行備份命令
ndb_mgm> start backup 4
Waiting for completed, this may take several minutes
Node 2: Backup 4 started from node 1
Node 2: Backup 4 started from node 1 completed
StartGCP: 540 StopGCP: 543
#Records: 2070 #LogRecords: 0
Data: 53152 bytes Log: 0 bytes
//關閉並重啓cluster
關閉順序
sql節點---data節點---管理節點
啓動cluster
1.啓動管理節點
shell> ndb_mgmd -f /var/lib/mysql-cluster/config.ini
2.開啓data節點
shell> ndbd --initial #--initial操做會清空全部表和數據
2014-02-28 13:19:25 [ndbd] INFO -- Angel connected to '10.10.54.154:1186'
2014-02-28 13:19:25 [ndbd] INFO -- Angel allocated nodeid: 2
3.開啓sql節點
/etc/init.d/mysqld start
//再次建立新數據庫和表,驗證增量備份
1.建立新數據庫
mysql> create database d2;
mysql> use d2;
mysql> create table d2_t1(id int NOT NULL) engine=ndb;
mysql> insert into d2_t1 values(1),(2);
mysql> show tables;
+--------------+
| Tables_in_d2 |
+--------------+
| d2_t1 |
+--------------+
//恢復數據,並查看數據庫中數據
1.說明
A.以前的操做流程爲:
建立d1----備份----建立d2&&刪除d1----恢復數據
B.恢復數據後驗證的是:
d1數據庫被恢復,d2數據庫仍保留
2.在四個data節點上都執行恢復操做
shell> ndb_restore -c 10.10.54.154 -n 2 -m -b 4 -r /data/backup/BACKUP/BACKUP-4/
shell> ndb_restore -c 10.10.54.154 -n 3 -b 4 -r /data/backup/BACKUP/BACKUP-4/
shell> ndb_restore -c 10.10.54.154 -n 4 -b 4 -r /data/backup/BACKUP/BACKUP-4/
shell> ndb_restore -c 10.10.54.154 -n 5 -b 4 -r /data/backup/BACKUP/BACKUP-4/
#-c:管理節點
#-n:當前恢復節點,變化
#-m:第一次恢復時須要加
#-b:執行備份時的備份id
#-r:備份文件位置
3.部分結果
shell> ndb_restore -c 10.10.54.154 -n 2 -m -b 4 -r /data/backup/BACKUP/BACKUP-4/
Nodeid = 2
Backup Id = 4
backup path = /data/backup/BACKUP/BACKUP-4/
Opening file '/data/backup/BACKUP/BACKUP-4/BACKUP-4.2.ctl'
File size 23040 bytes
Backup version in files: ndb-6.3.11 ndb version: mysql-5.5.35 ndb-7.2.15
Stop GCP of Backup: 542
Connected to ndb!!
Successfully restored table `d1/def/d1_t1`
Successfully restored table event REPL$d1/d1_t1
...
NDBT_ProgramExit: 0 - OK
4.驗證d1數據庫恢復,d2保留
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| d1 |
| d2 |
...
mysql> use d1;
mysql> show tables;
+--------------+
| Tables_in_d1 |
+--------------+
| d1_t2 |
| d1_t1 |
+--------------+
###d1數據庫中的表成功恢復
mysql> use d2;
mysql> show tables;
+--------------+
| Tables_in_d2 |
+--------------+
| d2_t1 |
+--------------+
mysql> select * from d2_t1;
+----+
| id |
+----+
| 2 |
| 1 |
+----+
###d2數據庫中的數據被保留