背景:HostA上oracle通过NBU进行RMAN备份至带库,从HostB上恢复该库;
目的:在丢失了一部分数据的情况下,但因为没有足够的空间不能做整库恢复,只想恢复部分表;
so假设:源主机HostA,目标主机HostB,NBUMaster主机Po,Oracle_sid均为test,
Oracle用户均为ora。
步骤:
1、增加Po主机上文件
[Po:root]#touch /usr/openv/netbackup/db/altnames/No.Restrictions
//取消nbu的异机恢复限制
2、修改Po主机上文件,修改参数
[Po:root]#vi /usr/openv/netbackup/bp.conf
FORCE_RESTORE_MEDIA_SERVER = HostA HostB
  这步需要重启netbackup
下面开始恢复步骤(均为ora用户操作)
3、copy spfile
在HostA上test数据库的pfile(create pfile from spfile)ftp至HostB中的
   $ORACLE_HOME/db下
4、HostB上,密码文件、相应的dump目录
   [HostB:ora]#orapwd file=<fname> password=<password> entries=<users>
   [HostB:ora]#mkdir $admin/test/*dump
5、启动数据库至nomount
   [HostB:ora]#sqlplus / as sysdba
Connected to an idle instance.
SQL> startup nomount
ORACLE instance started.
Total System Global Area 1526726656 bytes
Fixed Size                   2191720 bytes
Variable Size             1430245016 bytes
Database Buffers           83886080 bytes
Redo Buffers               10403840 bytes
6、登录catalog,进行rman恢复
[HostB:ora]#rman target / catalog user/pwd@rman
connected to target database: TEST (not mounted)
connected to recovery catalog database
7、set dbid(HostA上test库的dbid)
RMAN> set dbid=2091611406
executing command: SET DBID
database name is "TEST" and DBID is 2091611406
8、恢复control file
RMAN> RUN {
2>       ALLOCATE CHANNEL D1 TYPE 'sbt_tape';
3>       send 'NB_ORA_SERV=Po,NB_ORA_CLIENT=HostA'; //一定需要NB_ORA_CLIENT,否则找不到介质
4>       RESTORE CONTROLFILE;
5>       RELEASE CHANNEL D1;
6>       }
allocated channel: D1
channel D1: sid=166 devtype=SBT_TAPE
channel D1: VERITAS NetBackup for Oracle - Release 6.0 (2006110304)
sent command to channel: D1
Starting restore at 2009-05-11:21:24:58
channel D1: starting datafile backupset restore
channel D1: restoring control file
channel D1: reading from backup piece c-3381955389-20090511-02
channel D1: restored backup piece 1
piece handle=c-3381955389-20090511-02 tag=TAG20090511T170809
channel D1: restore complete, elapsed time: 00:01:47
output filename=/test/control01.ctl
output filename=/test/control02.ctl
output filename=/test/control03.ctl
Finished restore at 2009-05-11:21:26:56
released channel: D1
9、控制文件修复成功,将库alter至mount状态
RMAN> alter database mount;
database mounted
10、恢复数据库
RMAN> run {
2>       ALLOCATE CHANNEL D1 TYPE 'SBT_TAPE';
3>       send 'NB_ORA_SERV=Po,NB_ORA_CLIENT=HostA';
4>       restore database skip tablespace users;//屏蔽不想恢复的users表空间
6>       recover database SKIP FOREVER TABLESPACE users;
5>     RELEASE CHANNEL D1;
7>   }
allocated channel: D1
channel D1: sid=44 devtype=SBT_TAPE
channel D1: VERITAS NetBackup for Oracle - Release 6.0 (2006110304)
sent command to channel: D1
Starting restore at 2009-05-11:21:46:50
channel D1: starting datafile backupset restore
channel D1: specifying datafile(s) to restore from backup set
restoring datafile 00003 to /test/sysaux01.dbf
channel D1: reading from backup piece bk_2_1_686595521
channel D1: restored backup piece 1
piece handle=bk_2_1_686595521 tag=HOT_DB_BK_LEVEL0
channel D1: restore complete, elapsed time: 00:02:26
channel D1: starting datafile backupset restore
channel D1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /test/system01.dbf
channel D1: reading from backup piece bk_1_1_686595521
channel D1: restored backup piece 1
piece handle=bk_1_1_686595521 tag=HOT_DB_BK_LEVEL0
channel D1: restore complete, elapsed time: 00:02:57
channel D1: starting datafile backupset restore
channel D1: specifying datafile(s) to restore from backup set
restoring datafile 00002 to /test/undotbs01.dbf
channel D1: reading from backup piece bk_3_1_686595521
channel D1: restored backup piece 1
piece handle=bk_3_1_686595521 tag=HOT_DB_BK_LEVEL0
channel D1: restore complete, elapsed time: 00:01:55
Finished restore at 2009-05-11:21:54:23
Starting recover at 2009-05-11:21:54:24
starting media recovery
channel D1: starting archive log restore to default destination
channel D1: restoring archive log
archive log thread=1 sequence=5
channel D1: reading from backup piece al_8_1_686595863
channel D1: restored backup piece 1
piece handle=al_8_1_686595863 tag=TAG20090511T170423
channel D1: restore complete, elapsed time: 00:01:57
archive log filename=/oracle10/app/oracle/product/10.2.0/dbs/arch1_5_686569151.dbf thread=1 sequence=5
unable to find archive log
archive log thread=1 sequence=6
released channel: D1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 05/11/2009 21:56:39
RMAN-06054: media recovery requesting unknown log: thread 1 seq 6 lowscn 608603
recover成功,因为没有恢复归档,所以会报一些错,这里忽略。
11,open数据库
RMAN> alter database open resetlogs;
database opened
new incarnation of database registered in recovery catalog
starting full resync of recovery catalog
full resync complete
数据库打开成功,over!

一些tips:
1、pfile参数需要修改,否则起库可能会报错,内存等参数肯定在恢复库的时候不会设置的和生产库一样大
SQL> startup nomount
ORA-00439: feature not enabled: Real Application Clusters
(恢复rac的时候,要删掉一些rac库的参数)
SQL> startup nomount
ORA-27154: post/wait create failed
ORA-27300: OS system dependent operation:semget failed with status: 28
ORA-27301: OS failure message: No space left on device
ORA-27302: failure occurred at: sskgpcreates
(这个错可能与process、sessions、主机信号量等参数有关)
2、设置错了NB_ORA_CLIENT或是原数据库文件所在目录没有创建,在restore控制文件或数据文件的时候都会报这个错
ORA-19511: Error received from media manager layer, error text:
   Backup file <bk_5_1_686595657> not found in NetBackup catalog
3、设置名字或位置
set newname for datafile 'filename' or filenumber to 'newlocation' ;
设置时间
set until time "to_date('12/8/2004 14:00:00','mm/dd/yyyy hh24:mi:ss')";
4、restore database skip tablespace users;
   recover database skip forever tablespace users;
使用skip参数屏蔽不想要的表空间(10g)


btw:如果空间足够,完全可以把rman备份集全部copy至HostB上恢复,虽然最简单,但这样即需要大量的空间,又会耗费很长的时间,在指想恢复部分表的情况下,这种方法动静大了点。
关键点:nbu的一些配置文件参数(FORCE_RESTORE_MEDIA_SERVER,NB_ORA_CLIENT等参数)、restoredatabase的skip参数。

恢复rac的还没来及做,下一步就要恢复真实数据了