By 清欢 04月25日
场景:主库定时清理归档任务失败,报错备库仍需要这些归档来应用不可删除,以下是报错信息:
RMAN-08137: WARNING: archived log not deleted, needed for standby or upstream capture process
查看备库alert日志出现了gap,如下:
Fetching gap sequence in thread 1, gap sequence 26-31
正常情况下,只需将主库未传送的归档copy到备库手工注册即可,但发现主库也没有有这部分归档,所以需要对备库进行恢复。以下将使用增量备份来恢复故障备库。
强制删除归档RMAN> DELETE FORCE ARCHIVELOG UNTIL TIME 'SYSDATE-7';手工注册日志SQL> ALTER DATABASE REGISTER LOGFILE '<PATH>';
在备库上关闭日志应用
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;Database altered.
确定增量备份的起始scn号(取以下查询结果中的最小SCN)
SQL> SELECT CURRENT_SCN FROM V$DATABASE;CURRENT_SCN-----------917051SQL> SELECT MIN(FIRST_NONLOGGED_SCN) FROM V$DATAFILE WHERE FIRST_NONLOGGED_SCN>0;MIN(FIRST_NONLOGGED_SCN)------------------------SQL> SELECT FILE#, FIRST_NONLOGGED_SCN FROM V$DATAFILE WHERE FIRST_NONLOGGED_SCN > 0;no rows selected
创建增量备份
[oracle@odd backup]$ rman target /Recovery Manager: Release 11.2.0.3.0 - Production on Mon Mar 12 15:06:40 Copyright (c) 1982, , Oracle and/or its affiliates. All rights reserved.connected to target database: PROD (DBID=382173196)RMAN> backup format '/home/oracle/backup/sdb_incre_%U.bkp' incremental from scn 917051 database;Starting backup at 12-MAR-18using channel ORA_DISK_1backup will be obsolete on date 19-MAR-18archived logs will not be kept or backed upchannel ORA_DISK_1: starting full datafile backup setchannel ORA_DISK_1: specifying datafile(s) in backup setinput datafile file number=00001 name=/u01/app/oracle/oradata/PROD/system01.dbfinput datafile file number=00002 name=/u01/app/oracle/oradata/PROD/sysaux01.dbfinput datafile file number=00003 name=/u01/app/oracle/oradata/PROD/undotbs01.dbfinput datafile file number=00004 name=/u01/app/oracle/oradata/PROD/users01.dbfchannel ORA_DISK_1: starting piece 1 at 12-MAR-18channel ORA_DISK_1: finished piece 1 at 12-MAR-18piece handle=/home/oracle/backup/sdb_incre_07stjtq9_1_1.bkp tag=TAG0312T151209 comment=NONEchannel ORA_DISK_1: backup set complete, elapsed time: 00:00:35using channel ORA_DISK_1backup will be obsolete on date 19-MAR-18archived logs will not be kept or backed upchannel ORA_DISK_1: starting full datafile backup setchannel ORA_DISK_1: specifying datafile(s) in backup setincluding current control file in backup setchannel ORA_DISK_1: starting piece 1 at 12-MAR-18channel ORA_DISK_1: finished piece 1 at 12-MAR-18piece handle=/home/oracle/backup/sdb_incre_08stjtrc_1_1.bkp tag=TAG0312T151209 comment=NONEchannel ORA_DISK_1: backup set complete, elapsed time: 00:00:01Finished backup at 12-MAR-18RMAN> backup format '/home/oracle/backup/sdb_%U.ctl' current controlfile for standby;Starting backup at 12-MAR-18using channel ORA_DISK_1channel ORA_DISK_1: starting full datafile backup setchannel ORA_DISK_1: specifying datafile(s) in backup setincluding standby control file in backup setchannel ORA_DISK_1: starting piece 1 at 12-MAR-18channel ORA_DISK_1: finished piece 1 at 12-MAR-18piece handle=/home/oracle/backup/sdb_09stjtsc_1_1.ctl tag=TAG0312T151316 comment=NONEchannel ORA_DISK_1: backup set complete, elapsed time: 00:00:01Finished backup at 12-MAR-18
传输至备库
[oracle@odd backup]$ lssdb_09stjtsc_1_1.ctl sdb_incre_07stjtq9_1_1.bkp sdb_incre_08stjtrc_1_1.bkp[oracle@odd backup]$ scp * even:/home/oracle/backup/oracle@even's password: sdb_09stjtsc_1_1.ctl 100% 9632KB 9.4MB/s 00:00 sdb_incre_07stjtq9_1_1.bkp 100% 3344KB 3.3MB/s 00:01 sdb_incre_08stjtrc_1_1.bkp 100% 9632KB 9.4MB/s 00:00
手动注册备份文件记录入备库(如有catalog忽略此步骤,但主备备份目录需一致)
[oracle@even backup]$ rman target /Recovery Manager: Release 11.2.0.3.0 - Production on Mon Mar 12 15:15:10 Copyright (c) 1982, , Oracle and/or its affiliates. All rights reserved.connected to target database: PROD (DBID=382173196)RMAN> catalog start with '/home/oracle/backup';using target database control file instead of recovery catalogsearching for all files that match the pattern /home/oracle/backupList of Files Unknown to the Database=====================================File Name: /home/oracle/backup/sdb_incre_08stjtrc_1_1.bkpFile Name: /home/oracle/backup/sdb_09stjtsc_1_1.ctlFile Name: /home/oracle/backup/sdb_incre_07stjtq9_1_1.bkpDo you really want to catalog the above files (enter YES or NO)? YEScataloging files...cataloging doneList of Cataloged Files=======================File Name: /home/oracle/backup/sdb_incre_08stjtrc_1_1.bkpFile Name: /home/oracle/backup/sdb_09stjtsc_1_1.ctlFile Name: /home/oracle/backup/sdb_incre_07stjtq9_1_1.bkp
恢复备库控制文件
RMAN> startup force nomount;Oracle instance startedTotal System Global Area627732480 bytesFixed Size 1346756 bytesVariable Size499123004 bytesDatabase Buffers 121634816 bytesRedo Buffers 5627904 bytesRMAN> restore standby controlfile from '/home/oracle/backup/sdb_09stjtsc_1_1.ctl';Starting restore at 12-MAR-18allocated channel: ORA_DISK_1channel ORA_DISK_1: SID=19 device type=DISKchannel ORA_DISK_1: restoring control filechannel ORA_DISK_1: restore complete, elapsed time: 00:00:04output file name=/u01/app/oracle/oradata/SBDB/control01.ctloutput file name=/u01/app/oracle/fast_recovery_area/SBDB/control02.ctlFinished restore at 12-MAR-18
恢复数据库
RMAN> alter database mount;database mountedreleased channel: ORA_DISK_1RMAN> recover database noredo;Starting recover at 12-MAR-18Starting implicit crosscheck backup at 12-MAR-18allocated channel: ORA_DISK_1channel ORA_DISK_1: SID=55 device type=DISKCrosschecked 7 objectsFinished implicit crosscheck backup at 12-MAR-18Starting implicit crosscheck copy at 12-MAR-18using channel ORA_DISK_1Finished implicit crosscheck copy at 12-MAR-18searching for all files in the recovery areacataloging files...cataloging doneList of Cataloged Files=======================File Name: /u01/app/oracle/fast_recovery_area/SBDB/archivelog/_03_12/o1_mf_1_11_fbcoqrjw_.arcFile Name: /u01/app/oracle/fast_recovery_area/SBDB/archivelog/_03_12/o1_mf_1_24_fbd9fs6y_.arcFile Name: /u01/app/oracle/fast_recovery_area/SBDB/archivelog/_03_12/o1_mf_1_16_fbd8p0xs_.arcFile Name: /u01/app/oracle/fast_recovery_area/SBDB/archivelog/_03_12/o1_mf_1_21_fbd8p3gh_.arcFile Name: /u01/app/oracle/fast_recovery_area/SBDB/archivelog/_03_12/o1_mf_1_25_fbd9mgvl_.arcFile Name: /u01/app/oracle/fast_recovery_area/SBDB/archivelog/_03_12/o1_mf_1_14_fbcoqv8f_.arcFile Name: /u01/app/oracle/fast_recovery_area/SBDB/archivelog/_03_12/o1_mf_1_23_fbd9fs8g_.arcFile Name: /u01/app/oracle/fast_recovery_area/SBDB/archivelog/_03_12/o1_mf_1_20_fbd8p0xy_.arcFile Name: /u01/app/oracle/fast_recovery_area/SBDB/archivelog/_03_12/o1_mf_1_18_fbd8p0f3_.arcFile Name: /u01/app/oracle/fast_recovery_area/SBDB/archivelog/_03_12/o1_mf_1_10_fbcoqrjb_.arcFile Name: /u01/app/oracle/fast_recovery_area/SBDB/archivelog/_03_12/o1_mf_1_32_fbd9nbfw_.arcFile Name: /u01/app/oracle/fast_recovery_area/SBDB/archivelog/_03_12/o1_mf_1_9_fbcorw11_.arcFile Name: /u01/app/oracle/fast_recovery_area/SBDB/archivelog/_03_12/o1_mf_1_13_fbcoqrkc_.arcFile Name: /u01/app/oracle/fast_recovery_area/SBDB/archivelog/_03_12/o1_mf_1_19_fbd8p0f8_.arcFile Name: /u01/app/oracle/fast_recovery_area/SBDB/archivelog/_03_12/o1_mf_1_15_fbd8p0y3_.arcFile Name: /u01/app/oracle/fast_recovery_area/SBDB/archivelog/_03_12/o1_mf_1_22_fbd9fsgt_.arcFile Name: /u01/app/oracle/fast_recovery_area/SBDB/archivelog/_03_12/o1_mf_1_17_fbd8p113_.arcFile Name: /u01/app/oracle/fast_recovery_area/SBDB/archivelog/_03_12/o1_mf_1_12_fbcoqrk7_.arcusing channel ORA_DISK_1channel ORA_DISK_1: starting incremental datafile backup set restorechannel ORA_DISK_1: specifying datafile(s) to restore from backup setdestination for restore of datafile 00001: /u01/app/oracle/oradata/SBDB/system01.dbfdestination for restore of datafile 00002: /u01/app/oracle/oradata/SBDB/sysaux01.dbfdestination for restore of datafile 00003: /u01/app/oracle/oradata/SBDB/undotbs01.dbfdestination for restore of datafile 00004: /u01/app/oracle/oradata/SBDB/users01.dbfchannel ORA_DISK_1: reading from backup piece /home/oracle/backup/sdb_incre_07stjtq9_1_1.bkpchannel ORA_DISK_1: piece handle=/home/oracle/backup/sdb_incre_07stjtq9_1_1.bkp tag=TAG0312T151209channel ORA_DISK_1: restored backup piece 1channel ORA_DISK_1: restore complete, elapsed time: 00:00:03Finished recover at 12-MAR-18
打开数据库,开启日志实时应用
SQL> alter database open;Database altered.SQL> alter database recover managed standby database using current logfile disconnect;Database altered.