在delete误删数据之后,没有再对此表进行其他ddl、dml和load等操作,可以使用手动切换AB版本的方式来进行数据恢复。
名称 | 值 |
CPU | Intel(R) Core(TM) i5-1035G1 CPU @ 1.00GHz |
操作系统 | CentOS Linux release 7.9.2009 (Core) |
内存 | 3G |
逻辑核数 | 2 |
Gbase8a版本 | 8.6.2-R43.34.27468a27 |
我这边只有一个节点,且没有备份。
[gbase@czg2 t1_n1.GED]$ gcadmin
CLUSTER STATE: ACTIVE
CLUSTER MODE: NORMAL
=====================================================================
| GBASE COORDINATOR CLUSTER INFORMATION |
=====================================================================
| NodeName | IpAddress |gcware |gcluster |DataState |
---------------------------------------------------------------------
| coordinator1 | 192.168.142.12 | OPEN | OPEN | 0 |
---------------------------------------------------------------------
=================================================================
| GBASE DATA CLUSTER INFORMATION |
=================================================================
|NodeName | IpAddress |gnode |syncserver |DataState |
-----------------------------------------------------------------
| node1 | 192.168.142.12 | OPEN | OPEN | 0 |
-----------------------------------------------------------------
[gbase@czg2 t1_n1.GED]$ gcadmin showdistribution
Distribution ID: 1 | State: new | Total segment num: 1
Primary Segment Node IP Segment ID Duplicate Segment node IP
========================================================================================================================
| 192.168.142.12 | 1 | |
========================================================================================================================
gbase> create table t1 (c1 int,c2 varchar(100));
Query OK, 0 rows affected (Elapsed: 00:00:00.16)
gbase> insert into t1 values(1,'czg');
Query OK, 1 row affected (Elapsed: 00:00:00.14)
gbase> insert into t1 values(2,'zxj');
Query OK, 1 row affected (Elapsed: 00:00:00.01)
gbase> delete from czg.t1 where c1 in (1);
Query OK, 1 row affected (Elapsed: 00:00:00.05)
我们切换到t1表的元数据目录,元数据是分A、B两个版本,table.delete.A是做过delete操作才会有的。
[gbase@czg2 t1_n1.GED]$ pwd
/opt/gnode/userdata/gbase/czg/metadata/t1_n1.GED
[gbase@czg2 t1_n1.GED]$ ll
总用量 44
-rw------- 1 gbase gbase 129 8月 8 08:59 C00000.ctl.A
-rw------- 1 gbase gbase 129 8月 8 08:59 C00000.ctl.B
-rw------- 1 gbase gbase 106 8月 8 08:59 C00000.map
-rw------- 1 gbase gbase 113 8月 8 08:59 C00001.ctl.A
-rw------- 1 gbase gbase 113 8月 8 08:59 C00001.ctl.B
-rw------- 1 gbase gbase 106 8月 8 08:59 C00001.map
-rw------- 1 gbase gbase 26 8月 8 09:11 table.delete.A
-rw------- 1 gbase gbase 237 8月 8 09:11 table.des.A
-rw------- 1 gbase gbase 237 8月 8 08:59 table.des.B
-rw------- 1 gbase gbase 52 8月 8 09:11 table.state.A
-rw------- 1 gbase gbase 52 8月 8 08:59 table.state.B
两个版本我们怎么确认此表当前用的是哪个版本呢,上面的目录中没有lock文件,表示用的版本A。如果有的话,表示用的版本B。
[gbase@czg2 t1_n1.GED]$ metadump table.state.A
This tool is designed for use at GBase internally,and is unsupported externally.
GBase makes no claims and holds no liability regarding the external use of this tool.
This tool is copyrighted and his redistribution is restricted.
table.state.A
+-------------------------------------+-----------------+
| TABLE_STATE_VERSION | 65536 |
| sizeof(int) | 4 |
| self_version | 1 |
| TABLE_STATE_TABLE_INFO | 196608 |
| sizeof(int) + sizeof(uint64) | 12 |
| table_scn | 7471108 |
| table_last_operation | DELETE |
| TABLE_STATE_TABLE_VERSION | 131072 |
| sizeof(int)*3 | 12 |
| ctl_version | B |
| des_version | A |
| delete_version | A |
+-------------------------------------+-----------------+
查看A版本此表元数据信息,主要看几个点table_last_operation:delete,table_scn:7471108。
[gbase@czg2 t1_n1.GED]$ gncli
GBase client 8.6.2-R43.34.27468a27. Copyright (c) 2004-2023, GBase. All Rights Reserved.
gbase> select table_schema,table_name,scn from information_schema.tables where table_schema='czg' and table_name='t1_n1';
+--------------+------------+---------+
| table_schema | table_name | scn |
+--------------+------------+---------+
| czg | t1_n1 | 7471108 |
+--------------+------------+---------+
1 row in set (Elapsed: 00:00:00.01)
通过数据字典表查看scn号为7471108 和上面能够对应上。
[gbase@czg2 metadata]$ cp -r t1_n1.GED t1_n1.GED_BAK
两个方法选其中一个即可,我这边用的是第一种进行测试验证。
我这边删除的数据只涉及一个分片n1,而且没有备份分片,如果实际情况中涉及了多个分片或有备份分片,也都需要执行SQL。
[gbase@czg2 t1_n1.GED]$ gncli
GBase client 8.6.2-R43.34.27468a27. Copyright (c) 2004-2023, GBase. All Rights Reserved.
gbase> revert table czg.t1_n1 scn_number 7471108;
Query OK, 0 rows affected (Elapsed: 00:00:00.09)
上面我们说过:没有lock文件,表示用的版本A。如果有的话,表示用的版本B。
我们是A版本,切换到B版本,所以touch一个lock文件即可。反之删除lock文件即可。
[gbase@czg2 t1_n1.GED]$ gccli
GBase client 8.6.2-R43.34.27468a27. Copyright (c) 2004-2023, GBase. All Rights Reserved.
gbase> refresh table czg.t1;
Query OK, 0 rows affected (Elapsed: 00:00:00.01)
gbase> select * from czg.t1;
+------+------+
| c1 | c2 |
+------+------+
| 1 | czg |
| 2 | zxj |
+------+------+
2 rows in set (Elapsed: 00:00:00.10)