几点说明:
(1)RMAN异机恢复的时候,db_name必须相同。如果说要想改成其他的实例名,可以在恢复成功后,用nid命令修改。实例名的信息会记录到控制文件里,所以如果在恢复的时候,如果实例名不一致,恢复的时候会报错。
(2)如果恢复的路径和源库不一致,就需要在restore时用set命令指定新位置。并且使用switchdatafileall将信息更新的到控制文件。
在做duplicate的时候,RMAN会自动根据pfile中的log_file_name_convert和db_file_name_convert来进行set的转换。手工restore时,只能只只能使用set命令。
(3)异机恢复对相同目录和不同目录都做了说明。
(4)最后测试了NID修改DBID和DBNAME.
一.Target库准备工作:
1.查询DBID
SQL>selectname,dbidfromv$database;
NAMEDBID
-------------------
DAVE808234286
2.备份DB
关于RMAN的shell备份脚本,参考:
Nocatalog下的RMAN增量备份shell脚本
在这里我用0级和1级备份了下DB。
[oracle@qs-dmm-rh1backup]$ls
arch_0pm6qt8q_1_1_20110309dave_lev0_0jm6qt77_1_1_20110309dave_lev1_0um6qtcq_1_1_20110309
arch_0qm6qt8q_1_1_20110309dave_lev0_0km6qt77_1_1_20110309dave_lev1_0vm6qtcq_1_1_20110309
arch_13m6qtda_1_1_20110309dave_lev0_0lm6qt77_1_1_20110309dave_lev1_11m6qtd7_1_1_20110309
arch_14m6qtda_1_1_20110309dave_lev0_0nm6qt7c_1_1_20110309dave_spfile_16m6qtde_1_1_20110309
ctl_file_15m6qtdc_1_1_20110309dave_lev1_0tm6qtcq_1_1_20110309
二.Auxiliary库准备工作:
1.创建口令文件
[oracle@qs-dmm-rh2trace]$orapwdfile=?/dbs/orapwdavepassword=oracle
2.创建相关的目录
[oracle@qs-dmm-rh2u01]$mkdiroradata
[oracle@qs-dmm-rh2oradata]$pwd
/u01/oradata
3.创建初始化参数
将Target库的pfile文件copy过来。
也可以使用RMAN从我们Target库的备份集中恢复,因为我们之前备份过spfile。不过使用RMAN,DB要先启动到nomout状态。这个可以用默认的init.ora来启动。
[oracle@qs-dmm-rh2backup]$exportORACLE_SID=dave
[oracle@qs-dmm-rh2backup]$rmantarget/
RecoveryManager:Release11.2.0.1.0-ProductiononFriMar1115:11:312011
Copyright(c)1982,2009,Oracleand/oritsaffiliates.Allrightsreserved.
connectedtotargetdatabase:DAVE(notmounted)
RMAN>restorespfiletopfile'/u01/app/oracle/product/11.2.0/dbhome_1/dbs/initdave2.ora'from'/u01/backup/dave_spfile_16m6qtde_1_1_20110309';
Startingrestoreat11-MAR-11
usingtargetdatabasecontrolfileinsteadofrecoverycatalog
allocatedchannel:ORA_DISK_1
channelORA_DISK_1:SID=19devicetype=DISK
channelORA_DISK_1:restoringspfilefromAUTOBACKUP/u01/backup/dave_spfile_16m6qtde_1_1_20110309
channelORA_DISK_1:SPFILErestorefromAUTOBACKUPcomplete
Finishedrestoreat11-MAR-11
如果修改数据文件保存的位置,那么要修改控制文件的相关的参数:
*.control_files='/u01/oradata/control01.ctl','/u01/oradata/control02.ctl','/u01/oradata/control03.ctl'
*.db_name='dave'
4.将用pfile将Auxiliary库启动到nomout状态
SQL>startupnomountpfile=?/dbs/initdave.ora
5.恢复控制文件
[oracle@qs-dmm-rh2dbs]$exportORACLE_SID=dave
[oracle@qs-dmm-rh2dbs]$rmantarget/
RecoveryManager:Release11.2.0.1.0-ProductiononFriMar1115:25:552011
Copyright(c)1982,2009,Oracleand/oritsaffiliates.Allrightsreserved.
connectedtotargetdatabase:DAVE(notmounted)
RMAN>restorecontrolfilefrom'/u01/backup/ctl_file_15m6qtdc_1_1_20110309';
Startingrestoreat11-MAR-11
usingtargetdatabasecontrolfileinsteadofrecoverycatalog
allocatedchannel:ORA_DISK_1
channelORA_DISK_1:SID=20devicetype=DISK
channelORA_DISK_1:restoringcontrolfile
channelORA_DISK_1:restorecomplete,elapsedtime:00:00:01
outputfilename=/u01/oradata/control01.ctl
outputfilename=/u01/oradata/control02.ctl
outputfilename=/u01/oradata/control03.ctl
Finishedrestoreat11-MAR-11
restore的时候需要控制文件,控制文件恢复的位置,是我们在pfile中的control_files参数控制的。
6.将DB启动到mout状态
RMAN>alterdatabasemount;
databasemounted
releasedchannel:ORA_DISK_1
7.restore数据库
7.1恢复目录不同的情况:
因为我们的路径不同,所以我们需要使用set命令转换一下路径。
到Target库查询一下:
SQL>selectfile_id,file_namefromdba_data_files;
FILE_IDFILE_NAME
-----------------------------------------------------
4/u01/app/oracle/oradata/dave/users01.dbf
3/u01/app/oracle/oradata/dave/undotbs01.dbf
2/u01/app/oracle/oradata/dave/sysaux01.dbf
1/u01/app/oracle/oradata/dave/system01.dbf
SQL>selectfile_id,file_namefromdba_temp_files;
FILE_IDFILE_NAME
----------------------------------------------------
1/u01/app/oracle/oradata/dave/temp01.dbf
注意,restore的时候不会对temp表空间进行restore。所以等restore之后,我们需要手工创建temp表空间。
RMAN>run
2>{
setnewnamefordatafile1to"/u01/oradata/system01.dbf";
3>4>setnewnamefordatafile2to"/u01/oradata/sysaux01.dbf";
5>setnewnamefordatafile3to"/u01/oradata/undotbs01.dbf";
6>setnewnamefordatafile4to"/u01/oradata/users01.dbf";
7>restoredatabase;
8>switchdatafileall;
9>}
对switchdatafileall的说明:
--对于nocatalog模式下,rman备份的信息是保存在控制文件里的,包括文件的路径信息。这里的switchdatafileall的作用,就是更新控制文件里的信息。
executingcommand:SETNEWNAME
releasedchannel:ORA_DISK_1
executingcommand:SETNEWNAME
executingcommand:SETNEWNAME
executingcommand:SETNEWNAME
Startingrestoreat11-MAR-11
allocatedchannel:ORA_DISK_1
channelORA_DISK_1:SID=20devicetype=DISK
channelORA_DISK_1:startingdatafilebackupsetrestore
channelORA_DISK_1:specifyingdatafile(s)torestorefrombackupset
channelORA_DISK_1:restoringdatafile00003to/u01/oradata/undotbs01.dbf
channelORA_DISK_1:readingfrombackuppiece/u01/backup/dave_lev0_0lm6qt77_1_1_20110309
channelORA_DISK_1:piecehandle=/u01/backup/dave_lev0_0lm6qt77_1_1_20110309tag=DAVE_LEV0
channelORA_DISK_1:restoredbackuppiece1
channelORA_DISK_1:restorecomplete,elapsedtime:00:00:03
channelORA_DISK_1:startingdatafilebackupsetrestore
channelORA_DISK_1:specifyingdatafile(s)torestorefrombackupset
channelORA_DISK_1:restoringdatafile00004to/u01/oradata/users01.dbf
channelORA_DISK_1:readingfrombackuppiece/u01/backup/dave_lev0_0nm6qt7c_1_1_20110309
channelORA_DISK_1:piecehandle=/u01/backup/dave_lev0_0nm6qt7c_1_1_20110309tag=DAVE_LEV0
channelORA_DISK_1:restoredbackuppiece1
channelORA_DISK_1:restorecomplete,elapsedtime:00:00:01
channelORA_DISK_1:startingdatafilebackupsetrestore
channelORA_DISK_1:specifyingdatafile(s)torestorefrombackupset
channelORA_DISK_1:restoringdatafile00002to/u01/oradata/sysaux01.dbf
channelORA_DISK_1:readingfrombackuppiece/u01/backup/dave_lev0_0km6qt77_1_1_20110309
channelORA_DISK_1:piecehandle=/u01/backup/dave_lev0_0km6qt77_1_1_20110309tag=DAVE_LEV0
channelORA_DISK_1:restoredbackuppiece1
channelORA_DISK_1:restorecomplete,elapsedtime:00:00:15
channelORA_DISK_1:startingdatafilebackupsetrestore
channelORA_DISK_1:specifyingdatafile(s)torestorefrombackupset
channelORA_DISK_1:restoringdatafile00001to/u01/oradata/system01.dbf
channelORA_DISK_1:readingfrombackuppiece/u01/backup/dave_lev0_0jm6qt77_1_1_20110309
channelORA_DISK_1:piecehandle=/u01/backup/dave_lev0_0jm6qt77_1_1_20110309tag=DAVE_LEV0
channelORA_DISK_1:restoredbackuppiece1
channelORA_DISK_1:restorecomplete,elapsedtime:00:00:25
Finishedrestoreat11-MAR-11
datafile1switchedtodatafilecopy
inputdatafilecopyRECID=5STAMP=745522150filename=/u01/oradata/system01.dbf
datafile2switchedtodatafilecopy
inputdatafilecopyRECID=6STAMP=745522150filename=/u01/oradata/sysaux01.dbf
datafile3switchedtodatafilecopy
inputdatafilecopyRECID=7STAMP=745522150filename=/u01/oradata/undotbs01.dbf
datafile4switchedtodatafilecopy
inputdatafilecopyRECID=8STAMP=745522150filename=/u01/oradata/users01.dbf
7.2恢复目录相同
这种情况比较简单,直接:
RMAN>restoredatabase;
8.recoverDB
RMAN>recoverdatabase;
Startingrecoverat11-MAR-11
usingchannelORA_DISK_1
channelORA_DISK_1:startingincrementaldatafilebackupsetrestore
channelORA_DISK_1:specifyingdatafile(s)torestorefrombackupset
destinationforrestoreofdatafile00001:/u01/oradata/system01.dbf
channelORA_DISK_1:readingfrombackuppiece/u01/backup/dave_lev1_0tm6qtcq_1_1_20110309
channelORA_DISK_1:piecehandle=/u01/backup/dave_lev1_0tm6qtcq_1_1_20110309tag=DAVE_LEV1
channelORA_DISK_1:restoredbackuppiece1
channelORA_DISK_1:restorecomplete,elapsedtime:00:00:01
channelORA_DISK_1:startingincrementaldatafilebackupsetrestore
channelORA_DISK_1:specifyingdatafile(s)torestorefrombackupset
destinationforrestoreofdatafile00002:/u01/oradata/sysaux01.dbf
channelORA_DISK_1:readingfrombackuppiece/u01/backup/dave_lev1_0um6qtcq_1_1_20110309
channelORA_DISK_1:piecehandle=/u01/backup/dave_lev1_0um6qtcq_1_1_20110309tag=DAVE_LEV1
channelORA_DISK_1:restoredbackuppiece1
channelORA_DISK_1:restorecomplete,elapsedtime:00:00:02
channelORA_DISK_1:startingincrementaldatafilebackupsetrestore
channelORA_DISK_1:specifyingdatafile(s)torestorefrombackupset
destinationforrestoreofdatafile00003:/u01/oradata/undotbs01.dbf
channelORA_DISK_1:readingfrombackuppiece/u01/backup/dave_lev1_0vm6qtcq_1_1_20110309
channelORA_DISK_1:piecehandle=/u01/backup/dave_lev1_0vm6qtcq_1_1_20110309tag=DAVE_LEV1
channelORA_DISK_1:restoredbackuppiece1
channelORA_DISK_1:restorecomplete,elapsedtime:00:00:01
channelORA_DISK_1:startingincrementaldatafilebackupsetrestore
channelORA_DISK_1:specifyingdatafile(s)torestorefrombackupset
destinationforrestoreofdatafile00004:/u01/oradata/users01.dbf
channelORA_DISK_1:readingfrombackuppiece/u01/backup/dave_lev1_11m6qtd7_1_1_20110309
channelORA_DISK_1:piecehandle=/u01/backup/dave_lev1_11m6qtd7_1_1_20110309tag=DAVE_LEV1
channelORA_DISK_1:restoredbackuppiece1
channelORA_DISK_1:restorecomplete,elapsedtime:00:00:01
startingmediarecovery
channelORA_DISK_1:startingarchivedlogrestoretodefaultdestination
channelORA_DISK_1:restoringarchivedlog
archivedlogthread=1sequence=7
channelORA_DISK_1:readingfrombackuppiece/u01/backup/arch_13m6qtda_1_1_20110309
channelORA_DISK_1:piecehandle=/u01/backup/arch_13m6qtda_1_1_20110309tag=ARC_BAK
channelORA_DISK_1:restoredbackuppiece1
channelORA_DISK_1:restorecomplete,elapsedtime:00:00:01
archivedlogfilename=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_7_745352047.dbfthread=1sequence=7
channelORA_DISK_1:startingarchivedlogrestoretodefaultdestination
channelORA_DISK_1:restoringarchivedlog
archivedlogthread=1sequence=8
channelORA_DISK_1:readingfrombackuppiece/u01/backup/arch_14m6qtda_1_1_20110309
channelORA_DISK_1:piecehandle=/u01/backup/arch_14m6qtda_1_1_20110309tag=ARC_BAK
channelORA_DISK_1:restoredbackuppiece1
channelORA_DISK_1:restorecomplete,elapsedtime:00:00:01
archivedlogfilename=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_8_745352047.dbfthread=1sequence=8
unabletofindarchivedlog
archivedlogthread=1sequence=9
RMAN-00571:===========================================================
RMAN-00569:===============ERRORMESSAGESTACKFOLLOWS===============
RMAN-00571:===========================================================
RMAN-03002:failureofrecovercommandat03/11/201117:32:00
RMAN-06054:mediarecoveryrequestingunknownarchivedlogforthread1withsequence9andstartingSCNof823627
RMAN>
之后会报一个错误:
RMAN-06054:mediarecoveryrequestingunknownarchivedlogforthread1withsequence9andstartingSCNof823627
这里是提醒恢复到一个未知的scn号。在alterdatabasemount之后,通过setuntilscn或者setuntiltime命令设置恢复到的scn号或时间。就可以避免这个错误。
9.用openresetlogs打开数据库
SQL>alterdatabaseopenresetlogs;
Databasealtered.
我测试的平台是11gR2的版本,在openresetlogs之后,自动在原来默认的路径创建了temp表空间和3组redo文件。
如果恢复目录和原来相同,就不用修改。
如果目录不同,我们就需要把这些文件移到我们现在的data目录。
源目录:
[oracle@qs-dmm-rh2dave]$pwd
/u01/app/oracle/oradata/dave
[oracle@qs-dmm-rh2dave]$ls
redo01.logredo02.logredo03.logtemp01.dbf
现在的目录:
[oracle@qs-dmm-rh2dave]$cd/u01/oradata/
[oracle@qs-dmm-rh2oradata]$ls
control01.ctlcontrol02.ctlcontrol03.ctlsysaux01.dbfsystem01.dbfundotbs01.dbfusers01.dbf
(1)处理onlineredolog
SQL>selectgroup#,bytes/1024/1024||'M',statusfromv$log;
GROUP#BYTES/1024/1024||'M'STATUS
-------------------------------------------------------------------
150MINACTIVE
250MCURRENT
350MUNUSED
SQL>selectgroup#,memberfromv$logfile;
GROUP#MEMBER
-------------------------------------------------------------------------------
3/u01/app/oracle/oradata/dave/redo03.log
2/u01/app/oracle/oradata/dave/redo02.log
1/u01/app/oracle/oradata/dave/redo01.log
oracle至少有2组redolog。所以我们可以将已经完成归档的redodrop掉,重新创建。
SQL>alterdatabasedroplogfilegroup3;
Databasealtered.
SQL>alterdatabaseaddlogfilegroup3('/u01/oradata/redo03.log')size50m;
Databasealtered.
SQL>altersystemswitchlogfile;
Systemaltered.
SQL>selectgroup#,bytes/1024/1024||'M',statusfromv$log;
GROUP#BYTES/1024/1024||'M'STATUS
-------------------------------------------------------------------
150MINACTIVE
250MACTIVE
350MCURRENT
SQL>alterdatabasedroplogfilegroup1;
Databasealtered.
SQL>alterdatabaseaddlogfilegroup1('/u01/oradata/redo01.log')size50m;
Databasealtered.
SQL>altersystemswitchlogfile;
Systemaltered.
SQL>alterdatabasedroplogfilegroup2;
Databasealtered.
SQL>alterdatabaseaddlogfilegroup2('/u01/oradata/redo02.log')size50m;
Databasealtered.
SQL>selectgroup#,memberfromv$logfile;
GROUP#MEMBER
-------------------------------------------------------------------------------
3/u01/oradata/redo03.log
2/u01/oradata/redo02.log
1/u01/oradata/redo01.log
(2)处理temp临时表空间
SQL>selectnamefromv$tempfile;
NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/dave/temp01.dbf
--表空间offline
SQL>alterdatabasetempfile'/u01/app/oracle/oradata/dave/temp01.dbf'offline;
Databasealtered.
--在OS级别移动temp的数据文件
SQL>!mv/u01/app/oracle/oradata/dave/temp01.dbf/u01/oradata/temp01.dbf
--修改控制文件中temp文件的信息
SQL>alterdatabaserenamefile'/u01/app/oracle/oradata/dave/temp01.dbf'to'/u01/oradata/temp01.dbf';
Databasealtered.
--temp表空间online
SQL>alterdatabasetempfile'/u01/oradata/temp01.dbf'online;
Databasealtered.
--验证
SQL>selectnamefromv$tempfile;
NAME
--------------------------------------------------------------------------------
/u01/oradata/temp01.dbf