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

玩转NBU异机全库恢复操作,不可错过!

原创 szrsu 2024-11-21
1298

本篇文章基于前面的两篇文章(还在苦于没有真实的物理带库可以让你实操?这么好用的虚拟带库,你不去试试可惜了!)和(Veritas Netbackup(NBU)备份Oracle数据库到虚拟带库实战,值得你一看!)构建的环境来进行的一个异机全库恢复操作,让你知道如何通过NBU来进行恢复的具体过程。

环境准备

环境说明

当前环境如下:

角色 主机名 IP地址 操作系统版本 数据库版本
NBU服务器 ora19c 10.10.10.150 CentOS7.9x64 Oracle 19C
恢复测试机 oratest 10.10.10.33 CentOS7.9x64 Oracle 19C

软件安装

测试机安装好跟备份的数据库相同版本的数据库软件和NBU客户端(参考之前的文章),本步骤略。

NBU服务端配置

NBU服务端需要配置允许异机恢复,否则会报错。

[root@ora19c:/usr/openv/netbackup/db]# mkdir /usr/openv/netbackup/db/altnames [root@ora19c:/usr/openv/netbackup/db]# cd /usr/openv/netbackup/db/altnames [root@ora19c:/usr/openv/netbackup/db/altnames]# touch No.Restrictions [root@ora19c:/usr/openv/netbackup/db/altnames]# ls No.Restrictions

添加创建以上No.Restrictions文件,允许异机恢复,不然异机 bplist 搜索时会报错如下:

[root@oratest:~]# cd /usr/openv/netbackup/bin
[root@oratest:/usr/openv/netbackup/bin]# ./bplist -C ora19c -t 4 -R -l /
EXIT STATUS 135: client is not validated to perform the requested operation

正常显示如下:

[root@oratest:/usr/openv/netbackup/bin]# ./bplist -C ora19c -t 4 -R -l /
-rw-rw---- oracle    oinstall     12845056 Nov 21 20:31 /c-606172501-20241121-03
-rw-rw---- oracle    oinstall     12845056 Nov 21 20:31 /cntrl_91_1_1185654686
-rw-rw---- oracle    oinstall     12845056 Nov 21 20:31 /c-606172501-20241121-02
-rw-rw---- oracle    oinstall      6291456 Nov 21 20:30 /al_89_1_1185654654
-rw-rw---- oracle    oinstall      8912896 Nov 21 20:30 /al_88_1_1185654629
-rw-rw---- oracle    oinstall     72089600 Nov 21 20:30 /al_87_1_1185654629
-rw-rw---- oracle    oinstall     12845056 Nov 21 20:30 /c-606172501-20241121-01
-rw-rw---- oracle    oinstall    320339968 Nov 21 20:28 /bk_85_1_1185654484
-rw-rw---- oracle    oinstall    583532544 Nov 21 20:28 /bk_84_1_1185654484
-rw-rw---- oracle    oinstall     12845056 Nov 20 20:29 /c-606172501-20241120-04
-rw-rw---- oracle    oinstall     12845056 Nov 20 20:28 /cntrl_81_1_1185568130
-rw-rw---- oracle    oinstall     12845056 Nov 20 20:28 /c-606172501-20241120-03
-rw-rw---- oracle    oinstall       262144 Nov 20 20:28 /al_79_1_1185568098
-rw-rw---- oracle    oinstall     10223616 Nov 20 20:28 /al_78_1_1185568083
-rw-rw---- oracle    oinstall     20709376 Nov 20 20:28 /al_77_1_1185568083
-rw-rw---- oracle    oinstall     12845056 Nov 20 20:27 /c-606172501-20241120-02
-rw-rw---- oracle    oinstall    583532544 Nov 20 20:25 /bk_74_1_1185567928
-rw-rw---- oracle    oinstall    320339968 Nov 20 20:25 /bk_75_1_1185567929
-rw-rw---- oracle    oinstall     12845056 Nov 15 17:36 /c-606172501-20241115-06
-rw-rw---- oracle    oinstall     12845056 Nov 15 17:36 /cntrl_66_1_1185125786
-rw-rw---- oracle    oinstall     12845056 Nov 15 17:36 /c-606172501-20241115-05
-rw-rw---- oracle    oinstall       262144 Nov 15 17:35 /al_64_1_1185125754
-rw-rw---- oracle    oinstall      3145728 Nov 15 17:35 /al_63_1_1185125739
-rw-rw---- oracle    oinstall      7340032 Nov 15 17:35 /al_62_1_1185125739
-rw-rw---- oracle    oinstall     12845056 Nov 15 17:35 /c-606172501-20241115-04
-rw-rw---- oracle    oinstall    319815680 Nov 15 17:33 /bk_60_1_1185125594
-rw-rw---- oracle    oinstall    583008256 Nov 15 17:33 /bk_59_1_1185125594
-rw-rw---- oracle    oinstall     12845056 Nov 15 15:12 /c-606172501-20241115-03
-rw-rw---- oracle    oinstall     12845056 Nov 15 15:12 /cntrl_57_1_1185117151
-rw-rw---- oracle    oinstall     12845056 Nov 15 15:12 /c-606172501-20241115-02
-rw-rw---- oracle    oinstall       524288 Nov 15 15:11 /al_55_1_1185117109
-rw-rw---- oracle    oinstall      7340032 Nov 15 15:11 /al_54_1_1185117109
-rw-rw---- oracle    oinstall     12845056 Nov 15 15:11 /c-606172501-20241115-01
-rw-rw---- oracle    oinstall    319029248 Nov 15 15:09 /bk_52_1_1185116974
-rw-rw---- oracle    oinstall    583008256 Nov 15 15:09 /bk_51_1_1185116974

bplist搜索命令:

cd /usr/openv/netbackup/bin ./bplist -C 客户端解析名 -S NBU服务端解析名 -t 4 -R -l /

启动到nomount状态

[oracle@oratest:~]$ export ORACLE_SID=s19c

[oracle@oratest:~]$ rman target /

Recovery Manager: Release 19.0.0.0.0 - Production on Thu Nov 21 20:28:37 2024
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.

connected to target database (not started)

RMAN> startup nomount;

startup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/u01/app/oracle/product/19.3.0/db/dbs/inits19c.ora'

starting Oracle instance without parameter file for retrieval of spfile
Oracle instance started

Total System Global Area    1073737800 bytes

Fixed Size                     8904776 bytes
Variable Size                276824064 bytes
Database Buffers             780140544 bytes
Redo Buffers                   7868416 bytes

还原spfile

RMAN> run {
ALLOCATE CHANNEL ch01 TYPE 'SBT_TAPE' PARMS 'SBT_LIBRARY=/usr/openv/netbackup/bin/libobk.so64';
SEND 'NB_ORA_SERV=ora19c,NB_ORA_CLIENT=ora19c';
restore spfile from '/c-606172501-20241120-04';
RELEASE CHANNEL ch01;
}
2> 3> 4> 5> 6> 

allocated channel: ch01
channel ch01: SID=11 device type=SBT_TAPE
channel ch01: Veritas NetBackup for Oracle - Release 8.1.1 (2018020320)

sent command to channel: ch01

Starting restore at 21-NOV-24

channel ch01: restoring spfile from AUTOBACKUP /c-606172501-20241120-04
channel ch01: SPFILE restore from AUTOBACKUP complete
Finished restore at 21-NOV-24

released channel: ch01

注意上面的参数设置:

NB_ORA_SERV指 NBU master Server,本环境为ora19c。

NB_ORA_CLIENT指备份的Oracle数据库的主机名,本环境刚好跟NBU master Server装在一起,所以也为ora19c,要根据实际环境去设置。

用spfile启动到nomount

用还原成功的spfile文件,重启启动数据库到nomount状态

idle 2024-11-21 21:27:05> shutdown immediate;
ORA-01507: database not mounted


ORACLE instance shut down.

--启动前,要先把spfile指定的相关目录提前创建好
[oracle@oratest:~]$ mkdir -p /u01/app/oracle/admin/s19c/adump
[oracle@oratest:~]$ mkdir -p /u01/arch

--启动到nomount
[oracle@oratest:~]$ sqlplus / as sysdba

SQL*Plus: Release 19.0.0.0.0 - Production on Thu Nov 21 21:33:22 2024
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle.  All rights reserved.

Connected to an idle instance.

idle 21-NOV-24> startup nomount;
ORACLE instance started.

Total System Global Area  805303360 bytes
Fixed Size		    8901696 bytes
Variable Size		  289406976 bytes
Database Buffers	  499122176 bytes
Redo Buffers		    7872512 bytes

还原控制文件

[root@oratest:/usr/openv/netbackup/bin]# ./bplist -C ora19c -t 4 -R -l / |  grep -a "cntrl"
-rw-rw---- oracle    oinstall     12845056 Nov 21 20:31 /cntrl_91_1_1185654686
-rw-rw---- oracle    oinstall     12845056 Nov 20 20:28 /cntrl_81_1_1185568130
-rw-rw---- oracle    oinstall     12845056 Nov 15 17:36 /cntrl_66_1_1185125786
-rw-rw---- oracle    oinstall     12845056 Nov 15 15:12 /cntrl_57_1_1185117151

–还原控制文件

RMAN> RUN 
{
ALLOCATE CHANNEL ch01 TYPE 'SBT_TAPE' PARMS 'SBT_LIBRARY=/usr/openv/netbackup/bin/libobk.so64';
SEND 'NB_ORA_SERV=ora19c,NB_ORA_CLIENT=ora19c';
restore controlfile from '/cntrl_81_1_1185568130';
RELEASE CHANNEL ch01;
}2> 3> 4> 5> 6> 7> 

using target database control file instead of recovery catalog
allocated channel: ch01
channel ch01: SID=261 device type=SBT_TAPE
channel ch01: Veritas NetBackup for Oracle - Release 8.1.1 (2018020320)

sent command to channel: ch01

Starting restore at 21-NOV-24

channel ch01: restoring control file
channel ch01: restore complete, elapsed time: 00:00:15
output file name=/oradata/S19C/control01.ctl
output file name=/u01/arch/S19C/control02.ctl
Finished restore at 21-NOV-24

released channel: ch01

–还原成功后,启动到mount状态

RMAN> alter database mount;

Statement processed

恢复数据库

–数据路径与原库一样

run{ 
ALLOCATE CHANNEL ch01 TYPE 'SBT_TAPE' PARMS 'SBT_LIBRARY=/usr/openv/netbackup/bin/libobk.so64';
ALLOCATE CHANNEL ch02 TYPE 'SBT_TAPE' PARMS 'SBT_LIBRARY=/usr/openv/netbackup/bin/libobk.so64';
SEND 'NB_ORA_SERV=ora19c,NB_ORA_CLIENT=ora19c';
set until time "to_date('2024-11-19 21:00:00','yyyy-mm-dd hh24:mi:ss')";
restore database; 
recover database; 
release channel ch01; 
release channel ch02; 
} 

–数据路径与原库不一样

##数据路径与原库不一样,需要用set newname进行更改
run{ 
ALLOCATE CHANNEL ch01 TYPE 'SBT_TAPE' PARMS 'SBT_LIBRARY=/usr/openv/netbackup/bin/libobk.so64';
ALLOCATE CHANNEL ch02 TYPE 'SBT_TAPE' PARMS 'SBT_LIBRARY=/usr/openv/netbackup/bin/libobk.so64';
SEND 'NB_ORA_SERV=ora19c,NB_ORA_CLIENT=ora19c';
set newname for datafile 1 to '/data/S19C/system01.dbf';
set newname for datafile 3 to '/data/S19C/sysaux01.dbf';
set newname for datafile 4 to '/data/S19C/undotbs01.dbf';
set newname for datafile 7 to '/data/S19C/users01.dbf';
set newname for tempfile 1 to '/data/S19C/temp01.dbf';
set until time "to_date('2024-11-18 21:00:00','yyyy-mm-dd hh24:mi:ss')";
restore database; 
switch datafile all;
switch tempfile all;
recover database; 
release channel ch01; 
release channel ch02; 
} 

恢复过程:

RMAN> run{ 
ALLOCATE CHANNEL ch01 TYPE 'SBT_TAPE' PARMS 'SBT_LIBRARY=/usr/openv/netbackup/bin/libobk.so64';
ALLOCATE CHANNEL ch02 TYPE 'SBT_TAPE' PARMS 'SBT_LIBRARY=/usr/openv/netbackup/bin/libobk.so64';
SEND 'NB_ORA_SERV=ora19c,NB_ORA_CLIENT=ora19c';
set until 2> 3> 4> 5> time "to_date('2024-11-19 21:00:00','yyyy-mm-dd hh24:mi:ss')";
restore database; 
recover database; 
release channel ch01; 
release channel ch02; 
} 6> 7> 8> 9> 10> 

allocated channel: ch01
channel ch01: SID=13 device type=SBT_TAPE
channel ch01: Veritas NetBackup for Oracle - Release 8.1.1 (2018020320)

allocated channel: ch02
channel ch02: SID=138 device type=SBT_TAPE
channel ch02: Veritas NetBackup for Oracle - Release 8.1.1 (2018020320)

sent command to channel: ch01
sent command to channel: ch02

executing command: SET until clause

Starting restore at 21-NOV-24
Starting implicit crosscheck backup at 21-NOV-24
Crosschecked 3 objects
Crosschecked 4 objects
Finished implicit crosscheck backup at 21-NOV-24

Starting implicit crosscheck copy at 21-NOV-24
Finished implicit crosscheck copy at 21-NOV-24

searching for all files in the recovery area
cataloging files...
no files cataloged


channel ch01: starting datafile backup set restore
channel ch01: specifying datafile(s) to restore from backup set
channel ch01: restoring datafile 00004 to /oradata/S19C/undotbs01.dbf
channel ch01: restoring datafile 00007 to /oradata/S19C/users01.dbf
channel ch01: reading from backup piece bk_59_1_1185125594
channel ch02: starting datafile backup set restore
channel ch02: specifying datafile(s) to restore from backup set
channel ch02: restoring datafile 00001 to /oradata/S19C/system01.dbf
channel ch02: restoring datafile 00003 to /oradata/S19C/sysaux01.dbf
channel ch02: reading from backup piece bk_60_1_1185125594
channel ch01: piece handle=bk_59_1_1185125594 tag=HOT_DB_BK_INC_LVL0
channel ch01: restored backup piece 1
channel ch01: restore complete, elapsed time: 00:01:25
channel ch02: piece handle=bk_60_1_1185125594 tag=HOT_DB_BK_INC_LVL0
channel ch02: restored backup piece 1
channel ch02: restore complete, elapsed time: 00:02:15
Finished restore at 21-NOV-24

Starting recover at 21-NOV-24

starting media recovery

channel ch01: starting archived log restore to default destination
channel ch01: restoring archived log
archived log thread=1 sequence=68
channel ch01: restoring archived log
archived log thread=1 sequence=69
channel ch01: reading from backup piece al_78_1_1185568083
channel ch02: starting archived log restore to default destination
channel ch02: restoring archived log
archived log thread=1 sequence=70
channel ch02: reading from backup piece al_77_1_1185568083
channel ch02: piece handle=al_77_1_1185568083 tag=TAG20241120T202803
channel ch02: restored backup piece 1
channel ch02: restore complete, elapsed time: 00:00:07
channel ch01: piece handle=al_78_1_1185568083 tag=TAG20241120T202803
channel ch01: restored backup piece 1
channel ch01: restore complete, elapsed time: 00:00:15
archived log file name=/u01/arch/S19C/archivelog/2024_11_21/o1_mf_1_68_mmyjr1tv_.arc thread=1 sequence=68
channel default: deleting archived log(s)
archived log file name=/u01/arch/S19C/archivelog/2024_11_21/o1_mf_1_68_mmyjr1tv_.arc RECID=2093 STAMP=1185661570
archived log file name=/u01/arch/S19C/archivelog/2024_11_21/o1_mf_1_69_mmyjr1wk_.arc thread=1 sequence=69
channel default: deleting archived log(s)
archived log file name=/u01/arch/S19C/archivelog/2024_11_21/o1_mf_1_69_mmyjr1wk_.arc RECID=2092 STAMP=1185661569
archived log file name=/u01/arch/S19C/archivelog/2024_11_21/o1_mf_1_70_mmyjqy92_.arc thread=1 sequence=70
channel default: deleting archived log(s)
archived log file name=/u01/arch/S19C/archivelog/2024_11_21/o1_mf_1_70_mmyjqy92_.arc RECID=2091 STAMP=1185661566
media recovery complete, elapsed time: 00:00:01
Finished recover at 21-NOV-24

released channel: ch01

released channel: ch02

打开数据库

–redo logfile如果路径发生变化,需要更改一下

alter database rename file '/oradata/S19C/redo01.log' to '/data/S19C/redo01.log';

alter database rename file '/oradata/S19C/redo02.log' to '/data/S19C/redo02.log';

alter database rename file '/oradata/S19C/redo03.log' to '/data/S19C/redo03.log';

SQL> select member from v$logfile;

MEMBER
--------------------------------------------------------------------------------
/data/S19C/redo03.log
/data/S19C/redo02.log
/data/S19C/redo01.log

–由于是不完全恢复,用open resetlogs进行打开

SQL> alter database open resetlogs;

Database altered.

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

评论