名称 | 值 |
---|---|
cpu | Intel® Core™ i5-1035G1 CPU @ 1.00GHz |
操作系统 | CentOS Linux release 7.9.2009 (Core) |
内存 | 4G |
逻辑核数 | 3 |
Gbase-8a节点-IP1 | 192.168.142.10 |
Gbase-8a节点-IP2 | 192.168.142.11 |
Gbase-8a数据库版本 | 8.6.2.43-R33.132743 |
GBase 8a MPP Cluster 备份恢复工具gcrcman支持如下:
1、 实例级全量备份。将当前数据库的数据(全集群 gclusterd,gnode 存储的所有数据)全量备份至指定的备份目录中(用户保证创建好)。
2、 实例级增量备份。在指定备份目录中的全量或增量备份数据的基础上,将当前数据库的数据增量备份至该备份目录。
3、 表级全量备份。将某一个表的数据全量备份至备份目录中。
4、 表级增量备份。将某一个表的数据增量备份至备份目录中。
5、 实例级恢复。将备份目录中的指定备份数据,恢复至当前的数据库中。
6、 表级恢复。将备份目录中的单个表的数据,恢复至当前数据库中。
7、 查看备份数据。数据备份后,查看已经备份了哪些数据。
8、 删除备份数据。删除用户指定的备份数据。
9、 删除垃圾数据。由于异常或者用户中断,残留的垃圾备份数据,用户可以通过工具删除。
[gbase@czg0 bin]$ python gcrcman.py -h
SYNOPSIS
gcrcman.py [options] <-d|--path BACKUP_PATH>
OPTIONS:
-h,--help
Print this help
-V,--version
Print version
-d BACKUP_PATH,--path=BACKUP_PATH
Specify backup path, it must be absolute path
-e COMMAND,--execute=COMMAND
Specify backup or recover command
-P HOST_PASSWD,--ospassword=HOST_PASSWD
Specify operation system user gbase's password
-p DATABASE_PASSWD,--dbpassword=DATABASE_PASSWD
Specify database user gbase's password
-r PARALLEL_LEVEL,--parallel=PARALLEL_LEVEL
Specify parallel level. Parallel level is digital in range [1,128], default 4
-D,--disk_space_estimate
Skip estimate disk space before backup or recover
-c,--checksum_database
Skip database data checksum
-C,--checksum_backup_data
Skip backup data checksum
-t SECOND,--timeout=SECOND
Block on read, write or both transaction timeout, should be integar value
in range [0,3600], default[300 secs]. if zero then block indefinitely
backup or recover commands:
1.show backup show backup data
2.backup level <0|1> backup instance
3.backup table <dbname.tablename> level <0|1> backup single table
4.recover [<cycle_id> [point_id]] recover instance
5.recover [force] table <dbname.tablename> [<cycle_id> [point_id]] recover single table
6.delete <cycle_id | last> delete backup data
7.cleanup clean invalid backup data
8.quit exit
9.help
参数名 | 描述 |
---|---|
path | 该参数用于设定备份数据的存放路径。该路径必须是绝对路径,路径中支持“~”的使用。但是,不要将/opt/gcluser 或者/opt/gnode 这两个目录及子目录设置为 path 的路径。在每个节点下面都要有 path 参数指定的路径,且该路径要求有写权限。 |
execute | 该参数用于指定执行的备份恢复命令。 -e 是可选择,有则为命令行模式,无则为交互模式 |
ospassword | 该参数要求用户输入操作系统 gbase 用户的密码,如果不指定,默认为gbase。如果默认密码没有修改,则可以省略该参数。 |
dbpassword | 该参数要求用户输入 GBase 8a MPP Cluster 产品中数据库 gbase 用户的密码,默认为 gbase20110531,如果该密码被修改,请使用修改后的密码。如果默认密码没有修改,则可以省略该参数。 |
parallel | 该参数用于设置备份恢复工具执行的并行度。必须为数字,范围为[1-128]。不指定该参数时,默认为 4。 |
diskestimate | 该参数用于设定是否进行空间预估。默认不使用此参数,即在备份时进行空间预估。 |
checksum_database | 该参数用于设定是否进行 DC 的 checksum 的校验。默认不使用此参数,即在备份时进行 DC 的 checksum 校验。 |
checksum_backup_data | 该参数用于设定是否进行备份数据的校验。默认不使用此参数,即进行备份数据的校验。 |
timeout | 该参数用于设定等待读、写事务的时长,备份时需要等待集群中没有写事务,恢复备份数据时,需要等待集群中没有读和写事务,才可进行后面的操作。该参数值的单位为秒,取值范围为[0,3600],不指定该参数则默认值为 300 秒。0,表示无限等待,如果超时,则报错退出,表示此次备份或恢复失败。 |
[gbase@czg0 bin]$ gcadmin switchmode readonly
========== switch cluster mode...
switch pre mode: [NORMAL]
switch mode to [READONLY]
switch after mode: [READONLY]
[gbase@czg0 bin]$ gcadmin
CLUSTER STATE: ACTIVE
CLUSTER MODE: READONLY
=====================================================================
| GBASE COORDINATOR CLUSTER INFORMATION |
=====================================================================
| NodeName | IpAddress |gcware |gcluster |DataState |
---------------------------------------------------------------------
| coordinator1 | 192.168.142.10 | OPEN | OPEN | 0 |
---------------------------------------------------------------------
| coordinator2 | 192.168.142.11 | OPEN | OPEN | 0 |
---------------------------------------------------------------------
=================================================================
| GBASE DATA CLUSTER INFORMATION |
=================================================================
|NodeName | IpAddress |gnode |syncserver |DataState |
-----------------------------------------------------------------
| node1 | 192.168.142.10 | OPEN | OPEN | 0 |
-----------------------------------------------------------------
| node2 | 192.168.142.11 | OPEN | OPEN | 0 |
-----------------------------------------------------------------
备份语法:
backup level < 0 | 1 >
参数值说明如下:
参数值 | 说明 |
---|---|
0 | 代表对集群数据进行全备份。 |
1 | 代表对集群数据进行基于上次备份的增量备份。 |
[gbase@czg0 bin]$ python gcrcman.py -d /home/gbase/ -p gbase20110531
gcrcman>backup level 0
09.16 15:21:53 BackUp start
--------------------------------------------
09.16 15:21:53 node (192.168.142.10) backup begin
09.16 15:21:53 node (192.168.142.11) backup begin
09.16 15:22:29 node (192.168.142.10) backup success
09.16 15:22:29 node (192.168.142.11) backup success
--------------------------------------------
09.16 15:22:29 BackUp end
gcrcman>show backup
cycle point level time
0 0 0 2022-09-16 15:21:53
gcrcman>backup level 1
09.16 15:24:10 check cluster topology begin
09.16 15:24:10 node (192.168.142.10) check topology begin
09.16 15:24:14 node (192.168.142.10) check topology success
09.16 15:24:14 check cluster topology end
09.16 15:24:14 BackUp start
--------------------------------------------
09.16 15:24:14 node (192.168.142.10) backup begin
09.16 15:24:14 node (192.168.142.11) backup begin
09.16 15:24:47 node (192.168.142.10) backup success
09.16 15:24:47 node (192.168.142.11) backup success
--------------------------------------------
09.16 15:24:47 BackUp end
gcrcman>show backup
cycle point level time
0 0 0 2022-09-16 15:21:53
0 1 1 2022-09-16 15:24:14
[gbase@czg0 bin]$ gcadmin switchmode normal
[gbase@czg0 bin]$ gcadmin
CLUSTER STATE: ACTIVE
CLUSTER MODE: NORMAL
=====================================================================
| GBASE COORDINATOR CLUSTER INFORMATION |
=====================================================================
| NodeName | IpAddress |gcware |gcluster |DataState |
---------------------------------------------------------------------
| coordinator1 | 192.168.142.10 | OPEN | OPEN | 0 |
---------------------------------------------------------------------
| coordinator2 | 192.168.142.11 | OPEN | OPEN | 0 |
---------------------------------------------------------------------
=================================================================
| GBASE DATA CLUSTER INFORMATION |
=================================================================
|NodeName | IpAddress |gnode |syncserver |DataState |
-----------------------------------------------------------------
| node1 | 192.168.142.10 | OPEN | OPEN | 0 |
-----------------------------------------------------------------
| node2 | 192.168.142.11 | OPEN | OPEN | 0 |
-----------------------------------------------------------------
[gbase@czg0 bin]$ gccli -uroot -pqwer1234
GBase client 8.6.2.43-R33.132743. Copyright (c) 2004-2022, GBase. All Rights Reserved.
gbase> use czg;
Query OK, 0 rows affected (Elapsed: 00:00:00.00)
gbase> create table test_2022_09_16(a int);
Query OK, 0 rows affected, 1 warning (Elapsed: 00:00:00.16)
gbase> insert into test_2022_09_16 values(1);
Query OK, 1 row affected, 1 warning (Elapsed: 00:00:00.13)
gbase> commit;
Query OK, 0 rows affected (Elapsed: 00:00:00.00)
[gbase@czg0 bin]$ gcadmin switchmode readonly
========== switch cluster mode...
switch pre mode: [NORMAL]
switch mode to [READONLY]
switch after mode: [READONLY]
[gbase@czg0 bin]$ python gcrcman.py -d /home/gbase/ -p gbase20110531
gcrcman>backup level 1
09.16 15:31:36 check cluster topology begin
09.16 15:31:36 node (192.168.142.10) check topology begin
09.16 15:31:39 node (192.168.142.10) check topology success
09.16 15:31:39 check cluster topology end
09.16 15:31:39 BackUp start
--------------------------------------------
09.16 15:31:39 node (192.168.142.10) backup begin
09.16 15:31:39 node (192.168.142.11) backup begin
09.16 15:32:12 node (192.168.142.10) backup success
09.16 15:32:12 node (192.168.142.11) backup success
--------------------------------------------
09.16 15:32:12 BackUp end
gcrcman>
gcrcman>
gcrcman>show backup
cycle point level time
0 0 0 2022-09-16 15:21:53
0 1 1 2022-09-16 15:24:14
0 2 1 2022-09-16 15:31:39
就是说cycle : 0,point :2中有测试数据表test_2022_09_16,其他备份里没有。
[gbase@czg0 bin]$ gcadmin switchmode recovery
========== switch cluster mode...
switch pre mode: [READONLY]
switch mode to [RECOVERY]
switch after mode: [RECOVERY]
[gbase@czg0 bin]$ gcadmin
CLUSTER STATE: ACTIVE
CLUSTER MODE: RECOVERY
=====================================================================
| GBASE COORDINATOR CLUSTER INFORMATION |
=====================================================================
| NodeName | IpAddress |gcware |gcluster |DataState |
---------------------------------------------------------------------
| coordinator1 | 192.168.142.10 | OPEN | OPEN | 0 |
---------------------------------------------------------------------
| coordinator2 | 192.168.142.11 | OPEN | OPEN | 0 |
---------------------------------------------------------------------
=================================================================
| GBASE DATA CLUSTER INFORMATION |
=================================================================
|NodeName | IpAddress |gnode |syncserver |DataState |
-----------------------------------------------------------------
| node1 | 192.168.142.10 | OPEN | OPEN | 0 |
-----------------------------------------------------------------
| node2 | 192.168.142.11 | OPEN | OPEN | 0 |
-----------------------------------------------------------------
语法:
recover [<cycle_id> [point_id]]
参数说明如下:
参数 | 描述 |
---|---|
cycle_id | 备份周期的 ID。 |
point_id | 备份点的 ID。 |
recover 命令有以下三种形式:
(1) recover:将数据库恢复到最新周期的最新备份点。
(2) recover cycle_id:将数据库恢复到指定周期 cycle_id 内的最新备份点。
(3)recover cycle_id point_id:将数据库恢复到指定周期 cycle_id 内的指定备份点 point_id。
[gbase@czg0 bin]$ python gcrcman.py -d /home/gbase/ -p gbase20110531
gcrcman>
gcrcman>show backup
cycle point level time
0 0 0 2022-09-16 15:21:53
0 1 1 2022-09-16 15:24:14
0 2 1 2022-09-16 15:31:39
gcrcman>recover 0 1
09.16 15:34:35 check cluster topology begin
09.16 15:34:35 node (192.168.142.10) check topology begin
09.16 15:34:38 node (192.168.142.10) check topology success
09.16 15:34:38 check cluster topology end
09.16 15:34:38 check BackUp start
--------------------------------------------
09.16 15:34:38 node (192.168.142.10) check backup begin
09.16 15:34:38 node (192.168.142.11) check backup begin
09.16 15:34:53 node (192.168.142.10) check backup success
09.16 15:34:53 node (192.168.142.11) check backup success
--------------------------------------------
09.16 15:34:53 check BackUp success
09.16 15:34:53 Recover start
--------------------------------------------
09.16 15:34:53 node (192.168.142.10) Recover begin
09.16 15:34:53 node (192.168.142.11) Recover begin
09.16 15:35:21 node (192.168.142.10) Recover success
09.16 15:35:21 node (192.168.142.11) Recover success
--------------------------------------------
09.16 15:35:21 Recover success
[gbase@czg0 bin]$ gccli -uroot -pqwer1234
GBase client 8.6.2.43-R33.132743. Copyright (c) 2004-2022, GBase. All Rights Reserved.
gbase> use czg;
Query OK, 0 rows affected (Elapsed: 00:00:00.00)
gbase> show tables;
+-------------------------------+
| Tables_in_czg |
+-------------------------------+
| events_list |
| l_pty_cus_policy_renewal_0714 |
| liketab |
| sun |
| sun1 |
| sun_copy |
| sun_date |
+-------------------------------+
7 rows in set (Elapsed: 00:00:00.00)
没有test_2022_09_16表,不完全恢复成功,cycle : 0,point :1中没有此表数据。
[gbase@czg0 bin]$ python gcrcman.py -d /home/gbase/ -p gbase20110531
gcrcman>recover 0 2
09.16 15:36:03 check cluster topology begin
09.16 15:36:03 node (192.168.142.10) check topology begin
09.16 15:36:07 node (192.168.142.10) check topology success
09.16 15:36:07 check cluster topology end
09.16 15:36:07 check BackUp start
--------------------------------------------
09.16 15:36:07 node (192.168.142.10) check backup begin
09.16 15:36:07 node (192.168.142.11) check backup begin
09.16 15:36:24 node (192.168.142.10) check backup success
09.16 15:36:24 node (192.168.142.11) check backup success
--------------------------------------------
09.16 15:36:24 check BackUp success
09.16 15:36:24 Recover start
--------------------------------------------
09.16 15:36:24 node (192.168.142.10) Recover begin
09.16 15:36:24 node (192.168.142.11) Recover begin
09.16 15:36:51 node (192.168.142.10) Recover success
09.16 15:36:51 node (192.168.142.11) Recover success
--------------------------------------------
09.16 15:36:51 Recover success
[gbase@czg0 bin]$ gcadmin switchmode normal
========== switch cluster mode...
switch pre mode: [RECOVERY]
switch mode to [NORMAL]
switch after mode: [NORMAL]
恢复成功,可以正常查询到test_2022_09_16表。
[gbase@czg0 bin]$ gccli -uroot -pqwer1234
GBase client 8.6.2.43-R33.132743. Copyright (c) 2004-2022, GBase. All Rights Reserved.
gbase> use czg;
Query OK, 0 rows affected (Elapsed: 00:00:00.00)
gbase> select * from test_2022_09_16;
+------+
| a |
+------+
| 1 |
+------+
1 row in set (Elapsed: 00:00:00.01)
语法:
delete <cycle_id | last>
参数说明如下:
参数 | 描述 |
---|---|
cycle_id | 备份周期的 id。 |
last | 最后一个备份点 id。 |
使用场景:
由于在实际应用中,一般会采用“全-增-全-增……”的模式,首先进行一次全备,之后进行若干次增备,再进行全备,之后进行若干此增备,依次循环备份操作过程。
在备份过程累计操作一段时间后,会积累大量的陈旧备份记录,因此,用户可以通过该命令进行备份记录的清除。
delete 命令有以下两种形式:
1、 delete cycle_id:删除一个周期内的全部备份记录。按此选项执行后,将删除周期为 cycle_id 的所有备份点的备份记录。
2、 delete last:删除备份记录中的最后一个备份点。按此选项执行后,将删除最后一个周期内的最后一个备份点的备份记录。
删除的备份记录规则如下:
1、删除主分片节点中 path 中对应的备份记录文件。
2、如果其他节点中的 gcrcman.py指定的path,曾经从主分片节点的path中进行过拷贝操作,那么这些非主分片节点集群中 path 内的备份文件将会全部被删除。
[gbase@czg0 bin]$ python gcrcman.py -d /home/gbase/ -p gbase20110531
gcrcman>show backup
cycle point level time
0 0 0 2022-09-16 15:21:53
0 1 1 2022-09-16 15:24:14
0 2 1 2022-09-16 15:31:39
gcrcman>delete last
09.16 15:46:56 Delete BackUp Points start
--------------------------------------------
09.16 15:46:56 node (192.168.142.10) delete begin
09.16 15:46:56 node (192.168.142.11) delete begin
09.16 15:46:58 node (192.168.142.10) delete success
09.16 15:46:58 node (192.168.142.11) delete success
--------------------------------------------
09.16 15:46:58 Delete BackUp Points end
gcrcman>show backup
cycle point level time
0 0 0 2022-09-16 15:21:53
0 1 1 2022-09-16 15:24:14