合 rman全量+增量恢复报错ORA-01152: file 1 was not restored from a sufficiently old backup
Tags: Oracle故障处理备份恢复rman增量备份ORA-01152
现象
rman在做完增量恢复操作后,执行“alter database open resetlogs;”,报错:ORA-01152: file 1 was not restored from a sufficiently old backup,如下:
1 2 3 4 5 6 7 8 9 | RMAN> alter database open resetlogs; using target database control file instead of recovery catalog RMAN-00571: =========================================================== RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =========================================================== RMAN-03002: failure of alter db command at 02/16/2022 10:46:26 ORA-01152: file 1 was not restored from a sufficiently old backup ORA-01110: data file 1: '/u01/app/oracle/oradata/LHR11G/system01.dbf' |
恢复场景:首先rman全备,然后过了2天,删除这2天的归档,然后做增量备份,然后在异机直接做recover操作的时候报错了。
原因
由于controlfile里所记录的scn与datafile里的scn不一致。
模拟
IP | 版本 | 数据库名 | 归档 | 角色 |
---|---|---|---|---|
172.17.0.2 | 11.2.0.4 | LHR11G | Y | 源端 |
172.17.0.3 | 11.2.0.4 | LHR11G | Y | 目标端 |
环境准备:
1 2 3 4 5 6 7 | -- 源库 docker run -itd --name lhroratest -h lhroratest \ --privileged=true lhrbest/oracle_11g_ee_lhr_11.2.0.4:2.0 init -- 目标库 docker run -itd --name lhroratest2 -h lhroratest2 \ --privileged=true lhrbest/oracle_11g_ee_lhr_11.2.0.4:2.0 init |
源库做全备
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | alter database enable block change tracking using file '/home/oracle/lhr11g.bct'; rm -rf /home/oracle/bk/* CROSSCHECK backupset ; delete noprompt backupset ; delete noprompt archivelog all; CONFIGURE DEVICE TYPE DISK PARALLELISM 2 BACKUP TYPE TO BACKUPSET; run { backup INCREMENTAL LEVEL 0 as compressed backupset database format '/home/oracle/bk/%d%U.full'; sql 'alter system archive log current'; backup as compressed backupset archivelog from time 'sysdate-10/24/60' format '/home/oracle/bk/%d%U.arc'; backup current controlfile format '/home/oracle/bk/%d%U.ctl'; backup spfile format '/home/oracle/bk/spfile_%d_%U.ora'; } scp /home/oracle/bk/* oracle@172.17.0.3:/home/oracle/bk/ |
注意这里的归档日志的备份“sysdate-10/24/60”,表示只备份最近10分钟的归档,因为我这个库比较小,所以10分钟可以备份完成。若库比较大,备份需要2小时,那么建议这里的时间调大一点,即需要备份从开始全备到全备结束之间的所有归档。
目标库全量恢复
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | startup force mount restrict; drop database; rm -rf /u01/app/oracle/flash_recovery_area/LHR11G/archivelog/* mkdir -p /u01/app/oracle/flash_recovery_area/LHR11G/ rman target / startup force nomount restore spfile from '/home/oracle/bk/spfile_LHR11G_2m0lvkmi_1_1.ora'; startup force nomount restore controlfile from '/home/oracle/bk/LHR11G3b0lvlj3_1_1.ctl'; alter database mount; restore database; recover database; |
全量恢复的时候,需要注意,删除之前库已经产生的归档文件。
在做完recover database后需要注意归档号是多少。
源库做增量备份
这里为了模拟实验,多次切换归档文件后,再删除这些产生的归档文件。