RMAN-06556: datafile 1 must be restored from backup older than SCN 1350000
这个问题在不完全恢复时经常出现,最近整理以前文档发现了以前自己遇到的两个案例
案例1
正常进行不完全恢复:
进行一次RMAN全备:
RMAN> backup as compressed backupset database;
Starting backup at 24-JUN-20
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=141 device type=DISK
channel ORA_DISK_1: starting compressed full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/app/oracle/oradata/prod/system01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/prod/sysaux01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/prod/example01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/prod/undotbs01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/prod/users01.dbf
channel ORA_DISK_1: starting piece 1 at 24-JUN-20
channel ORA_DISK_1: finished piece 1 at 24-JUN-20
piece handle=/u01/app/oracle/fast_recovery_area/PROD/backupset/2020_06_24/o1_mf_nnndf_TAG20200624T100732_hh5fc52y_.bkp tag=TAG20200624T100732 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:15
channel ORA_DISK_1: starting compressed full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 24-JUN-20
channel ORA_DISK_1: finished piece 1 at 24-JUN-20
piece handle=/u01/app/oracle/fast_recovery_area/PROD/backupset/2020_06_24/o1_mf_ncsnf_TAG20200624T100732_hh5ffkg8_.bkp tag=TAG20200624T100732 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 24-JUN-20
建立测试表:
SYS@prod>create table test tablespace users as select * from dba_objects;
Table created.
查看当前SCN:
SYS@prod>select current_scn from v$database;
CURRENT_SCN
\-----------
993592
模拟误修改数据:
SYS@prod>update test set object_id = 1;
86953 rows updated.
SYS@prod>truncate table test;
Table truncated.
单独备份4号数据文件:
RMAN> backup datafile 4;
Starting backup at 24-JUN-20
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=144 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00004 name=/u01/app/oracle/oradata/prod/users01.dbf
channel ORA_DISK_1: starting piece 1 at 24-JUN-20
channel ORA_DISK_1: finished piece 1 at 24-JUN-20
piece handle=/u01/app/oracle/fast_recovery_area/PROD/backupset/2020_06_24/o1_mf_nnndf_TAG20200624T101032_hh5fjs43_.bkp tag=TAG20200624T101032 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 24-JUN-20
关库执行恢复:
RMAN> shutdown immediate;
database closed
database dismounted
Oracle instance shut down
RMAN> startup mount;
connected to target database (not started)
Oracle instance started
database mounted
Total System Global Area 835104768 bytes
Fixed Size 2257840 bytes
Variable Size 490736720 bytes
Database Buffers 335544320 bytes
Redo Buffers 6565888 bytes
执行全库恢复:
RMAN> restore database;
Starting restore at 24-JUN-20
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=133 device type=DISK
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/prod/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/prod/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/prod/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/prod/example01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/PROD/backupset/2020_06_24/o1_mf_nnndf_TAG20200624T100732_hh5fc52y_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/PROD/backupset/2020_06_24/o1_mf_nnndf_TAG20200624T100732_hh5fc52y_.bkp tag=TAG20200624T100732
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:01:15
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/prod/users01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/PROD/backupset/2020_06_24/o1_mf_nnndf_TAG20200624T101032_hh5fjs43_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/PROD/backupset/2020_06_24/o1_mf_nnndf_TAG20200624T101032_hh5fjs43_.bkp tag=TAG20200624T101032
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 24-JUN-20
仔细观察可以发现,RMAN恢复时读取了两个备份集,第一个备份集为全库备份的备份集,又单独读取了第二个仅备份4号文件的备份集。
recover至指定SCN993592:
RMAN> recover database until scn 993592;
Starting recover at 24-JUN-20
using channel ORA_DISK_1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 06/24/2020 10:13:15
RMAN-06556: datafile 4 must be restored from backup older than SCN 993592
问题分析:
出现该问题的原因是由于执行restore时,RMAN自动4号数据文件最新的备份集,在进行不完全恢复时,需要使用目标SCN先前的备份+归档日志来进行不完全恢复至目标SCN,而该4号数据文件备份集的SCN是大于目标SCN993592, 所以会出现如下错误,
那么该如何避免这个问题呢,个人认为在这种情况下进行不完全恢复时,只能单独注册使用的全库备份备份集,那么如何删除控制文件中记录的备份集信息呢,没想到好办法,以本次案例说明:如果你执行delete backup等操作,那么操作系统上的4号数据文件的备份文件也会被删除,但是可以先将操作系统上4号数据文件的备份文件移动到其他位置,然后执行crosscheck backup 以及 delete expired backup,但是如果备份集过大,mv也十分耗时间。
案例2:
执行不完全恢复出现的错误:
RMAN>recover database until scn 1350000
…
…
RMAN-06556: datafile 1 must be restored from backup older than SCN 1350000
查看RMAN备份集SCN:
RMAN> list backup;
2 Full 1.15G DISK 00:00:21 28-SEP-20
BP Key: 2 Status: AVAILABLE Compressed: NO Tag: TAG20200928T220645
Piece Name: /home/oracle/rman/0bvbj0rl_1_1
List of Datafiles in backup set 2
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
1 Full 1350013 28-SEP-20 /oracle/app/oradata/proddg1/system01.dbf
2 Full 1350013 28-SEP-20 /oracle/app/oradata/proddg1/sysaux01.dbf
3 Full 1350013 28-SEP-20 /oracle/app/oradata/proddg1/undotbs01.dbf
4 Full 1350013 28-SEP-20 /oracle/app/oradata/proddg1/users01.dbf
5 Full 1350013 28-SEP-20 /oracle/app/oradata/proddg1/example01.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
3 Full 9.64M DISK 00:00:01 28-SEP-20
BP Key: 3 Status: AVAILABLE Compressed: NO Tag: TAG20200928T220645
Piece Name: /home/oracle/rman/0cvbj0se_1_1
SPFILE Included: Modification time: 28-SEP-20
SPFILE db_unique_name: PRODDG1
Control File Included: Ckp SCN: *****1350042***** Ckp time: 28-SEP-20
问题分析:
是由于在进行不完全恢复时,需要使用目标SCN先前的备份+归档日志来进行不完全恢复到目标SCN,出现上面的错误,是因为我们使用的备份集SCN是大于1350000,使用list backup可以看出备份集SCN为1350042是大于恢复的目标SCN(1350000),我们只能使用该备份集不完全恢复至大于SCN1350042时刻