DBMS_BACKUP_RESTORE.DBMS_BACKUP_RESTORE用于特殊情况下的恢复
一般如下:系统崩溃,rman使用控制文件,没有使用控制文件自动备份,现在仅有最后一次全备(备份中包括控制文件),以及其增量备份,规档备份.
通常这种情况下不能使用常规RMAN来恢复,因为此全备份中备份的控制文件中没有包含本次的备份信息,rman使用控制文件备份的时候是先备份控制文件
后备份其它信息
背景知识
在Oracle 816 以后的版本中,Oracle提供了一个包:DBMS_BACKUP_RESTORE.DBMS_BACKUP_RESTORE 包是由dbmsbkrs.sql 和 prvtbkrs.plb 这两个脚本创建的.catproc.sql 脚本运行后会调用这两个包.所以是每个数据库都有的这个包是Oracle服务器和操作系统之间IO操作的接口.由恢复管理器直接调用。而且据说这两个脚本的功能是内建到Oracle的一些库文件中的.
由此可见,我们可以在数据库 nomount 情况下调用这些package ,来达到我们的恢复目的。在dbmsbkrs.sql 和prvtbkrs.plb 这两个脚本中有详细的说明文档
关键的内容有:
FUNCTION deviceAllocate(
type IN varchar2 default NULL
,name IN varchar2 default NULL
,ident IN varchar2 default NULL
,noio IN boolean default FALSE
,params IN varchar2 default NULL )
RETURN varchar2;
PROCEDURE restoreControlfileTo(cfname IN varchar2);
PROCEDURE restoreDataFileTo( dfnumber IN binary_integer
,toname IN varchar2 default NULL);
SQL>startup force nomount;
SQL>
DECLARE
devtype varchar2(256);
done boolean;
BEGIN
--分配一个device channel,如果使用的操作系统文件,type就为空,如果是从磁带上恢复要用 "sbt_tape";
devtype:=sys.dbms_backup_restore.deviceAllocate(type=>'',ident=>'t1');
--指明开始restore
sys.dbms_backup_restore.restoreSetDatafile;
--指出待恢复文件目标存储位置;
sys.dbms_backup_restore.restoreControlfileTo(cfname=>'D:ORACLEORADATAFENETCONTROL01.CTL');
--sys.dbms_backup_restore.restoreControlfileTo(cfname=>'D:ORACLEORADATAFENETCONTROL02.CTL');
--sys.dbms_backup_restore.restoreControlfileTo(cfname=>'D:ORACLEORADATAFENETCONTROL03.CTL');
--指定备份集的位置
sys.dbms_backup_restore.restoreBackupPiece(done=>done,handle=>'D:ORA9I6095222264.RMAN', params=>null);
--释放通道
sys.dbms_backup_restore.deviceDeallocate;
END;
可以通过该语句得到file#和name的对应关系
select 'sys.dbms_backup_restore.restoreDatafileTo(dfnumber=>' || file# ||
',toname=>' ||chr(39)|| name ||chr(39) || ');',
'sys.dbms_backup_restore.applySetDatafile(dfnumber=>' || file# ||
',toname=>' ||chr(39)|| name ||chr(39) || ');'
from v$datafile;
在nomount状态下执行以下语句
恢复0级备份的语句
DECLARE
devtype varchar2(256);
done boolean;
BEGIN
devtype:=sys.dbms_backup_restore.deviceAllocate (type=>'',ident=>'t1');
sys.dbms_backup_restore.restoreSetDatafile;
sys.dbms_backup_restore.restoreDatafileTo(dfnumber=>1,toname=>'D:ORACLEORADATAFENETSYSTEM01.DBF');
sys.dbms_backup_restore.restoreDatafileTo(dfnumber=>2,toname=>'D:ORACLEORADATAFENETUNDOTBS01.DBF');
sys.dbms_backup_restore.restoreDatafileTo(dfnumber=>3,toname=>'D:ORACLEORADATAFENETCWMLITE01.DBF');
sys.dbms_backup_restore.restoreDatafileTo(dfnumber=>4,toname=>'D:ORACLEORADATAFENETDRSYS01.DBF');
sys.dbms_backup_restore.restoreDatafileTo(dfnumber=>5,toname=>'D:ORACLEORADATAFENETEXAMPLE01.DBF');
sys.dbms_backup_restore.restoreDatafileTo(dfnumber=>6,toname=>'D:ORACLEORADATAFENETINDX01.DBF');
sys.dbms_backup_restore.restoreDatafileTo(dfnumber=>7,toname=>'D:ORACLEORADATAFENETODM01.DBF');
sys.dbms_backup_restore.restoreDatafileTo(dfnumber=>8,toname=>'D:ORACLEORADATAFENETTOOLS01.DBF');
sys.dbms_backup_restore.restoreDatafileTo(dfnumber=>9,toname=>'D:ORACLEORADATAFENETUSERS01.DBF');
sys.dbms_backup_restore.restoreDatafileTo(dfnumber=>10,toname=>'D:ORACLEORADATAFENETXDB01.DBF');
sys.dbms_backup_restore.restoreDatafileTo(dfnumber=>11,toname=>'D:ORACLEORADATAFENETBJIC.ORA');
sys.dbms_backup_restore.restoreDatafileTo(dfnumber=>12,toname=>'D:ORACLEORADATAFENETPM_USERS.DBF');
sys.dbms_backup_restore.restoreBackupPiece(done=>done,handle=>'D:ORA9I6095222264.RMAN', params=>null);
sys.dbms_backup_restore.deviceDeallocate;
END;
恢复增量备份的语句
DECLARE
devtype varchar2(256);
done boolean;
BEGIN
devtype:=sys.dbms_backup_restore.deviceAllocate (type=>'',ident=>'t1');
sys.dbms_backup_restore.applySetDatafile;
sys.dbms_backup_restore.applySetDatafile(dfnumber=>1,toname=>'D:ORACLEORADATAFENETSYSTEM01.DBF');
sys.dbms_backup_restore.applySetDatafile(dfnumber=>2,toname=>'D:ORACLEORADATAFENETUNDOTBS01.DBF');
sys.dbms_backup_restore.applySetDatafile(dfnumber=>3,toname=>'D:ORACLEORADATAFENETCWMLITE01.DBF');
sys.dbms_backup_restore.applySetDatafile(dfnumber=>4,toname=>'D:ORACLEORADATAFENETDRSYS01.DBF');
sys.dbms_backup_restore.applySetDatafile(dfnumber=>5,toname=>'D:ORACLEORADATAFENETEXAMPLE01.DBF');
sys.dbms_backup_restore.applySetDatafile(dfnumber=>6,toname=>'D:ORACLEORADATAFENETINDX01.DBF');
sys.dbms_backup_restore.applySetDatafile(dfnumber=>7,toname=>'D:ORACLEORADATAFENETODM01.DBF');
sys.dbms_backup_restore.applySetDatafile(dfnumber=>8,toname=>'D:ORACLEORADATAFENETTOOLS01.DBF');
sys.dbms_backup_restore.applySetDatafile(dfnumber=>9,toname=>'D:ORACLEORADATAFENETUSERS01.DBF');
sys.dbms_backup_restore.applySetDatafile(dfnumber=>10,toname=>'D:ORACLEORADATAFENETXDB01.DBF');
sys.dbms_backup_restore.applySetDatafile(dfnumber=>11,toname=>'D:ORACLEORADATAFENETBJIC.ORA');
sys.dbms_backup_restore.applySetDatafile(dfnumber=>12,toname=>'D:ORACLEORADATAFENETPM_USERS.DBF');
sys.dbms_backup_restore.applyBackupPiece(done=>done,handle=>'D:ORA9I6095222264.L1', params=>null);
sys.dbms_backup_restore.deviceDeallocate
END;
恢复归档日志archive log文件
SQL>DECLARE
devtype varchar2(256);
done boolean;
BEGIN
devtype:=sys.dbms_backup_restore.deviceAllocate(type=>'',ident=>'T1');
sys.dbms_backup_restore.restoreSetArchivedLog;
sys.dbms_backup_restore.restoreArchivedLogRange;
sys.dbms_backup_restore.restoreBackupPiece(done=>done,handle=>'D:ORA9I6095222264.arc',params=>null);
sys.dbms_backup_restore.deviceDeallocate;
END
mount数据库
SQL> alter database mount;
恢复数据库到某一时间点
SQL> >recover database until time '2006-12-14 10:00:00';
启动数据库
SQL> alter database open resetlogs;
参考
1) DBA工作备忘录之三:rman备份,未使用catalog,控制文件丢失的解决办法
作者:Fenng
日期:03-July-2004
出处: http://www.dbanotes.net
版本:1.0
2)Control File中备份信息被覆盖情况下的数据库恢复案例