数据库恢复报RMAN-06026,尝试dbms_backup_restore包进行恢复

今天在帮一个同事恢复数据库是碰到一个奇怪的问题,备份集明明是正常的,就是无法通过rman恢复,提示no backup or copy of datafile 10 found to restore

可以用list backup看到备份集:

BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
38 Full 581.45M DISK 00:01:31 02-AUG-11
BP Key: 38 Status: AVAILABLE Compressed: NO Tag: TAG20110802T112000
Piece Name: /tmp/backup/full_1emivq31_1_1.bak
List of Datafiles in backup set 38
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
1 Full 2447463 02-AUG-11 /home/oracle/oracle/oradata/ora1/system01.dbf
3 Full 2447463 02-AUG-11 /home/oracle/oracle/oradata/ora1/sysaux01.dbf
4 Full 2447463 02-AUG-11 /home/oracle/oracle/oradata/ora1/users01.dbf
6 Full 2447463 02-AUG-11 /home/oracle/oracle/oradata/ora1/u22.dbf
7 Full 2447463 02-AUG-11 /home/oracle/oracle/oradata/ora1/u44.dbf
10 Full 2447463 02-AUG-11 /home/oracle/oracle/oradata/ora1/undo01.dbf

BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
39 Full 142.00K DISK 00:00:03 02-AUG-11
BP Key: 39 Status: AVAILABLE Compressed: NO Tag: TAG20110802T112000
Piece Name: /tmp/backup/full_1fmivq60_1_1.bak
List of Datafiles in backup set 39
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
8 Full 2447517 02-AUG-11 /home/oracle/oracle/oradata/ora1/u12.dbf
9 Full 2447517 02-AUG-11 /home/oracle/oracle/oradata/ora1/u13.dbf

BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
40 Full 5.86M DISK 00:00:02 02-AUG-11
BP Key: 40 Status: AVAILABLE Compressed: NO Tag: TAG20110802T112000
Piece Name: /tmp/backup/full_1gmivq64_1_1.bak
Control File Included: Ckp SCN: 2447544 Ckp time: 02-AUG-11
SPFILE Included: Modification time: 02-AUG-11

而且在/tmp/backup目录先备份文件也是真实存在的,
SQL> host ls -l /tmp/backup
total 602172
-rw-r--r-- 1 oracle dba 609697792 Oct 17 09:56 full_1emivq31_1_1.bak
-rw-r--r-- 1 oracle dba 147456 Oct 17 09:56 full_1fmivq60_1_1.bak
-rw-r--r-- 1 oracle dba 6160384 Oct 17 09:56 full_1gmivq64_1_1.bak
就是恢复的时候提示找不到数据文件的备份集.

RMAN> restore database;

Starting restore at 17-OCT-11
using channel ORA_DISK_1

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 10/17/2011 09:56:21
RMAN-06026: some targets not found - aborting restore
RMAN-06023: no backup or copy of datafile 10 found to restore
RMAN-06023: no backup or copy of datafile 9 found to restore
RMAN-06023: no backup or copy of datafile 8 found to restore
RMAN-06023: no backup or copy of datafile 7 found to restore
RMAN-06023: no backup or copy of datafile 6 found to restore
RMAN-06023: no backup or copy of datafile 4 found to restore
RMAN-06023: no backup or copy of datafile 3 found to restore
RMAN-06023: no backup or copy of datafile 1 found to restore

通过dbms_backup_restore包尝试恢复数据,这个包很厉害,可以在数据库nomount下使用,用于从备份集中读取各类文件.
由于数据文件在不同的备份集中,需要执行两次dbms_backup_restore包
SQL>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=>08,toname=>'/home/oracle/oracle/oradata/ora1/u12.dbf');
sys.dbms_backup_restore.restoreDatafileTo(dfnumber=>09,toname=>'/home/oracle/oracle/oradata/ora1/u13.dbf');

sys.dbms_backup_restore.restoreBackupPiece(done=>done,handle=>'/tmp/backup/full_1fmivq60_1_1.bak', params=>null);
sys.dbms_backup_restore.deviceDeallocate;
END;
/

SQL>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=>01,toname=>'/home/oracle/oracle/oradata/ora1/system01.dbf');
sys.dbms_backup_restore.restoreDatafileTo(dfnumber=>03,toname=>'/home/oracle/oracle/oradata/ora1/sysaux01.dbf');
sys.dbms_backup_restore.restoreDatafileTo(dfnumber=>04,toname=>'/home/oracle/oracle/oradata/ora1/users01.dbf');
sys.dbms_backup_restore.restoreDatafileTo(dfnumber=>06,toname=>'/home/oracle/oracle/oradata/ora1/u22.dbf');
sys.dbms_backup_restore.restoreDatafileTo(dfnumber=>07,toname=>'/home/oracle/oracle/oradata/ora1/u44.dbf');
sys.dbms_backup_restore.restoreDatafileTo(dfnumber=>10,toname=>'/home/oracle/oracle/oradata/ora1/undo01.dbf');
sys.dbms_backup_restore.restoreBackupPiece(done=>done,handle=>'/tmp/backup/full_1emivq31_1_1.bak', params=>null);

sys.dbms_backup_restore.deviceDeallocate;
END;
/
每执行一次包,要退出重新连接数据库,不然会报ORA-19568: a device is already allocated to this session
这些结束后,通过rman执行recover database执行恢复,顺利完成.