ONTAPE 备份恢复小实验
ontape 是8s最常用的备份恢复工具,最近遇到一个这样的需求:
1.首先进行了L0 L1 L2 级备份
2.再进行了L0 L1 L2备份
问:能否恢复第一次L1 时的状态。
答:只要备份文件还在,当然可以恢复。
ontape备份,是需要再onconfig文件中修改TAPEDEV参数来确定备份路径的。本次实验,我的备份路径设置在了 $GBASEDBTDIR/backup/
实验开始:
首先我们再mydb库里创建t1表,为了更加直观,t1表只有一列 num;
[gbasedbt@peixun-0054 ~]$ dbaccess mydb -
Database selected.
>create table t1 (num int);
一、备份
1.插入第一条数据10 (10 表示第一次L0 级备份)
>insert into t1 values(10);1.1 第一次L0级备份
[gbasedbt@peixun-0054 ~]ontape -s -L 0
100 percent done.
File created: /opt/gbase/backup/peixun-0054_2_L0
Please label this tape as number 1 in the arc tape sequence.
This tape contains the following logical logs:
7
Program over.2.插入第二条数据 11 (11表示第一次L1级备份)
>insert into t1 values(11);2.1第一次L1级备份
[gbasedbt@peixun-0054 ~]$ ontape -s -L 1
100 percent done.
File created: /opt/gbase/backup/peixun-0054_2_L1
Please label this tape as number 1 in the arc tape sequence.
This tape contains the following logical logs:
7
Program over.3.插入第三条数据12
>insert into t1 values(12);3.1第一次L2级备份
[gbasedbt@peixun-0054 ~]$ ontape -s -L 2
100 percent done.
File created: /opt/gbase/backup/peixun-0054_2_L2
Please label this tape as number 1 in the arc tape sequence.
This tape contains the following logical logs:
7
Program over.4.插入第四条数据20(20表示第二次L0级备份)
>insert into t1 values(20);4.1第二次L0级备份
[gbasedbt@peixun-0054 ~]ontape -s -L 0
100 percent done.
File created: /opt/gbase/backup/peixun-0054_2_L0
Please label this tape as number 1 in the arc tape sequence.
This tape contains the following logical logs:
7
Program over.5.插入第五条数据21
>insert into t1 values(21);5.1第二次L1级备份
[gbasedbt@peixun-0054 ~]$ ontape -s -L 1
100 percent done.
File created: /opt/gbase/backup/peixun-0054_2_L1
Please label this tape as number 1 in the arc tape sequence.
This tape contains the following logical logs:
7
Program over.6.插入第六条数据22
>insert into t1 values(22);6.1第二次L2级备份
[gbasedbt@peixun-0054 ~]$ ontape -s -L 2
100 percent done.
File created: /opt/gbase/backup/peixun-0054_2_L2
Please label this tape as number 1 in the arc tape sequence.
This tape contains the following logical logs:
7
Program over.此时我们可以到 $GBASEDBTDIR/backup 目录下查看都有哪些备份文件
[gbasedbt@peixun-0054 backup]$ ll
total 460648
-rw-rw---- 1 gbasedbt gbasedbt 101777408 Nov 23 09:03 peixun-0054_2_20231123_090305_L0
-rw-rw---- 1 gbasedbt gbasedbt 67076096 Nov 23 09:21 peixun-0054_2_20231123_092059_L1
-rw-rw---- 1 gbasedbt gbasedbt 67010560 Nov 23 09:21 peixun-0054_2_20231123_092123_L2
-rw-rw---- 1 gbasedbt gbasedbt 101810176 Nov 23 09:21 peixun-0054_2_L0
-rw-rw---- 1 gbasedbt gbasedbt 67010560 Nov 23 09:22 peixun-0054_2_L1
-rw-rw---- 1 gbasedbt gbasedbt 67010560 Nov 23 09:22 peixun-0054_2_L2我们会发现第一次备份的L0 L1 L2文档的名称发生了变化,加上了日期。
二、恢复
此时,我们选择恢复
1.选择完全恢复,只恢复0级,查看此时恢复的是第一次的0级备份还是第二次的0级备份。
[gbasedbt@peixun-0054 ccc]$ ontape -r
Restore will use level 0 archive file /opt/gbase/backup/peixun-0054_2_L0. Press Return to continue ...
Archive Tape Information
Tape type: Archive Backup Tape
Online version: GBase Database Server Version 12.10.FC4G1AEE
Archive date: Thu Nov 23 09:03:05 2023
User id: gbasedbt
Terminal id: /dev/pts/0
Archive level: 0
Tape device: /opt/gbase/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 [sbspace1 ]
Archive Information
GBase Database Server Copyright 2001, 2023 General Data Corporation
Initialization Time 09/27/2023 09:28:35
System Page Size 2048
Version 32
Index Page Logging OFF
Archive CheckPoint Time 11/23/2023 09:03:05
Dbspaces
number flags fchunk nchunks flags owner name
1 40001 1 1 N BA gbasedbt rootdbs
2 40001 2 1 N BA gbasedbt llogdbs
3 40001 3 1 N BA gbasedbt plogdbs
4 48001 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 42001 8 1 N TBA gbasedbt tmpdbs4
9 40001 9 1 N BA gbasedbt datadbs1
10 40001 10 1 N BA gbasedbt datadbs2
11 40001 11 1 N BA gbasedbt datadbs3
Chunks
chk/dbs offset size free bpages flags pathname
1 1 0 102400 89508 PO-B- /opt/gbase/gbase01_dbs/rootdbs
2 2 0 2560000 59947 PO-B- /opt/gbase/gbase01_dbs/llogdbs
3 3 0 2560000 74947 PO-B- /opt/gbase/gbase01_dbs/plogdbs
4 4 0 512000 25659 POSB- /opt/gbase/gbase01_dbs/sbspace1
5 5 0 512000 511512 PO-B- /opt/gbase/gbase01_dbs/tmpdbs1
6 6 0 512000 511576 PO-B- /opt/gbase/gbase01_dbs/tmpdbs2
7 7 0 512000 511576 PO-B- /opt/gbase/gbase01_dbs/tmpdbs3
8 8 0 512000 511576 PO-B- /opt/gbase/gbase01_dbs/tmpdbs4
9 9 0 51200 40264 PO-BE /opt/gbase/gbase01_dbs/datadbs1_1
10 10 0 51200 50776 PO-BE /opt/gbase/gbase01_dbs/datadbs2_1
11 11 0 51200 50776 PO-BE /opt/gbase/gbase01_dbs/datadbs3_1
Continue restore? (y/n)y
Do you want to back up the logs? (y/n)y
Would you like to back up log 7? (y/n) y
Read/Write End Of Medium enabled: blocks = 2
Please label this tape as number 1 in the log tape sequence.
This tape contains the following logical logs:
7
Log salvage is complete, continuing restore of archive.
Restore a level 1 archive (y/n) n
Do you want to restore log tapes? (y/n)n
/opt/gbase/bin/onmode -sy
Program over.
[gbasedbt@peixun-0054 ~]$ onstat -
Quiescent -- Up 01:19:57 -- 2171620 Kbytes
[gbasedbt@peixun-0054 ~]$ onmode -m
[gbasedbt@peixun-0054 ~]$ dbaccess mydb -
Database selected.
> select * from t1;
id
10
11
12
20
4 row(s) retrieved.
>
发现恢复到了第二次的0级备份的时候。
那么想恢复到第一次1级2级该怎么办呢?
我们需要把备份文档复制到另外一个目录里,实验里再backup目录里在创建了一个ccc的文档。并且把前三个备份文档(文件名带日期的)复制到ccc目录里。并且把名称中的日期去掉。
[gbasedbt@peixun-0054 backup]$ mv peixun-0054_2_20231123_09* ccc/
[gbasedbt@peixun-0054 backup]$ cd ccc/
[gbasedbt@peixun-0054 ccc]$ ll
total 230336
-rw-rw---- 1 gbasedbt gbasedbt 101777408 Nov 23 09:03 peixun-0054_2_20231123_090305_L0
-rw-rw---- 1 gbasedbt gbasedbt 67076096 Nov 23 09:21 peixun-0054_2_20231123_092059_L1
-rw-rw---- 1 gbasedbt gbasedbt 67010560 Nov 23 09:21 peixun-0054_2_20231123_092123_L2
[gbasedbt@peixun-0054 ccc]$ mv peixun-0054_2_20231123_090305_L0 peixun-0054_2_L0
[gbasedbt@peixun-0054 ccc]$ mv peixun-0054_2_*L1 peixun-0054_2_L1
[gbasedbt@peixun-0054 ccc]$ mv peixun-0054_2_*L2 peixun-0054_2_L2
[gbasedbt@peixun-0054 ccc]$ ll
total 230336
-rw-rw---- 1 gbasedbt gbasedbt 101777408 Nov 23 09:03 peixun-0054_2_L0
-rw-rw---- 1 gbasedbt gbasedbt 67076096 Nov 23 09:21 peixun-0054_2_L1
-rw-rw---- 1 gbasedbt gbasedbt 67010560 Nov 23 09:21 peixun-0054_2_L2此时我们再进行完全恢复,不过要加上一个参数 -t /备份文件的存放路径 (下方演示为恢复到第一次1级备份)
[gbasedbt@peixun-0054 ccc]$ ontape -r -t /opt/gbase/backup/ccc/
Restore will use level 0 archive file /opt/gbase/backup/ccc/peixun-0054_2_L0. Press Return to continue ...
Archive Tape Information
Tape type: Archive Backup Tape
Online version: GBase Database Server Version 12.10.FC4G1AEE
Archive date: Thu Nov 23 09:03:05 2023
User id: gbasedbt
Terminal id: /dev/pts/0
Archive level: 0
Tape device: /opt/gbase/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 [sbspace1 ]
Archive Information
GBase Database Server Copyright 2001, 2023 General Data Corporation
Initialization Time 09/27/2023 09:28:35
System Page Size 2048
Version 32
Index Page Logging OFF
Archive CheckPoint Time 11/23/2023 09:03:05
Dbspaces
number flags fchunk nchunks flags owner name
1 40001 1 1 N BA gbasedbt rootdbs
2 40001 2 1 N BA gbasedbt llogdbs
3 40001 3 1 N BA gbasedbt plogdbs
4 48001 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 42001 8 1 N TBA gbasedbt tmpdbs4
9 40001 9 1 N BA gbasedbt datadbs1
10 40001 10 1 N BA gbasedbt datadbs2
11 40001 11 1 N BA gbasedbt datadbs3
Chunks
chk/dbs offset size free bpages flags pathname
1 1 0 102400 89508 PO-B- /opt/gbase/gbase01_dbs/rootdbs
2 2 0 2560000 59947 PO-B- /opt/gbase/gbase01_dbs/llogdbs
3 3 0 2560000 74947 PO-B- /opt/gbase/gbase01_dbs/plogdbs
4 4 0 512000 25659 POSB- /opt/gbase/gbase01_dbs/sbspace1
5 5 0 512000 511512 PO-B- /opt/gbase/gbase01_dbs/tmpdbs1
6 6 0 512000 511576 PO-B- /opt/gbase/gbase01_dbs/tmpdbs2
7 7 0 512000 511576 PO-B- /opt/gbase/gbase01_dbs/tmpdbs3
8 8 0 512000 511576 PO-B- /opt/gbase/gbase01_dbs/tmpdbs4
9 9 0 51200 40264 PO-BE /opt/gbase/gbase01_dbs/datadbs1_1
10 10 0 51200 50776 PO-BE /opt/gbase/gbase01_dbs/datadbs2_1
11 11 0 51200 50776 PO-BE /opt/gbase/gbase01_dbs/datadbs3_1
Continue restore? (y/n)y
Do you want to back up the logs? (y/n)n
Restore a level 1 archive (y/n) y
Ready for level 1 tape
Restore will use level 1 archive file /opt/gbase/backup/ccc/peixun-0054_2_L1. Press Return to continue ...
Archive Tape Information
Tape type: Archive Backup Tape
Online version: GBase Database Server Version 12.10.FC4G1AEE
Archive date: Thu Nov 23 09:20:59 2023
User id: gbasedbt
Terminal id: /dev/pts/1
Archive level: 1
Tape device: /opt/gbase/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
Do you want to restore log tapes? (y/n)n
/opt/gbase/bin/onmode -sy
Program over.
可以看到备份成功了。
也就是说,如果没有-t参数,ontape备份的时候默认读取到TAPEDEV参数的路径。
如果有-t参数,那就到-t后的路径里寻找备份文件,寻找的备份文件命名格式为 hostname_SERVERNUM_L0 hostname_SERVERNUM_L1 hostname_SERVERNUM_L2
三、番外篇:
如果只想恢复到第一次L0,不需要把备份文件复制到其他目录里,可以通过这种方式:
[gbasedbt@peixun-0054 ccc]$ ontape -r -t /opt/gbase/backup/第一次L0备份文件的名称## 需要注意的是,此种恢复无法恢复L1 L2。
四、备份文档的命名规则:
备份文件命名规则:
<hostname>_<servernum>_L<#>
<hostname> 数据库所在机器的hostname
<servernum>数据库实例的编号
L<#>为备份级别
示例:server1_101_L0
<hostname>_<servernum>_Log<#######>
<hostname> 数据库所在机器的hostname
<servernum>数据库实例的编号
Log<######>日志的唯一id号
示例:server1_101_Log12012321321
热门帖子
- 12025-12-01浏览数:182763
- 22023-05-09浏览数:25059
- 42023-09-25浏览数:18525
- 52020-05-11浏览数:17529