试用dbms_backup_restore包
<DIV><FONT face=宋体 size=2>本来想试一试10g RMAN里的catalog命令,于是我对现在测试库做了一个全库备份并将我将控制文件备份到文件:</FONT></DIV><DIV> </DIV>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<DIV><FONT face=Arial color=#808080 size=2>RMAN> backup database plus archivelog delete input;</FONT></DIV><FONT color=#808080></FONT>
<DIV><BR><A href="mailto:SYS@test" target=_blank><FONT face=Arial color=#808080 size=2>SYS@test</FONT></A><FONT face=Arial color=#808080 size=2> SQL> alter database backup controlfile to trace;</FONT></DIV>
<DIV><FONT face=Arial color=#808080 size=2>Database altered.</FONT></DIV></BLOCKQUOTE>
<DIV><FONT face=Arial color=#808080 size=1></FONT> </DIV>
<DIV><FONT face=宋体 color=#000000 size=2>我将所有控制文件,数据文件和重做日志全部删除。我假定我的备份集中没有控制文件,我尝试通过手工创建控制文件,然后使用catalog将备份集catalog到新建的日志文件中去。可是失败了,因为没有数据文件,无法手工创建控制文件:</FONT></DIV>
<DIV><FONT face=Arial color=#808080 size=1></FONT> </DIV>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<DIV><FONT face=Arial color=#808080 size=2>SQL*Plus: Release 10.2.0.4.0 - Production on Tue Aug 9 16:19:37 2011</FONT></DIV>
<DIV><FONT face=Arial color=#808080 size=2>Copyright (c) 1982, 2007, Oracle. All Rights Reserved.</FONT></DIV>
<DIV><BR><FONT face=Arial color=#808080 size=2>Connected to:<BR>Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production<BR>With the Partitioning, OLAP, Data Mining and Real Application Testing options</FONT></DIV>
<DIV><A href="mailto:SYS@test" target=_blank><FONT face=Arial color=#808080 size=2>SYS@test</FONT></A><FONT face=Arial color=#808080 size=2> SQL> CREATE CONTROLFILE REUSE DATABASE "TEST" RESETLOGS ARCHIVELOG<BR> 2 MAXLOGFILES 16<BR> 3 MAXLOGMEMBERS 3<BR> 4 MAXDATAFILES 100<BR> 5 MAXINSTANCES 8<BR> 6 MAXLOGHISTORY 292<BR> 7 LOGFILE<BR> 8 GROUP 1 '/u01/app/oracle/oradata/test/redo01.log' SIZE 50M,<BR> 9 GROUP 2 '/u01/app/oracle/oradata/test/redo02.log' SIZE 50M,<BR> 10 GROUP 3 '/u01/app/oracle/oradata/test/redo03.log' SIZE 50M<BR> 11 -- STANDBY LOGFILE<BR> 12 DATAFILE<BR> 13 '/u01/app/oracle/oradata/test/system01.dbf',<BR> 14 '/u01/app/oracle/oradata/test/undotbs01.dbf',<BR> 15 '/u01/app/oracle/oradata/test/sysaux01.dbf',<BR> 16 '/u01/app/oracle/oradata/test/users01.dbf',<BR> 17 '/u01/app/oracle/oradata/test/test01.dbf',<BR> 18 '/u01/app/oracle/oradata/test/test02.dbf',<BR> 19 '/u01/app/oracle/product/10.2.0/dbs/t1_01.ora',<BR> 20 '/u01/app/oracle/product/10.2.0/dbs/undots02.ora'<BR> 21 CHARACTER SET AL32UTF8<BR> 22 ;<BR>CREATE CONTROLFILE REUSE DATABASE "TEST" RESETLOGS ARCHIVELOG<BR>*<BR>ERROR at line 1:<BR>ORA-01503: CREATE CONTROLFILE failed<BR>ORA-01565: error in identifying file<BR>'/u01/app/oracle/oradata/test/system01.dbf'<BR>ORA-27037: unable to obtain file status<BR>Linux Error: 2: No such file or directory<BR>Additional information: 3</FONT></DIV></BLOCKQUOTE>
<DIV> </DIV>
<DIV><FONT size=2>看来必须先将数据文件恢复回来,在这种情况下,我尝试使用dbms_backup_restore包,先将数据文件恢复回来:</FONT></DIV>
<DIV> </DIV>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<DIV><FONT face=Arial color=#808080 size=2>SQL*Plus: Release 10.2.0.4.0 - Production on Tue Aug 9 16:20:11 2011</FONT></DIV>
<DIV><FONT face=Arial color=#808080 size=2>Copyright (c) 1982, 2007, Oracle. All Rights Reserved.</FONT></DIV>
<DIV><BR><FONT face=Arial color=#808080 size=2>Connected to:<BR>Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production<BR>With the Partitioning, OLAP, Data Mining and Real Application Testing options</FONT></DIV>
<DIV><A href="mailto:SYS@test" target=_blank><FONT face=Arial color=#808080 size=2>SYS@test</FONT></A><FONT face=Arial><FONT size=2><FONT color=#808080> SQL> declare<BR> 2 devtype varchar2(256);<BR> 3 done boolean;<BR> 4 begin<BR> 5 devtype:=sys.dbms_backup_restore.deviceallocate(type=>'',ident=>'t1');<BR> 6 sys.dbms_backup_restore.restoresetdatafile;<BR> 7 sys.dbms_backup_restore.restoredatafileto(dfnumber=>01,toname=>'/u01/app/oracle/oradata/test/system01.dbf');<BR> 8 sys.dbms_backup_restore.restoredatafileto(dfnumber=>03,toname=>'/u01/app/oracle/oradata/test/sysaux01.dbf');<BR> 9 sys.dbms_backup_restore.restoredatafileto(dfnumber=>06,toname=>'/u01/app/oracle/oradata/test/test02.dbf');<BR> 10 sys.dbms_backup_restore.restoredatafileto(dfnumber=>07,toname=>'/u01/app/oracle/product/10.2.0/dbs/t1_01.ora');<BR> 11 sys.dbms_backup_restore.restorebackuppiece(done=>done,handle=>'/u01/rman_back/TEST/TEST_20110809_47mjio1k_1_1',params=>null);<BR> 12 sys.dbms_backup_restore.devicedeallocate;<BR> 13 end;<BR> 14 /</FONT><BR><FONT color=#808080>PL/SQL procedure successfully completed.</FONT></FONT></FONT></DIV><FONT color=#808080 size=1>
<DIV><A href="mailto:SYS@test" target=_blank><FONT face=Arial>S<FONT size=2>YS@test</FONT></FONT></A><FONT face=Arial size=2> SQL> declare<BR> 2 devtype varchar2(256);<BR> 3 done boolean;<BR> 4 begin<BR> 5 devtype:=sys.dbms_backup_restore.deviceallocate(type=>'',ident=>'t1');<BR> 6 sys.dbms_backup_restore.restoresetdatafile;<BR> 7 sys.dbms_backup_restore.restoredatafileto(dfnumber=>04,toname=>'/u01/app/oracle/oradata/test/users01.dbf');<BR>sys.dbms_backup_restore.restoredatafileto(dfnumber=>02,toname=>'/u01/app/oracle/oradata/test/undotbs01.dbf');<BR>sys.dbms_backup_restore.restoredatafileto(dfnumber=>05,toname=>'/u01/app/oracle/oradata/test/test01. 8 dbf');<BR>sys.dbms_backup_restore.restoredatafileto(dfnumber=>08,toname=>'/u01/app/oracle/product/10.2.0/dbs/undots02.ora');<BR>sys.dbms_backup_restore.rest 9 orebackuppiece(done=>done,handle=>'/u01/rman_back/TEST/TEST_20110809_46mjio1k_1_1',params=>null);<BR>sys.dbms_backup_restore.devicedealloca 10 te;<BR>end;<BR>/ 11 12 13 14</FONT></DIV>
<DIV><FONT face=Arial size=2>PL/SQL procedure successfully completed.</FONT></DIV></BLOCKQUOTE><FONT face=Arial>
<DIV><BR></FONT> </DIV></FONT>
<DIV><FONT size=2>注意:使用这个脚本必须知道每一个数文件与备份集的关系,不然会出错,错误代码忘记拷贝了。可能通过备份时的日志查看一一对应的关系。所以再次证明了保存好备份日志也是一件非常必要的事。</FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2>实验做到这里,本来打算手工重建控制文件的,然后使用catalog命令。但我并没有这样做,而是干脆把使用dbms_backup_restore包的实验做到底了。</FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2>恢复控制文件:</FONT></DIV>
<DIV> </DIV>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<DIV><A href="mailto:SYS@test" target=_blank><FONT face=Arial color=#808080 size=2>SYS@test</FONT></A><FONT face=Arial color=#808080 size=2> SQL> declare<BR> 2 devtype varchar2(256);<BR> 3 done boolean;<BR> 4 begin<BR> 5 devtype:=sys.dbms_backup_restore.deviceallocate(type=>'',ident=>'t1');<BR> 6 sys.dbms_backup_restore.restoresetdatafile;<BR> 7 sys.dbms_backup_restore.restoreControlfileTo (cfname=>'/u01/app/oracle/oradata/test/control01.ctl');<BR> 8 sys.dbms_backup_restore.restorebackuppiece(done=>done,handle=>'/u01/rman_back/TEST/c-2012049283-20110809-00',params=>null);<BR>sys.dbms_backup_restore.devicedeallocate;<BR>end;<BR>/<BR> 9 10 11<BR>PL/SQL procedure successfully completed.<BR></FONT></DIV></BLOCKQUOTE>
<DIV> </DIV>
<DIV><FONT size=2>恢复归档日志:</FONT></DIV>
<DIV> </DIV>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<DIV><A href="mailto:SYS@test" target=_blank><FONT face=Arial color=#808080 size=2>SYS@test</FONT></A><FONT face=Arial color=#808080 size=2> SQL> declare<BR> 2 devtype varchar2(256);<BR> 3 done boolean;<BR> 4 begin<BR> 5 devtype:=sys.dbms_backup_restore.deviceallocate(type=>'',ident=>'t1');<BR> 6 sys.dbms_backup_restore.restoresetarchivedlog(destination=>'/u01/app/oracle/flash_recovery_area/TEST/archivelog/');<BR> 7 sys.dbms_backup_restore.restorearchivedlog(thread=>1,sequence=>133);<BR> 8 sys.dbms_backup_restore.restorebackuppiece(done=>done,handle=>'/u01/rman_back/TEST/TEST_20110809_48mjio41_1_1',params=>null);<BR> 9 sys.dbms_backup_restore.devicedeallocate;<BR> 10 end;<BR> 11 /</FONT></DIV>
<DIV><FONT face=Arial color=#808080 size=2>PL/SQL procedure successfully completed.</FONT></DIV></BLOCKQUOTE>
<DIV> </DIV>
<DIV> </DIV>
<DIV><FONT size=2>这样RESTORE的工作已经完成了,可以尝试mount数据库并恢复:</FONT></DIV>
<DIV> </DIV>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<DIV><A href="mailto:SYS@test" target=_blank><FONT face=Arial color=#808080 size=2>SYS@test</FONT></A><FONT face=Arial color=#808080 size=2> SQL> alter database mount;</FONT></DIV>
<DIV><FONT face=Arial color=#808080 size=2>Database altered.</FONT></DIV>
<DIV><A href="mailto:SYS@test" target=_blank><FONT face=Arial color=#808080 size=2>SYS@test</FONT></A><FONT face=Arial color=#808080 size=2> SQL> recover database using backup controlfile until cancel<BR>ORA-00279: change 11544987 generated at 08/09/2011 15:41:40 needed for thread 1<BR>ORA-00289: suggestion :<BR>/u01/app/oracle/flash_recovery_area/TEST/archivelog/2011_08_09/o1_mf_1_133_%u_.a<BR>rc<BR>ORA-00280: change 11544987 for thread 1 is in sequence #133</FONT></DIV>
<DIV><BR><FONT face=Arial color=#808080 size=2>Specify log: {<RET>=suggested | filename | AUTO | CANCEL}<BR>cancel<BR>Media recovery cancelled.<BR><BR></FONT><A href="mailto:SYS@test" target=_blank><FONT face=Arial color=#808080 size=2>SYS@test</FONT></A><FONT face=Arial color=#808080 size=2> SQL> alter database open resetlogs;</FONT></DIV>
<DIV><FONT face=Arial color=#808080 size=2>Database altered.<BR></FONT></DIV></BLOCKQUOTE>
<DIV><FONT face=宋体 size=2>这样整个使用dbms_backup_restore来做数据库恢复的过程就完成了。然而个人感觉真正的实战中应该不会这样用,因为1)既然备份集里面用控制文件的备份,为何不直接使用retore controlfile from “...”?2)使用dbms_backup_restore来恢复数据文件可比restore database / datafile 来的麻烦多了。 </FONT></DIV>
<DIV><FONT face=宋体 size=2></FONT> </DIV>
<DIV><FONT face=宋体 size=2>但当没有任何控制文件的备份时,dbms_backup_restore还是很有用的。思路应该是通过dbms_backup_restore恢复数据文件,然后手工方式创建控制文件,使用catalog将备份集catalog进控制文件,这样用于恢复数据库的archivelog的备份也可catalog进来。假如archivelog也没有,那么只能设定参数,允许在不一致的状态打开数据库了。有机会还是要找时间测试一下。</FONT></DIV>
<DIV><FONT face=宋体 size=2></FONT> </DIV>
<DIV><FONT face=宋体 size=2>下面将catalog的几个尝用命令摘抄如下:</FONT></DIV>
<DIV><FONT face=宋体 size=2>(摘自</FONT><A href="http://www.ningoo.net/html/2007/oracle10g_rman_catalog_command.html" target=_blank><FONT face=宋体 size=2>http://www.ningoo.net/html/2007/oracle10g_rman_catalog_command.html</FONT></A><FONT face=宋体 size=2>)</FONT></DIV>
<DIV>
<P><FONT face=宋体 size=2>扫描备份片<BR></FONT><BR><FONT size=2><FONT color=#808080><FONT face=Arial>CATALOG BACKUPPIECE ‘?/oradata/01dmsbj4_1_1.bcp’;<BR></FONT></FONT></FONT></P>
<P><FONT face=宋体 size=2>扫描归档日志<BR></FONT><BR><FONT face=Arial><FONT color=#808080><FONT size=2>CATALOG ARCHIVELOG ‘?/oradata/archive1_30.dbf’, ‘?/oradata/archive1_31.dbf’;<BR></FONT></FONT></FONT></P>
<P><FONT size=2>扫描数据文件拷贝,并且将其做为增量备份的level 0<BR></FONT><BR><FONT face=Arial color=#808080 size=2>CATALOG DATAFILECOPY ‘?/oradata/users01.bak’ LEVEL 0;<BR></FONT></P>
<P><FONT size=2>扫描控制文件拷贝<BR><BR></FONT><FONT face=Arial><FONT color=#808080><FONT size=2>CATALOG CONTROLFILECOPY ‘controlfilecopy.ctl’<BR></FONT></FONT></FONT></P>
<P><FONT size=2>扫描整个目录,如果备份片或者归档日志文件太多,可以放到一个目录中,一次性扫描就行<BR><BR></FONT><FONT face=Arial color=#808080 size=2>CATALOG START WITH ‘/tmp/arch_logs’;<BR></FONT></P>
<P><FONT size=2>扫描闪回恢复区<BR></FONT><BR><FONT face=Arial><FONT color=#808080><FONT size=2>CATALOG RECOVERY AREA NOPROMPT;<BR></FONT></FONT></FONT></P></DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
页:
[1]