54xw 发表于 2011-12-22 08:54

试用dbms_backup_restore包

<DIV><FONT face=宋体 size=2>本来想试一试10g RMAN里的catalog命令,于是我对现在测试库做了一个全库备份并将我将控制文件备份到文件:</FONT></DIV>
<DIV>&nbsp;</DIV>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<DIV><FONT face=Arial color=#808080 size=2>RMAN&gt; 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&gt; 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>&nbsp;</DIV>
<DIV><FONT face=宋体 color=#000000 size=2>我将所有控制文件,数据文件和重做日志全部删除。我假定我的备份集中没有控制文件,我尝试通过手工创建控制文件,然后使用catalog将备份集catalog到新建的日志文件中去。可是失败了,因为没有数据文件,无法手工创建控制文件:</FONT></DIV>
<DIV><FONT face=Arial color=#808080 size=1></FONT>&nbsp;</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.&nbsp; 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&gt; CREATE CONTROLFILE REUSE DATABASE "TEST" RESETLOGS&nbsp; ARCHIVELOG<BR>&nbsp; 2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MAXLOGFILES 16<BR>&nbsp; 3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MAXLOGMEMBERS 3<BR>&nbsp; 4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MAXDATAFILES 100<BR>&nbsp; 5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MAXINSTANCES 8<BR>&nbsp; 6&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MAXLOGHISTORY 292<BR>&nbsp; 7&nbsp; LOGFILE<BR>&nbsp; 8&nbsp;&nbsp;&nbsp; GROUP 1 '/u01/app/oracle/oradata/test/redo01.log'&nbsp; SIZE 50M,<BR>&nbsp; 9&nbsp;&nbsp;&nbsp; GROUP 2 '/u01/app/oracle/oradata/test/redo02.log'&nbsp; SIZE 50M,<BR>&nbsp;10&nbsp;&nbsp;&nbsp; GROUP 3 '/u01/app/oracle/oradata/test/redo03.log'&nbsp; SIZE 50M<BR>&nbsp;11&nbsp; -- STANDBY LOGFILE<BR>&nbsp;12&nbsp; DATAFILE<BR>&nbsp;13&nbsp;&nbsp;&nbsp; '/u01/app/oracle/oradata/test/system01.dbf',<BR>&nbsp;14&nbsp;&nbsp;&nbsp; '/u01/app/oracle/oradata/test/undotbs01.dbf',<BR>&nbsp;15&nbsp;&nbsp;&nbsp; '/u01/app/oracle/oradata/test/sysaux01.dbf',<BR>&nbsp;16&nbsp;&nbsp;&nbsp; '/u01/app/oracle/oradata/test/users01.dbf',<BR>&nbsp;17&nbsp;&nbsp;&nbsp; '/u01/app/oracle/oradata/test/test01.dbf',<BR>&nbsp;18&nbsp;&nbsp;&nbsp; '/u01/app/oracle/oradata/test/test02.dbf',<BR>&nbsp;19&nbsp;&nbsp;&nbsp; '/u01/app/oracle/product/10.2.0/dbs/t1_01.ora',<BR>&nbsp;20&nbsp;&nbsp;&nbsp; '/u01/app/oracle/product/10.2.0/dbs/undots02.ora'<BR>&nbsp;21&nbsp; CHARACTER SET AL32UTF8<BR>&nbsp;22&nbsp; ;<BR>CREATE CONTROLFILE REUSE DATABASE "TEST" RESETLOGS&nbsp; 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>&nbsp;</DIV>
<DIV><FONT size=2>看来必须先将数据文件恢复回来,在这种情况下,我尝试使用dbms_backup_restore包,先将数据文件恢复回来:</FONT></DIV>
<DIV>&nbsp;</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.&nbsp; 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&gt; declare<BR>&nbsp; 2&nbsp; devtype varchar2(256);<BR>&nbsp; 3&nbsp; done boolean;<BR>&nbsp; 4&nbsp; begin<BR>&nbsp; 5&nbsp; devtype:=sys.dbms_backup_restore.deviceallocate(type=&gt;'',ident=&gt;'t1');<BR>&nbsp; 6&nbsp; sys.dbms_backup_restore.restoresetdatafile;<BR>&nbsp; 7&nbsp; sys.dbms_backup_restore.restoredatafileto(dfnumber=&gt;01,toname=&gt;'/u01/app/oracle/oradata/test/system01.dbf');<BR>&nbsp; 8&nbsp; sys.dbms_backup_restore.restoredatafileto(dfnumber=&gt;03,toname=&gt;'/u01/app/oracle/oradata/test/sysaux01.dbf');<BR>&nbsp; 9&nbsp; sys.dbms_backup_restore.restoredatafileto(dfnumber=&gt;06,toname=&gt;'/u01/app/oracle/oradata/test/test02.dbf');<BR>&nbsp;10&nbsp; sys.dbms_backup_restore.restoredatafileto(dfnumber=&gt;07,toname=&gt;'/u01/app/oracle/product/10.2.0/dbs/t1_01.ora');<BR>&nbsp;11&nbsp; sys.dbms_backup_restore.restorebackuppiece(done=&gt;done,handle=&gt;'/u01/rman_back/TEST/TEST_20110809_47mjio1k_1_1',params=&gt;null);<BR>&nbsp;12&nbsp; sys.dbms_backup_restore.devicedeallocate;<BR>&nbsp;13&nbsp; end;<BR>&nbsp;14&nbsp; /</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&gt; declare<BR>&nbsp; 2&nbsp; devtype varchar2(256);<BR>&nbsp; 3&nbsp; done boolean;<BR>&nbsp; 4&nbsp; begin<BR>&nbsp; 5&nbsp; devtype:=sys.dbms_backup_restore.deviceallocate(type=&gt;'',ident=&gt;'t1');<BR>&nbsp; 6&nbsp; sys.dbms_backup_restore.restoresetdatafile;<BR>&nbsp; 7&nbsp; sys.dbms_backup_restore.restoredatafileto(dfnumber=&gt;04,toname=&gt;'/u01/app/oracle/oradata/test/users01.dbf');<BR>sys.dbms_backup_restore.restoredatafileto(dfnumber=&gt;02,toname=&gt;'/u01/app/oracle/oradata/test/undotbs01.dbf');<BR>sys.dbms_backup_restore.restoredatafileto(dfnumber=&gt;05,toname=&gt;'/u01/app/oracle/oradata/test/test01.&nbsp; 8&nbsp; dbf');<BR>sys.dbms_backup_restore.restoredatafileto(dfnumber=&gt;08,toname=&gt;'/u01/app/oracle/product/10.2.0/dbs/undots02.ora');<BR>sys.dbms_backup_restore.rest&nbsp; 9&nbsp; orebackuppiece(done=&gt;done,handle=&gt;'/u01/rman_back/TEST/TEST_20110809_46mjio1k_1_1',params=&gt;null);<BR>sys.dbms_backup_restore.devicedealloca 10&nbsp; te;<BR>end;<BR>/ 11&nbsp;&nbsp; 12&nbsp;&nbsp; 13&nbsp;&nbsp; 14</FONT></DIV>
<DIV><FONT face=Arial size=2>PL/SQL procedure successfully completed.</FONT></DIV></BLOCKQUOTE><FONT face=Arial>
<DIV><BR></FONT>&nbsp;</DIV></FONT>
<DIV><FONT size=2>注意:使用这个脚本必须知道每一个数文件与备份集的关系,不然会出错,错误代码忘记拷贝了。可能通过备份时的日志查看一一对应的关系。所以再次证明了保存好备份日志也是一件非常必要的事。</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>实验做到这里,本来打算手工重建控制文件的,然后使用catalog命令。但我并没有这样做,而是干脆把使用dbms_backup_restore包的实验做到底了。</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>恢复控制文件:</FONT></DIV>
<DIV>&nbsp;</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&gt; declare<BR>&nbsp; 2&nbsp; devtype varchar2(256);<BR>&nbsp; 3&nbsp; done boolean;<BR>&nbsp; 4&nbsp; begin<BR>&nbsp; 5&nbsp; devtype:=sys.dbms_backup_restore.deviceallocate(type=&gt;'',ident=&gt;'t1');<BR>&nbsp; 6&nbsp; sys.dbms_backup_restore.restoresetdatafile;<BR>&nbsp; 7&nbsp; sys.dbms_backup_restore.restoreControlfileTo (cfname=&gt;'/u01/app/oracle/oradata/test/control01.ctl');<BR>&nbsp; 8&nbsp; sys.dbms_backup_restore.restorebackuppiece(done=&gt;done,handle=&gt;'/u01/rman_back/TEST/c-2012049283-20110809-00',params=&gt;null);<BR>sys.dbms_backup_restore.devicedeallocate;<BR>end;<BR>/<BR>&nbsp; 9&nbsp;&nbsp; 10&nbsp;&nbsp; 11<BR>PL/SQL procedure successfully completed.<BR></FONT></DIV></BLOCKQUOTE>
<DIV>&nbsp;</DIV>
<DIV><FONT size=2>恢复归档日志:</FONT></DIV>
<DIV>&nbsp;</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&gt; declare<BR>&nbsp; 2&nbsp; devtype varchar2(256);<BR>&nbsp; 3&nbsp; done boolean;<BR>&nbsp; 4&nbsp; begin<BR>&nbsp; 5&nbsp; devtype:=sys.dbms_backup_restore.deviceallocate(type=&gt;'',ident=&gt;'t1');<BR>&nbsp; 6&nbsp; sys.dbms_backup_restore.restoresetarchivedlog(destination=&gt;'/u01/app/oracle/flash_recovery_area/TEST/archivelog/');<BR>&nbsp; 7&nbsp; sys.dbms_backup_restore.restorearchivedlog(thread=&gt;1,sequence=&gt;133);<BR>&nbsp; 8&nbsp; sys.dbms_backup_restore.restorebackuppiece(done=&gt;done,handle=&gt;'/u01/rman_back/TEST/TEST_20110809_48mjio41_1_1',params=&gt;null);<BR>&nbsp; 9&nbsp; sys.dbms_backup_restore.devicedeallocate;<BR>&nbsp;10&nbsp; end;<BR>&nbsp;11&nbsp; /</FONT></DIV>
<DIV><FONT face=Arial color=#808080 size=2>PL/SQL procedure successfully completed.</FONT></DIV></BLOCKQUOTE>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=2>这样RESTORE的工作已经完成了,可以尝试mount数据库并恢复:</FONT></DIV>
<DIV>&nbsp;</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&gt; 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&gt; 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: {&lt;RET&gt;=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&gt; 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>&nbsp;</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>&nbsp;</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>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
页: [1]
查看完整版本: 试用dbms_backup_restore包