暂无图片
暂无图片
1
暂无图片
暂无图片
暂无图片

GBase 8s 学习笔记 011 —— GBase 8s 备份与恢复:基于ontape的备份与恢复

心有阳光 2023-02-16
992

GBase 8s 学习笔记 011 —— GBase 8s 备份与恢复:基于ontape的备份与恢复

ontape简介

使用ontape,可以进行GBase 8s数据库的备份与恢复。

  • ontape支持L0,L1,L2三级备份与恢复。
  • ontape支持逻辑日志的备份与恢复。
  • ontape本身不支持基于时间点的恢复,但可通过其它工具,将ontape备份的单个表中数据,恢复到指定的时间点(暂不讨论)。基于时间点的数据库备份与恢复,建议使用onbar实现。

备份命令:

命令 说明
ontape -s -L 0 进行L0级备份
ontape -s -L 1 进行L1级备份
ontape -s -L 2 进行L2级备份
ontape -a 进行自动逻辑日志备份
ontape -c 启动连续逻辑日志备份
ontape -S 抢救逻辑日志

恢复命令

命令 说明
ontape -r 完成恢复
ontape -p 进行物理恢复
ontape -l 进行逻辑恢复
ontape -C 连续逻辑日志恢复
ontape -X 停止连续逻辑日志恢复

业务场景模拟规划

模拟数据库在遇到数据库空间文件被删除时和表被删除时,如何尽可能的抢救数据。

时间 业务 说明
t1 系统上线 创建t_dept和t_employee
t2 t_dept新增3条数据
t3 t_employee新增5条数据
t4 系统进行L0备份 用于验证L0物理恢复
t5 t_employee新增5条数据
t6 系统进行L1备份
t7 t_employee新增1条数据
t8 系统进行L1备份 用于观察多次备份对文件名的影响
t9 t_employee新增5条数据
t10 系统进行L2备份 用于验证L2物理恢复
t11 t_dept新增1条数据
t12 t_employee更新1条数据
t13 切换逻辑日志 模拟因业务变化导致日志切换
t14 t_employee删除1条数据
t15 删除Chunk文件 模拟灾难
t16 t_dept新增1条数据
t17 备份逻辑日志
t18 进行完全恢复
t19 t_employee新增5条数据
t20 删除t_employee表 模拟灾难
t21 尝试L0级物理恢复
t22 尝试L1级物理恢复
t23 尝试L2级物理恢复
t24 尝试L2级物理恢复+部分逻辑恢复

备份/恢复操作演示

ontape环境参数设置

使用ontape进行数据库的备份与恢复时,需要设置ontape默认使用的存储设备。

可通过修改参数文件,或使用 onmode -wf 命令,设置GBase 8s的参数。可通过 onstat -c 命令,查看GBase 8s的参数设置。

检查 GBase 8s 备份的存储设备参数,发现未指定备份存储设备。

[gbasedbt@localhost ~]$ onstat -c | grep TAPEDEV | grep -v '#' Your evaluation license will expire on 2024-02-14 00:00:00 TAPEDEV /dev/null LTAPEDEV /dev/null [gbasedbt@localhost ~]$

GBase202.png备份与恢复

创建一个目录,并设置物理备份和逻辑备份的存储设备为新创建的目录。

[gbasedbt@localhost ~]$ mkdir backup [gbasedbt@localhost ~]$ onmode -wf "TAPEDEV=/home/gbasedbt/backup" Your evaluation license will expire on 2024-02-14 00:00:00 Value of TAPEDEV has been changed to /home/gbasedbt/backup. [gbasedbt@localhost ~]$ onmode -wf "LTAPEDEV=/home/gbasedbt/backup" Your evaluation license will expire on 2024-02-14 00:00:00 Value of LTAPEDEV has been changed to /home/gbasedbt/backup. [gbasedbt@localhost ~]$

GBase203.png备份与恢复

查看备份设备参数,已经指向新创建的目录。

[gbasedbt@localhost ~]$ onstat -c | grep TAPEDEV | grep -v '#' Your evaluation license will expire on 2024-02-14 00:00:00 TAPEDEV /home/gbasedbt/backup LTAPEDEV /home/gbasedbt/backup [gbasedbt@localhost ~]$

GBase204.png备份与恢复

实验步骤

  • 步骤1:创建数据库与表
[gbasedbt@localhost ~]$ dbaccess - - Your evaluation license will expire on 2024-02-14 00:00:00 > create database mydb in datadbs1 with log; Database created. > create table t_dept(f_deptid int, f_deptname varchar(20)); Table created. > create table t_employee(f_employeeid int, f_deptid int, f_employeename varchar(20)); Table created. > info tables; Table name t_dept t_employee >

GBase206.png备份与恢复

  • 步骤2:L0备份前的数据准备
> insert into t_dept values(1, 'dept_1'); insert into t_dept values(2, 'dept_2'); insert into t_dept values(3, 'dept_3'); 1 row(s) inserted. > 1 row(s) inserted. > insert into t_employee values(1, 1, 'employee_01'); insert into t_employee values(2, 1, 'employee_02'); insert into t_employee values(3, 2, 'employee_03'); insert into t_employee values(4, 2, 'employee_04'); insert into t_employee values(5, 3, 'employee_05'); 1 row(s) inserted. 1 row(s) inserted. > 1 row(s) inserted. > 1 row(s) inserted. > 1 row(s) inserted. > select * from t_dept; 1 row(s) inserted. f_deptid f_deptname 1 dept_1 2 dept_2 3 dept_3 3 row(s) retrieved. > select * from t_employee; f_employeeid f_deptid f_employeename 1 1 employee_01 2 1 employee_02 3 2 employee_03 4 2 employee_04 5 3 employee_05 5 row(s) retrieved. >

在L0备份前,t_dept表有3条记录,t_employee表有5条记录。在将数据库物理恢复到L0时,可恢复t_dept中的3条记录和t_employee中的5条记录。

GBase207.png备份与恢复

  • 步骤3:L0备份
[gbasedbt@localhost backup]$ ontape -s -L 0 Your evaluation license will expire on 2024-02-14 00:00:00 100 percent done. File created: /home/gbasedbt/backup/localhost.localdomain_101_L0 Please label this tape as number 1 in the arc tape sequence. This tape contains the following logical logs: 9 Program over. [gbasedbt@localhost backup]$ ll 总用量 46496 -rw-rw----. 1 gbasedbt gbasedbt 47611904 2月 16 14:51 localhost.localdomain_101_L0 [gbasedbt@localhost backup]$

GBase208.png备份与恢复

执行L0备份后,目录中生成一个名称为localhost.localdomain_101_L0的备份文件。

备份文件的命名规则:

<L0 | L1 | L2>

  • 步骤4:L1备份前的数据准备
> insert into t_employee values(11, 1, 'employee_11'); insert into t_employee values(12, 1, 'employee_12'); insert into t_employee values(13, 2, 'employee_13'); insert into t_employee values(14, 2, 'employee_14'); insert into t_employee values(15, 3, 'employee_15'); 1 row(s) inserted. > 1 row(s) inserted. > 1 row(s) inserted. > 1 row(s) inserted. > select * from t_employee; 1 row(s) inserted. f_employeeid f_deptid f_employeename 1 1 employee_01 2 1 employee_02 3 2 employee_03 4 2 employee_04 5 3 employee_05 11 1 employee_11 12 1 employee_12 13 2 employee_13 14 2 employee_14 15 3 employee_15 10 row(s) retrieved. >

GBase209.png备份与恢复

  • 步骤5:L1备份
[gbasedbt@localhost backup]$ ontape -s -L 1 Your evaluation license will expire on 2024-02-14 00:00:00 100 percent done. File created: /home/gbasedbt/backup/localhost.localdomain_101_L1 Please label this tape as number 1 in the arc tape sequence. This tape contains the following logical logs: 9 Program over. [gbasedbt@localhost backup]$ ll 总用量 52064 -rw-rw----. 1 gbasedbt gbasedbt 47611904 2月 16 14:51 localhost.localdomain_101_L0 -rw-rw----. 1 gbasedbt gbasedbt 5701632 2月 16 14:55 localhost.localdomain_101_L1 [gbasedbt@localhost backup]$

GBase210.png备份与恢复

  • 步骤6:L1备份前的数据准备(第二次)
> insert into t_employee values(16, 3, 'employee_16'); 1 row(s) inserted. > select * from t_employee; f_employeeid f_deptid f_employeename 1 1 employee_01 2 1 employee_02 3 2 employee_03 4 2 employee_04 5 3 employee_05 11 1 employee_11 12 1 employee_12 13 2 employee_13 14 2 employee_14 15 3 employee_15 16 3 employee_16 11 row(s) retrieved. >

GBase211.png备份与恢复

在第二次L1备份前,t_employee表有11条记录。
可通过L1的物理恢复,得到t_employee表的11条记录。

  • 步骤7:L1备份
[gbasedbt@localhost backup]$ ontape -s -L 1 Your evaluation license will expire on 2024-02-14 00:00:00 100 percent done. File created: /home/gbasedbt/backup/localhost.localdomain_101_L1 Please label this tape as number 1 in the arc tape sequence. This tape contains the following logical logs: 9 Program over. [gbasedbt@localhost backup]$ ll 总用量 57632 -rw-rw----. 1 gbasedbt gbasedbt 5701632 2月 16 14:55 localhost.localdomain_101_20230216_145540_L1 -rw-rw----. 1 gbasedbt gbasedbt 47611904 2月 16 14:51 localhost.localdomain_101_L0 -rw-rw----. 1 gbasedbt gbasedbt 5701632 2月 16 14:58 localhost.localdomain_101_L1 [gbasedbt@localhost backup]$

GBase212.png备份与恢复

GBase 8s最后一次的备份文件名为 <L0 | L1 | L2>。当连续使用同一级别进行备份时,前一次的备份会被自动更名为-<L0 | L1 | L2>。

  • 步骤8:L2备份前的数据准备
> insert into t_employee values(21, 1, 'employee_21'); insert into t_employee values(22, 1, 'employee_22'); insert into t_employee values(23, 2, 'employee_23'); insert into t_employee values(24, 2, 'employee_24'); insert into t_employee values(25, 3, 'employee_25'); 1 row(s) inserted. > 1 row(s) inserted. > 1 row(s) inserted. > 1 row(s) inserted. > select * from t_employee; 1 row(s) inserted. f_employeeid f_deptid f_employeename 1 1 employee_01 2 1 employee_02 3 2 employee_03 4 2 employee_04 5 3 employee_05 11 1 employee_11 12 1 employee_12 13 2 employee_13 14 2 employee_14 15 3 employee_15 16 3 employee_16 21 1 employee_21 22 1 employee_22 23 2 employee_23 24 2 employee_24 25 3 employee_25 16 row(s) retrieved. >

GBase213.png备份与恢复

在L2备份前,t_employee表有16条记录。
可通过L2的物理恢复,得到t_employee表的16条记录。

  • 步骤9:L2备份
[gbasedbt@localhost backup]$ ontape -s -L 2 Your evaluation license will expire on 2024-02-14 00:00:00 100 percent done. File created: /home/gbasedbt/backup/localhost.localdomain_101_L2 Please label this tape as number 1 in the arc tape sequence. This tape contains the following logical logs: 9 Program over. [gbasedbt@localhost backup]$ ll 总用量 63232 -rw-rw----. 1 gbasedbt gbasedbt 5701632 2月 16 14:55 localhost.localdomain_101_20230216_145540_L1 -rw-rw----. 1 gbasedbt gbasedbt 47611904 2月 16 14:51 localhost.localdomain_101_L0 -rw-rw----. 1 gbasedbt gbasedbt 5701632 2月 16 14:58 localhost.localdomain_101_L1 -rw-rw----. 1 gbasedbt gbasedbt 5734400 2月 16 15:01 localhost.localdomain_101_L2 [gbasedbt@localhost backup]$

GBase214.png备份与恢复

  • 步骤10:切换逻辑日志前的数据准备
> insert into t_dept values(4, 'dept_4'); 1 row(s) inserted. > select * from t_dept; f_deptid f_deptname 1 dept_1 2 dept_2 3 dept_3 4 dept_4 4 row(s) retrieved. > select * from t_employee; f_employeeid f_deptid f_employeename 1 1 employee_01 2 1 employee_02 3 2 employee_03 4 2 employee_04 5 3 employee_05 11 1 employee_11 12 1 employee_12 13 2 employee_13 14 2 employee_14 15 3 employee_15 16 3 employee_16 21 1 employee_21 22 1 employee_22 23 2 employee_23 24 2 employee_24 25 3 employee_25 16 row(s) retrieved. >

GBase215.png备份与恢复

  • 步骤11 切换逻辑日志

切换前,当前的逻辑日志文件是6,唯一编号为9。

[gbasedbt@localhost backup]$ onstat -l Your evaluation license will expire on 2024-02-14 00:00:00 On-Line -- Up 00:28:11 -- 597864 Kbytes Physical Logging Buffer bufused bufsize numpages numwrits pages/io P-2 0 1024 4372 12 364.33 phybegin physize phypos phyused %used 3:53 99400 8283 0 0.00 Logical Logging Buffer bufused bufsize numrecs numpages numwrits recs/pages pages/io L-2 0 512 53862 4023 64 13.4 62.9 Subsystem numrecs Log Space used OLDRSAM 53779 8003900 HA 13 572 DDL 70 24360 address number flags uniqid begin size used %used 47140f88 4 U-B---- 7 2:53 5000 5000 100.00 483d2970 5 U------ 8 2:5053 5000 5000 100.00 483d29d8 6 U---C-L 9 2:10053 5000 2550 51.00 483d2a40 7 A------ 0 2:15053 5000 0 0.00 483d2aa8 8 A------ 0 2:20053 5000 0 0.00 483d2b10 9 A------ 0 2:25053 5000 0 0.00 483d2b78 10 A------ 0 2:30053 5000 0 0.00 483d2be0 11 A------ 0 2:35053 5000 0 0.00 483d2c48 12 A------ 0 2:40053 5000 0 0.00 483d2cb0 13 A------ 0 2:45053 5000 0 0.00 483d2d18 14 A------ 0 2:50053 5000 0 0.00 483d2d80 15 A------ 0 2:55053 5000 0 0.00 483d2de8 16 A------ 0 2:60053 5000 0 0.00 483d2e50 17 A------ 0 2:65053 5000 0 0.00 483d2eb8 18 A------ 0 2:70053 5000 0 0.00 483d2f20 19 A------ 0 2:75053 5000 0 0.00 483d2f88 20 A------ 0 2:80053 5000 0 0.00 46f1ff30 21 A------ 0 2:85053 5000 0 0.00 46f1ff98 22 A------ 0 2:90053 5000 0 0.00 46feef30 23 A------ 0 2:95053 5000 0 0.00 20 active, 20 total [gbasedbt@localhost backup]$

GBase216.png备份与恢复

执行逻辑日志切换命令

[gbasedbt@localhost backup]$ onmode -l Your evaluation license will expire on 2024-02-14 00:00:00 [gbasedbt@localhost backup]$

GBase217.png备份与恢复

切换后,当前逻辑日志文件为7,唯一编号为10。

[gbasedbt@localhost backup]$ onstat -l Your evaluation license will expire on 2024-02-14 00:00:00 On-Line -- Up 00:30:54 -- 597864 Kbytes Physical Logging Buffer bufused bufsize numpages numwrits pages/io P-2 7 1024 4372 12 364.33 phybegin physize phypos phyused %used 3:53 99400 8283 7 0.01 Logical Logging Buffer bufused bufsize numrecs numpages numwrits recs/pages pages/io L-3 0 512 53862 4024 65 13.4 61.9 Subsystem numrecs Log Space used OLDRSAM 53779 8003900 HA 13 572 DDL 70 24360 address number flags uniqid begin size used %used 47140f88 4 U-B---- 7 2:53 5000 5000 100.00 483d2970 5 U------ 8 2:5053 5000 5000 100.00 483d29d8 6 U-----L 9 2:10053 5000 2551 51.02 483d2a40 7 U---C-- 10 2:15053 5000 0 0.00 483d2aa8 8 A------ 0 2:20053 5000 0 0.00 483d2b10 9 A------ 0 2:25053 5000 0 0.00 483d2b78 10 A------ 0 2:30053 5000 0 0.00 483d2be0 11 A------ 0 2:35053 5000 0 0.00 483d2c48 12 A------ 0 2:40053 5000 0 0.00 483d2cb0 13 A------ 0 2:45053 5000 0 0.00 483d2d18 14 A------ 0 2:50053 5000 0 0.00 483d2d80 15 A------ 0 2:55053 5000 0 0.00 483d2de8 16 A------ 0 2:60053 5000 0 0.00 483d2e50 17 A------ 0 2:65053 5000 0 0.00 483d2eb8 18 A------ 0 2:70053 5000 0 0.00 483d2f20 19 A------ 0 2:75053 5000 0 0.00 483d2f88 20 A------ 0 2:80053 5000 0 0.00 46f1ff30 21 A------ 0 2:85053 5000 0 0.00 46f1ff98 22 A------ 0 2:90053 5000 0 0.00 46feef30 23 A------ 0 2:95053 5000 0 0.00 20 active, 20 total [gbasedbt@localhost backup]$

GBase218.png备份与恢复

  • 步骤12 灾难前的最后一次数据变更

在灾难发生前,删除一个记录,用于后续恢复时的验证用例。

> delete from t_employee where f_employeeid = 14; 1 row(s) deleted. > select * from t_employee; f_employeeid f_deptid f_employeename 1 1 employee_01 2 1 employee_02 3 2 employee_03 4 2 employee_04 5 3 employee_05 11 1 employee_11 12 1 employee_12 13 2 employee_13 15 3 employee_15 16 3 employee_16 21 1 employee_21 22 1 employee_22 23 2 employee_23 24 2 employee_24 25 3 employee_25 15 row(s) retrieved. > select * from t_dept; f_deptid f_deptname 1 dept_1 2 dept_2 3 dept_3 4 dept_4 4 row(s) retrieved. >

GBase219.png备份与恢复

在灾难发生前,t_employee表有15条记录,t_dept表有4条记录。
可通过完全恢复,得到t_employee表的15条记录,t_dept表的4条记录。

  • 步骤13 模拟灾难发生
[gbasedbt@localhost backup]$ cd /opt/gbase/gbaseserver_dbs/ [gbasedbt@localhost gbaseserver_dbs]$ ll 总用量 1536000 -rw-rw----. 1 gbasedbt gbasedbt 104857600 2月 16 15:09 datadbs1_1 -rw-rw----. 1 gbasedbt gbasedbt 104857600 2月 16 14:36 datadbs2_1 -rw-rw----. 1 gbasedbt gbasedbt 104857600 2月 16 14:45 datadbs3_1 -rw-rw----. 1 gbasedbt gbasedbt 104857600 2月 16 14:36 datadbs4_1 -rw-rw----. 1 gbasedbt gbasedbt 104857600 2月 16 14:36 datadbs5_1 -rw-rw----. 1 gbasedbt gbasedbt 209715200 2月 16 15:09 llogdbs -rw-rw----. 1 gbasedbt gbasedbt 209715200 2月 16 15:09 plogdbs -rw-rw----. 1 gbasedbt gbasedbt 209715200 2月 16 15:09 rootdbs -rw-rw----. 1 gbasedbt gbasedbt 104857600 2月 16 14:36 sbspace1 -rw-rw----. 1 gbasedbt gbasedbt 104857600 2月 16 15:03 tmpdbs1 -rw-rw----. 1 gbasedbt gbasedbt 104857600 2月 16 15:03 tmpdbs2 -rw-rw----. 1 gbasedbt gbasedbt 104857600 2月 16 15:00 tmpdbs3 [gbasedbt@localhost gbaseserver_dbs]$ rm -rf datadbs1_1 [gbasedbt@localhost gbaseserver_dbs]$ ll 总用量 1433600 -rw-rw----. 1 gbasedbt gbasedbt 104857600 2月 16 14:36 datadbs2_1 -rw-rw----. 1 gbasedbt gbasedbt 104857600 2月 16 14:45 datadbs3_1 -rw-rw----. 1 gbasedbt gbasedbt 104857600 2月 16 14:36 datadbs4_1 -rw-rw----. 1 gbasedbt gbasedbt 104857600 2月 16 14:36 datadbs5_1 -rw-rw----. 1 gbasedbt gbasedbt 209715200 2月 16 15:09 llogdbs -rw-rw----. 1 gbasedbt gbasedbt 209715200 2月 16 15:09 plogdbs -rw-rw----. 1 gbasedbt gbasedbt 209715200 2月 16 15:09 rootdbs -rw-rw----. 1 gbasedbt gbasedbt 104857600 2月 16 14:36 sbspace1 -rw-rw----. 1 gbasedbt gbasedbt 104857600 2月 16 15:03 tmpdbs1 -rw-rw----. 1 gbasedbt gbasedbt 104857600 2月 16 15:03 tmpdbs2 -rw-rw----. 1 gbasedbt gbasedbt 104857600 2月 16 15:00 tmpdbs3 [gbasedbt@localhost gbaseserver_dbs]$

删除数据空间文件成功。

GBase220.png备份与恢复

  • 步骤14 灾难后的第一次数据变更

在数据库空间文件被删除后,对t_dept表的INSERT操作可以成功。

> insert into t_dept values(5, 'dept_5'); 1 row(s) inserted. > select * from t_dept; f_deptid f_deptname 1 dept_1 2 dept_2 3 dept_3 4 dept_4 5 dept_5 5 row(s) retrieved. >

灾难发生后,对t_dept表的操作成功,t_dept表共有5条记录。

GBase221.png备份与恢复

  • 步骤15 重启数据库,出现错误信息。

数据库报错,信息:Cannot open chunk ‘/opt/gbase/gbaseserver_dbs/datadbs1_1’.

因为这个文件被删除,所以GBase 8s找不到这个文件了。

[gbasedbt@localhost gbaseserver_dbs]$ onmode -ky Your evaluation license will expire on 2024-02-14 00:00:00 [gbasedbt@localhost gbaseserver_dbs]$ oninit -vy Your evaluation license will expire on 2024-02-14 00:00:00 Reading configuration file '/opt/gbase/etc/onconfig.gbaseserver'...succeeded Creating /GBASEDBTTMP/.infxdirs...succeeded Allocating and attaching to shared memory...succeeded Creating resident pool 36470 kbytes...succeeded Creating infos file "/opt/gbase/etc/.infos.gbaseserver"...succeeded Linking conf file "/opt/gbase/etc/.conf.gbaseserver"...succeeded Initializing rhead structure...rhlock_t 65536 (2048K)... rlock_t (26562K)... Writing to infos file...succeeded Initialization of Encryption...succeeded Initializing ASF...succeeded Initializing Dictionary Cache and SPL Routine Cache...succeeded Bringing up ADM VP...succeeded Creating VP classes...succeeded Forking main_loop thread...succeeded Initializing DR structures...succeeded Forking 1 'soctcp' listener threads...succeeded Starting tracing...succeeded Initializing 32 flushers...succeeded Initializing SDS Server network connections...succeeded Initializing log/checkpoint information...succeeded Initializing dbspaces...succeeded Opening primary chunks...oninit: Cannot open chunk '/opt/gbase/gbaseserver_dbs/datadbs1_1'. errno = 2 succeeded Validating chunks...succeeded Initialize Async Log Flusher...succeeded Starting B-tree Scanner...succeeded Init ReadAhead Daemon...succeeded Init DB Util Daemon...succeeded Initializing DBSPACETEMP list...succeeded Init Auto Tuning Daemon...succeeded Checking database partition index...succeeded Initializing dataskip structure...succeeded Checking for temporary tables to drop...succeeded Updating Global Row Counter...succeeded Forking onmode_mon thread...succeeded Creating periodic thread...succeeded Creating periodic thread...succeeded Starting scheduling system...succeeded Verbose output complete: mode = 5 [gbasedbt@localhost gbaseserver_dbs]$

GBase222.png备份与恢复

  • 步骤16 备份逻辑日志。

执行逻辑日志的备份后,目录中出现备份的逻辑日志(localdomain_101_Log0000000008、localdomain_101_Log0000000009、localdomain_101_Log0000000010)。

[gbasedbt@localhost backup]$ ontape -a Your evaluation license will expire on 2024-02-14 00:00:00 Performing automatic backup of logical logs. File created: /home/gbasedbt/backup/localhost.localdomain_101_Log0000000008 File created: /home/gbasedbt/backup/localhost.localdomain_101_Log0000000009 Do you want to back up the current logical log? (y/n) y File created: /home/gbasedbt/backup/localhost.localdomain_101_Log0000000010 Program over. [gbasedbt@localhost backup]$ ll 总用量 78592 -rw-rw----. 1 gbasedbt gbasedbt 5701632 2月 16 14:55 localhost.localdomain_101_20230216_145540_L1 -rw-rw----. 1 gbasedbt gbasedbt 47611904 2月 16 14:51 localhost.localdomain_101_L0 -rw-rw----. 1 gbasedbt gbasedbt 5701632 2月 16 14:58 localhost.localdomain_101_L1 -rw-rw----. 1 gbasedbt gbasedbt 5734400 2月 16 15:01 localhost.localdomain_101_L2 -rw-rw----. 1 gbasedbt gbasedbt 10321920 2月 16 15:17 localhost.localdomain_101_Log0000000008 -rw-rw----. 1 gbasedbt gbasedbt 5308416 2月 16 15:17 localhost.localdomain_101_Log0000000009 -rw-rw----. 1 gbasedbt gbasedbt 98304 2月 16 15:18 localhost.localdomain_101_Log0000000010 [gbasedbt@localhost backup]$

GBase223.png备份与恢复

进行逻辑日志备份时,会产生逻辑日志切换。当前的逻辑日志文件变为8,唯一编号为11。

[gbasedbt@localhost backup]$ onstat -l Your evaluation license will expire on 2024-02-14 00:00:00 On-Line (CKPT INP) -- Up 00:05:53 -- 597864 Kbytes Blocked:OVERRIDE_DOWN_SPACE Physical Logging Buffer bufused bufsize numpages numwrits pages/io P-1 0 1024 43 1 43.00 phybegin physize phypos phyused %used 3:53 99400 8377 43 0.04 Logical Logging Buffer bufused bufsize numrecs numpages numwrits recs/pages pages/io L-3 0 512 7 2 2 3.5 1.0 Subsystem numrecs Log Space used OLDRSAM 7 404 address number flags uniqid begin size used %used 47140f88 4 U-B---- 7 2:53 5000 5000 100.00 483d2970 5 U-B---- 8 2:5053 5000 5000 100.00 483d29d8 6 U-B---- 9 2:10053 5000 2551 51.02 483d2a40 7 U-B---L 10 2:15053 5000 12 0.24 483d2aa8 8 U---C-- 11 2:20053 5000 0 0.00 483d2b10 9 A------ 0 2:25053 5000 0 0.00 483d2b78 10 A------ 0 2:30053 5000 0 0.00 483d2be0 11 A------ 0 2:35053 5000 0 0.00 483d2c48 12 A------ 0 2:40053 5000 0 0.00 483d2cb0 13 A------ 0 2:45053 5000 0 0.00 483d2d18 14 A------ 0 2:50053 5000 0 0.00 483d2d80 15 A------ 0 2:55053 5000 0 0.00 483d2de8 16 A------ 0 2:60053 5000 0 0.00 483d2e50 17 A------ 0 2:65053 5000 0 0.00 483d2eb8 18 A------ 0 2:70053 5000 0 0.00 483d2f20 19 A------ 0 2:75053 5000 0 0.00 483d2f88 20 A------ 0 2:80053 5000 0 0.00 46f1ff30 21 A------ 0 2:85053 5000 0 0.00 46f1ff98 22 A------ 0 2:90053 5000 0 0.00 46feef30 23 A------ 0 2:95053 5000 0 0.00 20 active, 20 total [gbasedbt@localhost backup]$

GBase224.png备份与恢复

  • 步骤17 恢复数据库。

为丢失的数据库空间文件,创建一个同名的空文件,并设置好相应的权限。

[gbasedbt@localhost gbaseserver_dbs]$ pwd /opt/gbase/gbaseserver_dbs [gbasedbt@localhost gbaseserver_dbs]$ ll 总用量 1433600 -rw-rw----. 1 gbasedbt gbasedbt 104857600 2月 16 15:15 datadbs2_1 -rw-rw----. 1 gbasedbt gbasedbt 104857600 2月 16 15:15 datadbs3_1 -rw-rw----. 1 gbasedbt gbasedbt 104857600 2月 16 15:15 datadbs4_1 -rw-rw----. 1 gbasedbt gbasedbt 104857600 2月 16 15:15 datadbs5_1 -rw-rw----. 1 gbasedbt gbasedbt 209715200 2月 16 15:18 llogdbs -rw-rw----. 1 gbasedbt gbasedbt 209715200 2月 16 15:15 plogdbs -rw-rw----. 1 gbasedbt gbasedbt 209715200 2月 16 15:15 rootdbs -rw-rw----. 1 gbasedbt gbasedbt 104857600 2月 16 15:15 sbspace1 -rw-rw----. 1 gbasedbt gbasedbt 104857600 2月 16 15:15 tmpdbs1 -rw-rw----. 1 gbasedbt gbasedbt 104857600 2月 16 15:15 tmpdbs2 -rw-rw----. 1 gbasedbt gbasedbt 104857600 2月 16 15:15 tmpdbs3 [gbasedbt@localhost gbaseserver_dbs]$ touch datadbs1_1 [gbasedbt@localhost gbaseserver_dbs]$ ll 总用量 1433600 -rw-rw-r--. 1 gbasedbt gbasedbt 0 2月 16 15:24 datadbs1_1 -rw-rw----. 1 gbasedbt gbasedbt 104857600 2月 16 15:15 datadbs2_1 -rw-rw----. 1 gbasedbt gbasedbt 104857600 2月 16 15:15 datadbs3_1 -rw-rw----. 1 gbasedbt gbasedbt 104857600 2月 16 15:15 datadbs4_1 -rw-rw----. 1 gbasedbt gbasedbt 104857600 2月 16 15:15 datadbs5_1 -rw-rw----. 1 gbasedbt gbasedbt 209715200 2月 16 15:18 llogdbs -rw-rw----. 1 gbasedbt gbasedbt 209715200 2月 16 15:15 plogdbs -rw-rw----. 1 gbasedbt gbasedbt 209715200 2月 16 15:15 rootdbs -rw-rw----. 1 gbasedbt gbasedbt 104857600 2月 16 15:15 sbspace1 -rw-rw----. 1 gbasedbt gbasedbt 104857600 2月 16 15:15 tmpdbs1 -rw-rw----. 1 gbasedbt gbasedbt 104857600 2月 16 15:15 tmpdbs2 -rw-rw----. 1 gbasedbt gbasedbt 104857600 2月 16 15:15 tmpdbs3 [gbasedbt@localhost gbaseserver_dbs]$ chmod o-r datadbs1_1 [gbasedbt@localhost gbaseserver_dbs]$ ll 总用量 1433600 -rw-rw----. 1 gbasedbt gbasedbt 0 2月 16 15:24 datadbs1_1 -rw-rw----. 1 gbasedbt gbasedbt 104857600 2月 16 15:15 datadbs2_1 -rw-rw----. 1 gbasedbt gbasedbt 104857600 2月 16 15:15 datadbs3_1 -rw-rw----. 1 gbasedbt gbasedbt 104857600 2月 16 15:15 datadbs4_1 -rw-rw----. 1 gbasedbt gbasedbt 104857600 2月 16 15:15 datadbs5_1 -rw-rw----. 1 gbasedbt gbasedbt 209715200 2月 16 15:18 llogdbs -rw-rw----. 1 gbasedbt gbasedbt 209715200 2月 16 15:15 plogdbs -rw-rw----. 1 gbasedbt gbasedbt 209715200 2月 16 15:15 rootdbs -rw-rw----. 1 gbasedbt gbasedbt 104857600 2月 16 15:15 sbspace1 -rw-rw----. 1 gbasedbt gbasedbt 104857600 2月 16 15:15 tmpdbs1 -rw-rw----. 1 gbasedbt gbasedbt 104857600 2月 16 15:15 tmpdbs2 -rw-rw----. 1 gbasedbt gbasedbt 104857600 2月 16 15:15 tmpdbs3 [gbasedbt@localhost gbaseserver_dbs]$

GBase225.png备份与恢复

关闭GBase 8s数据库实例,并进行完全恢复。

[gbasedbt@localhost gbaseserver_dbs]$ onmode -ky Your evaluation license will expire on 2024-02-14 00:00:00 [gbasedbt@localhost gbaseserver_dbs]$ ontape -r Your evaluation license will expire on 2024-02-14 00:00:00 Restore will use level 0 archive file /home/gbasedbt/backup/localhost.localdomain_101_L0. Press Return to continue ... Archive Tape Information Tape type: Archive Backup Tape Online version: GBase Database Server Version 12.10.FC4G1TL Archive date: Thu Feb 16 14:51:12 2023 User id: gbasedbt Terminal id: /dev/pts/2 Archive level: 0 Tape device: /home/gbasedbt/backup/ Tape blocksize (in k): 32 Tape size (in k): system defined for directory Tape number in series: 1 Spaces to restore:1 [rootdbs ] 2 [llogdbs ] 3 [plogdbs ] 4 [datadbs1 ] 5 [datadbs2 ] 6 [datadbs3 ] 7 [datadbs4 ] 8 [datadbs5 ] 9 [sbspace1 ] Archive Information GBase Database Server Copyright 2001, 2021 General Data Corporation Initialization Time 02/14/2023 13:48:46 System Page Size 2048 Version 32 Index Page Logging OFF Archive CheckPoint Time 02/16/2023 14:51:11 Dbspaces number flags fchunk nchunks flags owner name 1 70001 1 1 N BA gbasedbt rootdbs 2 60001 2 1 N BA gbasedbt llogdbs 3 70001 3 1 N BA gbasedbt plogdbs 4 68001 4 1 N SBA gbasedbt sbspace1 5 42001 5 1 N TBA gbasedbt tmpdbs1 6 42001 6 1 N TBA gbasedbt tmpdbs2 7 42001 7 1 N TBA gbasedbt tmpdbs3 8 60001 8 1 N BA gbasedbt datadbs1 9 60001 9 1 N BA gbasedbt datadbs2 10 60001 10 1 N BA gbasedbt datadbs3 11 60001 11 1 N BA gbasedbt datadbs4 12 60001 12 1 N BA gbasedbt datadbs5 Chunks chk/dbs offset size free bpages flags pathname 1 1 0 102400 91514 PO-B- /opt/gbase/gbaseserver_dbs/rootdbs 2 2 0 102400 2347 PO-B- /opt/gbase/gbaseserver_dbs/llogdbs 3 3 0 102400 2947 PO-B- /opt/gbase/gbaseserver_dbs/plogdbs 4 4 0 51200 2581 POSB- /opt/gbase/gbaseserver_dbs/sbspace1 5 5 0 51200 50712 PO-B- /opt/gbase/gbaseserver_dbs/tmpdbs1 6 6 0 51200 50776 PO-B- /opt/gbase/gbaseserver_dbs/tmpdbs2 7 7 0 51200 50776 PO-B- /opt/gbase/gbaseserver_dbs/tmpdbs3 8 8 0 51200 36008 PO-BE /opt/gbase/gbaseserver_dbs/datadbs1_1 9 9 0 51200 50376 PO-BE /opt/gbase/gbaseserver_dbs/datadbs2_1 10 10 0 51200 50376 PO-BE /opt/gbase/gbaseserver_dbs/datadbs3_1 11 11 0 51200 50776 PO-BE /opt/gbase/gbaseserver_dbs/datadbs4_1 12 12 0 51200 50776 PO-BE /opt/gbase/gbaseserver_dbs/datadbs5_1 Continue restore? (y/n)y --##### 输入y #####-- Do you want to back up the logs? (y/n)y --##### 输入y #####-- File created: /home/gbasedbt/backup/localhost.localdomain_101_Log0000000007 File created: /home/gbasedbt/backup/localhost.localdomain_101_Log0000000008 File created: /home/gbasedbt/backup/localhost.localdomain_101_Log0000000009 File created: /home/gbasedbt/backup/localhost.localdomain_101_Log0000000010 Log salvage is complete, continuing restore of archive. Your evaluation license will expire on 2024-02-14 00:00:00 Restore a level 1 archive (y/n) y --##### 输入y #####-- Ready for level 1 tape Restore will use level 1 archive file /home/gbasedbt/backup/localhost.localdomain_101_L1. Press Return to continue ... Archive Tape Information Tape type: Archive Backup Tape Online version: GBase Database Server Version 12.10.FC4G1TL Archive date: Thu Feb 16 14:58:34 2023 User id: gbasedbt Terminal id: /dev/pts/2 Archive level: 1 Tape device: /home/gbasedbt/backup/ Tape blocksize (in k): 32 Tape size (in k): system defined for directory Tape number in series: 1 Restore a level 2 archive (y/n) y --##### 输入y #####-- Ready for level 2 tape Restore will use level 2 archive file /home/gbasedbt/backup/localhost.localdomain_101_L2. Press Return to continue ... Archive Tape Information Tape type: Archive Backup Tape Online version: GBase Database Server Version 12.10.FC4G1TL Archive date: Thu Feb 16 15:01:22 2023 User id: gbasedbt Terminal id: /dev/pts/2 Archive level: 2 Tape device: /home/gbasedbt/backup/ Tape blocksize (in k): 32 Tape size (in k): system defined for directory Tape number in series: 1 Do you want to restore log tapes? (y/n)y --##### 输入y #####-- Roll forward should start with log number 9 Restore will use log backup file /home/gbasedbt/backup/localhost.localdomain_101_Log0000000009. Press Return to continue ... Rollforward log file /home/gbasedbt/backup/localhost.localdomain_101_Log0000000009 ... Rollforward log file /home/gbasedbt/backup/localhost.localdomain_101_Log0000000010 ... Program over. [gbasedbt@localhost gbaseserver_dbs]$

GBase226.png备份与恢复
GBase227.png备份与恢复
GBase228.png备份与恢复

  • 步骤18 查看表数据。

完全恢复后,在数据空间文件删除前的数据验证通过。即使在数据空间文件被删除后的操作成功的事务数据,也可以被完全恢复。

[gbasedbt@localhost gbaseserver_dbs]$ onstat - Your evaluation license will expire on 2024-02-14 00:00:00 Quiescent -- Up 00:07:54 -- 1135464 Kbytes [gbasedbt@localhost gbaseserver_dbs]$ onmode -m Your evaluation license will expire on 2024-02-14 00:00:00 [gbasedbt@localhost gbaseserver_dbs]$ dbaccess - - Your evaluation license will expire on 2024-02-14 00:00:00 > database mydb; Database selected. > select * from t_dept; f_deptid f_deptname 1 dept_1 2 dept_2 3 dept_3 4 dept_4 5 dept_5 5 row(s) retrieved. > select * from t_employee; f_employeeid f_deptid f_employeename 1 1 employee_01 2 1 employee_02 3 2 employee_03 4 2 employee_04 5 3 employee_05 11 1 employee_11 12 1 employee_12 13 2 employee_13 15 3 employee_15 16 3 employee_16 21 1 employee_21 22 1 employee_22 23 2 employee_23 24 2 employee_24 25 3 employee_25 15 row(s) retrieved. >

检查结果:数据表完全恢复到数据库空间被删除前的状态,且在数据库空间文件被删除后新增的记录,也被正确恢复。

GBase229.png备份与恢复

  • 步骤19 删除表之前的数据准备
> insert into t_employee values(101, 1, 'employee_101'); insert into t_employee values(102, 1, 'employee_102'); insert into t_employee values(103, 2, 'employee_103'); insert into t_employee values(104, 2, 'employee_104'); insert into t_employee values(105, 3, 'employee_105'); 1 row(s) inserted. > 1 row(s) inserted. > 1 row(s) inserted. > 1 row(s) inserted. > select * from t_employee order by f_employeeid; 1 row(s) inserted. f_employeeid f_deptid f_employeename 1 1 employee_01 2 1 employee_02 3 2 employee_03 4 2 employee_04 5 3 employee_05 11 1 employee_11 12 1 employee_12 13 2 employee_13 15 3 employee_15 16 3 employee_16 21 1 employee_21 22 1 employee_22 23 2 employee_23 24 2 employee_24 25 3 employee_25 101 1 employee_101 102 1 employee_102 103 2 employee_103 104 2 employee_104 105 3 employee_105 20 row(s) retrieved. >

GBase230.png备份与恢复

此处构造的5条测试数据,由于没有基于时间点的恢复,可能在数据表被删除时,无法正确恢复。

  • 步骤20 删除t_employee数据表
> drop table t_employee; Table dropped. > select * from t_employee; 206: The specified table (t_employee) is not in the database. 111: ISAM error: no record found. Error in line 1 Near character position 24 >

GBase231.png备份与恢复

  • 步骤21 L0级物理恢复
[gbasedbt@localhost ~]$ onmode -ky Your evaluation license will expire on 2024-02-14 00:00:00 [gbasedbt@localhost ~]$ ontape -p Your evaluation license will expire on 2024-02-14 00:00:00 Restore will use level 0 archive file /home/gbasedbt/backup/localhost.localdomain_101_L0. Press Return to continue ... Archive Tape Information Tape type: Archive Backup Tape Online version: GBase Database Server Version 12.10.FC4G1TL Archive date: Thu Feb 16 14:51:12 2023 User id: gbasedbt Terminal id: /dev/pts/2 Archive level: 0 Tape device: /home/gbasedbt/backup/ Tape blocksize (in k): 32 Tape size (in k): system defined for directory Tape number in series: 1 Spaces to restore:1 [rootdbs ] 2 [llogdbs ] 3 [plogdbs ] 4 [datadbs1 ] 5 [datadbs2 ] 6 [datadbs3 ] 7 [datadbs4 ] 8 [datadbs5 ] 9 [sbspace1 ] Archive Information GBase Database Server Copyright 2001, 2021 General Data Corporation Initialization Time 02/14/2023 13:48:46 System Page Size 2048 Version 32 Index Page Logging OFF Archive CheckPoint Time 02/16/2023 14:51:11 Dbspaces number flags fchunk nchunks flags owner name 1 70001 1 1 N BA gbasedbt rootdbs 2 60001 2 1 N BA gbasedbt llogdbs 3 70001 3 1 N BA gbasedbt plogdbs 4 68001 4 1 N SBA gbasedbt sbspace1 5 42001 5 1 N TBA gbasedbt tmpdbs1 6 42001 6 1 N TBA gbasedbt tmpdbs2 7 42001 7 1 N TBA gbasedbt tmpdbs3 8 60001 8 1 N BA gbasedbt datadbs1 9 60001 9 1 N BA gbasedbt datadbs2 10 60001 10 1 N BA gbasedbt datadbs3 11 60001 11 1 N BA gbasedbt datadbs4 12 60001 12 1 N BA gbasedbt datadbs5 Chunks chk/dbs offset size free bpages flags pathname 1 1 0 102400 91514 PO-B- /opt/gbase/gbaseserver_dbs/rootdbs 2 2 0 102400 2347 PO-B- /opt/gbase/gbaseserver_dbs/llogdbs 3 3 0 102400 2947 PO-B- /opt/gbase/gbaseserver_dbs/plogdbs 4 4 0 51200 2581 POSB- /opt/gbase/gbaseserver_dbs/sbspace1 5 5 0 51200 50712 PO-B- /opt/gbase/gbaseserver_dbs/tmpdbs1 6 6 0 51200 50776 PO-B- /opt/gbase/gbaseserver_dbs/tmpdbs2 7 7 0 51200 50776 PO-B- /opt/gbase/gbaseserver_dbs/tmpdbs3 8 8 0 51200 36008 PO-BE /opt/gbase/gbaseserver_dbs/datadbs1_1 9 9 0 51200 50376 PO-BE /opt/gbase/gbaseserver_dbs/datadbs2_1 10 10 0 51200 50376 PO-BE /opt/gbase/gbaseserver_dbs/datadbs3_1 11 11 0 51200 50776 PO-BE /opt/gbase/gbaseserver_dbs/datadbs4_1 12 12 0 51200 50776 PO-BE /opt/gbase/gbaseserver_dbs/datadbs5_1 Continue restore? (y/n)y --##### 输入y #####-- Do you want to back up the logs? (y/n)y --##### 输入y #####-- File created: /home/gbasedbt/backup/localhost.localdomain_101_Log0000000011 Log salvage is complete, continuing restore of archive. Your evaluation license will expire on 2024-02-14 00:00:00 Restore a level 1 archive (y/n) n --##### 输入n,不进行L1恢复 #####-- Program over. [gbasedbt@localhost ~]$

GBase232.png备份与恢复
GBase233.png备份与恢复

查看L0级物理恢复后,被删除表的恢复情况

[gbasedbt@localhost ~]$ onstat - Your evaluation license will expire on 2024-02-14 00:00:00 Fast Recovery -- Up 00:01:55 -- 597864 Kbytes [gbasedbt@localhost ~]$ onmode -m Your evaluation license will expire on 2024-02-14 00:00:00 [gbasedbt@localhost ~]$ onstat - Your evaluation license will expire on 2024-02-14 00:00:00 On-Line -- Up 00:05:24 -- 597864 Kbytes [gbasedbt@localhost ~]$ echo "select * from t_employee" | dbaccess mydb Your evaluation license will expire on 2024-02-14 00:00:00 Database selected. f_employeeid f_deptid f_employeename 1 1 employee_01 2 1 employee_02 3 2 employee_03 4 2 employee_04 5 3 employee_05 5 row(s) retrieved. Database closed. [gbasedbt@localhost ~]$

GBase234.png备份与恢复

  • 步骤22 L1级物理恢复
[gbasedbt@localhost ~]$ onmode -ky Your evaluation license will expire on 2024-02-14 00:00:00 [gbasedbt@localhost ~]$ ontape -p Your evaluation license will expire on 2024-02-14 00:00:00 Restore will use level 0 archive file /home/gbasedbt/backup/localhost.localdomain_101_L0. Press Return to continue ... Archive Tape Information Tape type: Archive Backup Tape Online version: GBase Database Server Version 12.10.FC4G1TL Archive date: Thu Feb 16 14:51:12 2023 User id: gbasedbt Terminal id: /dev/pts/2 Archive level: 0 Tape device: /home/gbasedbt/backup/ Tape blocksize (in k): 32 Tape size (in k): system defined for directory Tape number in series: 1 Spaces to restore:1 [rootdbs ] 2 [llogdbs ] 3 [plogdbs ] 4 [datadbs1 ] 5 [datadbs2 ] 6 [datadbs3 ] 7 [datadbs4 ] 8 [datadbs5 ] 9 [sbspace1 ] Archive Information GBase Database Server Copyright 2001, 2021 General Data Corporation Initialization Time 02/14/2023 13:48:46 System Page Size 2048 Version 32 Index Page Logging OFF Archive CheckPoint Time 02/16/2023 14:51:11 Dbspaces number flags fchunk nchunks flags owner name 1 70001 1 1 N BA gbasedbt rootdbs 2 60001 2 1 N BA gbasedbt llogdbs 3 70001 3 1 N BA gbasedbt plogdbs 4 68001 4 1 N SBA gbasedbt sbspace1 5 42001 5 1 N TBA gbasedbt tmpdbs1 6 42001 6 1 N TBA gbasedbt tmpdbs2 7 42001 7 1 N TBA gbasedbt tmpdbs3 8 60001 8 1 N BA gbasedbt datadbs1 9 60001 9 1 N BA gbasedbt datadbs2 10 60001 10 1 N BA gbasedbt datadbs3 11 60001 11 1 N BA gbasedbt datadbs4 12 60001 12 1 N BA gbasedbt datadbs5 Chunks chk/dbs offset size free bpages flags pathname 1 1 0 102400 91514 PO-B- /opt/gbase/gbaseserver_dbs/rootdbs 2 2 0 102400 2347 PO-B- /opt/gbase/gbaseserver_dbs/llogdbs 3 3 0 102400 2947 PO-B- /opt/gbase/gbaseserver_dbs/plogdbs 4 4 0 51200 2581 POSB- /opt/gbase/gbaseserver_dbs/sbspace1 5 5 0 51200 50712 PO-B- /opt/gbase/gbaseserver_dbs/tmpdbs1 6 6 0 51200 50776 PO-B- /opt/gbase/gbaseserver_dbs/tmpdbs2 7 7 0 51200 50776 PO-B- /opt/gbase/gbaseserver_dbs/tmpdbs3 8 8 0 51200 36008 PO-BE /opt/gbase/gbaseserver_dbs/datadbs1_1 9 9 0 51200 50376 PO-BE /opt/gbase/gbaseserver_dbs/datadbs2_1 10 10 0 51200 50376 PO-BE /opt/gbase/gbaseserver_dbs/datadbs3_1 11 11 0 51200 50776 PO-BE /opt/gbase/gbaseserver_dbs/datadbs4_1 12 12 0 51200 50776 PO-BE /opt/gbase/gbaseserver_dbs/datadbs5_1 Continue restore? (y/n)y --##### 输入y #####-- Do you want to back up the logs? (y/n)y --##### 输入y #####-- No log files to salvage. Logs 9 - 9 already exists in directory /home/gbasedbt/backup/ Log salvage is complete, continuing restore of archive. Your evaluation license will expire on 2024-02-14 00:00:00 Restore a level 1 archive (y/n) y --##### 输入y #####-- Ready for level 1 tape Restore will use level 1 archive file /home/gbasedbt/backup/localhost.localdomain_101_L1. Press Return to continue ... Archive Tape Information Tape type: Archive Backup Tape Online version: GBase Database Server Version 12.10.FC4G1TL Archive date: Thu Feb 16 14:58:34 2023 User id: gbasedbt Terminal id: /dev/pts/2 Archive level: 1 Tape device: /home/gbasedbt/backup/ Tape blocksize (in k): 32 Tape size (in k): system defined for directory Tape number in series: 1 Restore a level 2 archive (y/n) n --##### 输入n,不进行L2的恢复 #####-- Program over. [gbasedbt@localhost ~]$

GBase235.png备份与恢复

GBase236.png备份与恢复

查看L1级物理恢复后,被删除表的恢复情况

[gbasedbt@localhost ~]$ onstat - Your evaluation license will expire on 2024-02-14 00:00:00 Fast Recovery -- Up 00:03:36 -- 597864 Kbytes [gbasedbt@localhost ~]$ onmode -m Your evaluation license will expire on 2024-02-14 00:00:00 [gbasedbt@localhost ~]$ echo "select * from t_employee" | dbaccess mydb Your evaluation license will expire on 2024-02-14 00:00:00 Database selected. f_employeeid f_deptid f_employeename 1 1 employee_01 2 1 employee_02 3 2 employee_03 4 2 employee_04 5 3 employee_05 11 1 employee_11 12 1 employee_12 13 2 employee_13 14 2 employee_14 15 3 employee_15 16 3 employee_16 11 row(s) retrieved. Database closed. [gbasedbt@localhost ~]$

GBase237.png
备份与恢复

  • 步骤23 L2级物理恢复
[gbasedbt@localhost ~]$ onmode -ky Your evaluation license will expire on 2024-02-14 00:00:00 [gbasedbt@localhost ~]$ ontape -p Your evaluation license will expire on 2024-02-14 00:00:00 Restore will use level 0 archive file /home/gbasedbt/backup/localhost.localdomain_101_L0. Press Return to continue ... Archive Tape Information Tape type: Archive Backup Tape Online version: GBase Database Server Version 12.10.FC4G1TL Archive date: Thu Feb 16 14:51:12 2023 User id: gbasedbt Terminal id: /dev/pts/2 Archive level: 0 Tape device: /home/gbasedbt/backup/ Tape blocksize (in k): 32 Tape size (in k): system defined for directory Tape number in series: 1 Spaces to restore:1 [rootdbs ] 2 [llogdbs ] 3 [plogdbs ] 4 [datadbs1 ] 5 [datadbs2 ] 6 [datadbs3 ] 7 [datadbs4 ] 8 [datadbs5 ] 9 [sbspace1 ] Archive Information GBase Database Server Copyright 2001, 2021 General Data Corporation Initialization Time 02/14/2023 13:48:46 System Page Size 2048 Version 32 Index Page Logging OFF Archive CheckPoint Time 02/16/2023 14:51:11 Dbspaces number flags fchunk nchunks flags owner name 1 70001 1 1 N BA gbasedbt rootdbs 2 60001 2 1 N BA gbasedbt llogdbs 3 70001 3 1 N BA gbasedbt plogdbs 4 68001 4 1 N SBA gbasedbt sbspace1 5 42001 5 1 N TBA gbasedbt tmpdbs1 6 42001 6 1 N TBA gbasedbt tmpdbs2 7 42001 7 1 N TBA gbasedbt tmpdbs3 8 60001 8 1 N BA gbasedbt datadbs1 9 60001 9 1 N BA gbasedbt datadbs2 10 60001 10 1 N BA gbasedbt datadbs3 11 60001 11 1 N BA gbasedbt datadbs4 12 60001 12 1 N BA gbasedbt datadbs5 Chunks chk/dbs offset size free bpages flags pathname 1 1 0 102400 91514 PO-B- /opt/gbase/gbaseserver_dbs/rootdbs 2 2 0 102400 2347 PO-B- /opt/gbase/gbaseserver_dbs/llogdbs 3 3 0 102400 2947 PO-B- /opt/gbase/gbaseserver_dbs/plogdbs 4 4 0 51200 2581 POSB- /opt/gbase/gbaseserver_dbs/sbspace1 5 5 0 51200 50712 PO-B- /opt/gbase/gbaseserver_dbs/tmpdbs1 6 6 0 51200 50776 PO-B- /opt/gbase/gbaseserver_dbs/tmpdbs2 7 7 0 51200 50776 PO-B- /opt/gbase/gbaseserver_dbs/tmpdbs3 8 8 0 51200 36008 PO-BE /opt/gbase/gbaseserver_dbs/datadbs1_1 9 9 0 51200 50376 PO-BE /opt/gbase/gbaseserver_dbs/datadbs2_1 10 10 0 51200 50376 PO-BE /opt/gbase/gbaseserver_dbs/datadbs3_1 11 11 0 51200 50776 PO-BE /opt/gbase/gbaseserver_dbs/datadbs4_1 12 12 0 51200 50776 PO-BE /opt/gbase/gbaseserver_dbs/datadbs5_1 Continue restore? (y/n)y Do you want to back up the logs? (y/n)y No log files to salvage. Logs 9 - 9 already exists in directory /home/gbasedbt/backup/ Log salvage is complete, continuing restore of archive. Your evaluation license will expire on 2024-02-14 00:00:00 Restore a level 1 archive (y/n) y Ready for level 1 tape Restore will use level 1 archive file /home/gbasedbt/backup/localhost.localdomain_101_L1. Press Return to continue ... Archive Tape Information Tape type: Archive Backup Tape Online version: GBase Database Server Version 12.10.FC4G1TL Archive date: Thu Feb 16 14:58:34 2023 User id: gbasedbt Terminal id: /dev/pts/2 Archive level: 1 Tape device: /home/gbasedbt/backup/ Tape blocksize (in k): 32 Tape size (in k): system defined for directory Tape number in series: 1 Restore a level 2 archive (y/n) y Ready for level 2 tape Restore will use level 2 archive file /home/gbasedbt/backup/localhost.localdomain_101_L2. Press Return to continue ... Archive Tape Information Tape type: Archive Backup Tape Online version: GBase Database Server Version 12.10.FC4G1TL Archive date: Thu Feb 16 15:01:22 2023 User id: gbasedbt Terminal id: /dev/pts/2 Archive level: 2 Tape device: /home/gbasedbt/backup/ Tape blocksize (in k): 32 Tape size (in k): system defined for directory Tape number in series: 1 Program over. [gbasedbt@localhost ~]$

GBase238.png备份与恢复
GBase239.png备份与恢复
GBase240.png备份与恢复

查看L2级物理恢复后,被删除表的恢复情况

[gbasedbt@localhost ~]$ onstat - Your evaluation license will expire on 2024-02-14 00:00:00 Fast Recovery -- Up 00:02:55 -- 597864 Kbytes [gbasedbt@localhost ~]$ onmode -m Your evaluation license will expire on 2024-02-14 00:00:00 [gbasedbt@localhost ~]$ echo "select * from t_employee" | dbaccess mydb Your evaluation license will expire on 2024-02-14 00:00:00 Database selected. f_employeeid f_deptid f_employeename 1 1 employee_01 2 1 employee_02 3 2 employee_03 4 2 employee_04 5 3 employee_05 11 1 employee_11 12 1 employee_12 13 2 employee_13 14 2 employee_14 15 3 employee_15 16 3 employee_16 21 1 employee_21 22 1 employee_22 23 2 employee_23 24 2 employee_24 25 3 employee_25 16 row(s) retrieved. Database closed. [gbasedbt@localhost ~]$

GBase241.png备份与恢复

  • 步骤21 L2级物理恢复+部分逻辑恢复

查看备份设备中的逻辑日志情况,根据实际情况,尝试移除最近的几个逻辑日志。本次演示,移除了最后2个逻辑日志。

[gbasedbt@localhost ~]$ cd backup/ [gbasedbt@localhost backup]$ ll 总用量 104160 -rw-rw----. 1 gbasedbt gbasedbt 5701632 2月 16 14:55 localhost.localdomain_101_20230216_145540_L1 -rw-rw----. 1 gbasedbt gbasedbt 10321920 2月 16 15:17 localhost.localdomain_101_20230216_151753_Log0000000008 -rw-rw----. 1 gbasedbt gbasedbt 5308416 2月 16 15:17 localhost.localdomain_101_20230216_151753_Log0000000009 -rw-rw----. 1 gbasedbt gbasedbt 98304 2月 16 15:18 localhost.localdomain_101_20230216_151803_Log0000000010 -rw-rw----. 1 gbasedbt gbasedbt 47611904 2月 16 14:51 localhost.localdomain_101_L0 -rw-rw----. 1 gbasedbt gbasedbt 5701632 2月 16 14:58 localhost.localdomain_101_L1 -rw-rw----. 1 gbasedbt gbasedbt 5734400 2月 16 15:01 localhost.localdomain_101_L2 -rw-rw----. 1 gbasedbt gbasedbt 10321920 2月 16 15:27 localhost.localdomain_101_Log0000000007 -rw-rw----. 1 gbasedbt gbasedbt 10321920 2月 16 15:27 localhost.localdomain_101_Log0000000008 -rw-rw----. 1 gbasedbt gbasedbt 5308416 2月 16 15:27 localhost.localdomain_101_Log0000000009 -rw-rw----. 1 gbasedbt gbasedbt 98304 2月 16 15:27 localhost.localdomain_101_Log0000000010 -rw-rw----. 1 gbasedbt gbasedbt 131072 2月 16 15:41 localhost.localdomain_101_Log0000000011 [gbasedbt@localhost backup]$ mkdir tmp [gbasedbt@localhost backup]$ mv localhost.localdomain_101_Log0000000010 localhost.localdomain_101_Log0000000011 tmp [gbasedbt@localhost backup]$ ll 总用量 103936 -rw-rw----. 1 gbasedbt gbasedbt 5701632 2月 16 14:55 localhost.localdomain_101_20230216_145540_L1 -rw-rw----. 1 gbasedbt gbasedbt 10321920 2月 16 15:17 localhost.localdomain_101_20230216_151753_Log0000000008 -rw-rw----. 1 gbasedbt gbasedbt 5308416 2月 16 15:17 localhost.localdomain_101_20230216_151753_Log0000000009 -rw-rw----. 1 gbasedbt gbasedbt 98304 2月 16 15:18 localhost.localdomain_101_20230216_151803_Log0000000010 -rw-rw----. 1 gbasedbt gbasedbt 47611904 2月 16 14:51 localhost.localdomain_101_L0 -rw-rw----. 1 gbasedbt gbasedbt 5701632 2月 16 14:58 localhost.localdomain_101_L1 -rw-rw----. 1 gbasedbt gbasedbt 5734400 2月 16 15:01 localhost.localdomain_101_L2 -rw-rw----. 1 gbasedbt gbasedbt 10321920 2月 16 15:27 localhost.localdomain_101_Log0000000007 -rw-rw----. 1 gbasedbt gbasedbt 10321920 2月 16 15:27 localhost.localdomain_101_Log0000000008 -rw-rw----. 1 gbasedbt gbasedbt 5308416 2月 16 15:27 localhost.localdomain_101_Log0000000009 drwxrwxr-x. 2 gbasedbt gbasedbt 100 216 16:15 tmp [gbasedbt@localhost backup]$

GBase242.png备份与恢复

进行完全恢复。

说明:虽然操作的是完全恢复,但因我们移除了部分最新的逻辑日志,实际上执行的结果是不完全恢复。

[gbasedbt@localhost backup]$ onmode -ky Your evaluation license will expire on 2024-02-14 00:00:00 [gbasedbt@localhost backup]$ ontape -r Your evaluation license will expire on 2024-02-14 00:00:00 Restore will use level 0 archive file /home/gbasedbt/backup/localhost.localdomain_101_L0. Press Return to continue ... Archive Tape Information Tape type: Archive Backup Tape Online version: GBase Database Server Version 12.10.FC4G1TL Archive date: Thu Feb 16 14:51:12 2023 User id: gbasedbt Terminal id: /dev/pts/2 Archive level: 0 Tape device: /home/gbasedbt/backup/ Tape blocksize (in k): 32 Tape size (in k): system defined for directory Tape number in series: 1 Spaces to restore:1 [rootdbs ] 2 [llogdbs ] 3 [plogdbs ] 4 [datadbs1 ] 5 [datadbs2 ] 6 [datadbs3 ] 7 [datadbs4 ] 8 [datadbs5 ] 9 [sbspace1 ] Archive Information GBase Database Server Copyright 2001, 2021 General Data Corporation Initialization Time 02/14/2023 13:48:46 System Page Size 2048 Version 32 Index Page Logging OFF Archive CheckPoint Time 02/16/2023 14:51:11 Dbspaces number flags fchunk nchunks flags owner name 1 70001 1 1 N BA gbasedbt rootdbs 2 60001 2 1 N BA gbasedbt llogdbs 3 70001 3 1 N BA gbasedbt plogdbs 4 68001 4 1 N SBA gbasedbt sbspace1 5 42001 5 1 N TBA gbasedbt tmpdbs1 6 42001 6 1 N TBA gbasedbt tmpdbs2 7 42001 7 1 N TBA gbasedbt tmpdbs3 8 60001 8 1 N BA gbasedbt datadbs1 9 60001 9 1 N BA gbasedbt datadbs2 10 60001 10 1 N BA gbasedbt datadbs3 11 60001 11 1 N BA gbasedbt datadbs4 12 60001 12 1 N BA gbasedbt datadbs5 Chunks chk/dbs offset size free bpages flags pathname 1 1 0 102400 91514 PO-B- /opt/gbase/gbaseserver_dbs/rootdbs 2 2 0 102400 2347 PO-B- /opt/gbase/gbaseserver_dbs/llogdbs 3 3 0 102400 2947 PO-B- /opt/gbase/gbaseserver_dbs/plogdbs 4 4 0 51200 2581 POSB- /opt/gbase/gbaseserver_dbs/sbspace1 5 5 0 51200 50712 PO-B- /opt/gbase/gbaseserver_dbs/tmpdbs1 6 6 0 51200 50776 PO-B- /opt/gbase/gbaseserver_dbs/tmpdbs2 7 7 0 51200 50776 PO-B- /opt/gbase/gbaseserver_dbs/tmpdbs3 8 8 0 51200 36008 PO-BE /opt/gbase/gbaseserver_dbs/datadbs1_1 9 9 0 51200 50376 PO-BE /opt/gbase/gbaseserver_dbs/datadbs2_1 10 10 0 51200 50376 PO-BE /opt/gbase/gbaseserver_dbs/datadbs3_1 11 11 0 51200 50776 PO-BE /opt/gbase/gbaseserver_dbs/datadbs4_1 12 12 0 51200 50776 PO-BE /opt/gbase/gbaseserver_dbs/datadbs5_1 Continue restore? (y/n)y Do you want to back up the logs? (y/n)n Your evaluation license will expire on 2024-02-14 00:00:00 Restore a level 1 archive (y/n) y Ready for level 1 tape Restore will use level 1 archive file /home/gbasedbt/backup/localhost.localdomain_101_L1. Press Return to continue ... Archive Tape Information Tape type: Archive Backup Tape Online version: GBase Database Server Version 12.10.FC4G1TL Archive date: Thu Feb 16 14:58:34 2023 User id: gbasedbt Terminal id: /dev/pts/2 Archive level: 1 Tape device: /home/gbasedbt/backup/ Tape blocksize (in k): 32 Tape size (in k): system defined for directory Tape number in series: 1 Restore a level 2 archive (y/n) y Ready for level 2 tape Restore will use level 2 archive file /home/gbasedbt/backup/localhost.localdomain_101_L2. Press Return to continue ... Archive Tape Information Tape type: Archive Backup Tape Online version: GBase Database Server Version 12.10.FC4G1TL Archive date: Thu Feb 16 15:01:22 2023 User id: gbasedbt Terminal id: /dev/pts/2 Archive level: 2 Tape device: /home/gbasedbt/backup/ Tape blocksize (in k): 32 Tape size (in k): system defined for directory Tape number in series: 1 Do you want to restore log tapes? (y/n)y Roll forward should start with log number 9 Restore will use log backup file /home/gbasedbt/backup/localhost.localdomain_101_Log0000000009. Press Return to continue ... Rollforward log file /home/gbasedbt/backup/localhost.localdomain_101_Log0000000009 ... Program over. [gbasedbt@localhost backup]$

GBase243.png备份与恢复

GBase244.png备份与恢复

GBase245.png备份与恢复

查看L2级物理恢复+部分逻辑恢复后,被删除表的恢复情况

[gbasedbt@localhost backup]$ onstat - Your evaluation license will expire on 2024-02-14 00:00:00 Quiescent -- Up 00:07:44 -- 1135464 Kbytes [gbasedbt@localhost backup]$ onmode -m Your evaluation license will expire on 2024-02-14 00:00:00 [gbasedbt@localhost backup]$ onstat - Your evaluation license will expire on 2024-02-14 00:00:00 On-Line -- Up 00:07:59 -- 1135464 Kbytes [gbasedbt@localhost backup]$ echo "select * from t_employee" | dbaccess mydb Your evaluation license will expire on 2024-02-14 00:00:00 Database selected. f_employeeid f_deptid f_employeename 1 1 employee_01 2 1 employee_02 3 2 employee_03 4 2 employee_04 5 3 employee_05 11 1 employee_updated 12 1 employee_12 13 2 employee_13 14 2 employee_14 15 3 employee_15 16 3 employee_16 21 1 employee_21 22 1 employee_22 23 2 employee_23 24 2 employee_24 25 3 employee_25 16 row(s) retrieved. Database closed. [gbasedbt@localhost backup]$

GBase246.png备份与恢复

GBase247.png备份与恢复

虽然此处恢复的数据仍然是11行,但L2备份后,被更新的记录被恢复成功。

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

文章被以下合辑收录

评论