ORACLE DATAGUARD技术是一个常用的数据保护机制,在DATAGUARD运行过程中,遇到异常导致备机不同步,而主库的归档日志也被清理,此时出现GAP,无法同步;就需要人工处理;对于小型数据库重新全量同步数据即可,但是对于大型数据库,通常建议是增量方式恢复,减少时间精力、网络、磁盘等资源的消耗,如下为一个RAC环境的备机增量恢复的过程:
1.查询备库SCN号及主备库数据文件信息
备库操作,备库取消归档应用,查询最小SCN号
SQL> select min(checkpoint_change#) from v$datafile_header
where file# not in (select file# from v$datafile where enabled = 'READ ONLY');
MIN(F.FHSCN)
75039049863
生产
SQL> select to_char(current_scn) from v$database;
SQL> select min(fhscn) from x$kcvfh;
SQL> select min(f.fhscn) from xkcvfh f,vdatafile d where f.hxfil=d.file# and d.enabled!='READ ONLY';
备库----------------------------------------------
SQL> select to_char(current_scn) from v$database;
SQL> select min(fhscn) from x$kcvfh;
SQL> select min(f.fhscn) from xkcvfh f,vdatafile d where f.hxfil=d.file# and d.enabled!='READ ONLY';
查完后查看最小值
查询主备库数据文件个数是否一致并记录备库数据文件路径
select file#, name from v$datafile order by file# ;
- 主库做RMAN的增量备份,scn号为查询出来的备库最小scn号
oracle@his01 rmanbak\]$ cat rman.sh #!/bin/bash # BACKUP_PATH=/backup/rman_backup/ # mkdir $BACKUP_PATH source /home/oracle/.bash_profile rman target / \<\< EOF run{ allocate channel d1 type disk; allocate channel d2 type disk; backup as compressed backupset datafile 60,61 format '/home/oracle/zlback/datafile_%U.bak' tag 'datafile';------若主库比备库多两个数据文件,执行这条命令。 BACKUP as compressed INCREMENTAL FROM SCN 75039049863 DATABASE FORMAT '/backup/hisbak/rmanbak/ForStandby_%U' tag 'FORSTANDBY';-----as compressed 为压缩参数 release channel d1; release channel d2; } 3.将备份好的备份集scp到备库 \[oracle@his01 rmanbak\]$ scp ForStandby_i\* 192.168.10.35:/rmanbak/ 4.备库注册备份集 RMAN\> catalog start with '/rmanbak/'; using target database control file instead of recovery catalog searching for all files that match the pattern /rmanbak/ List of Files Unknown to the Database ===================================== File Name: /rmanbak/ForStandby_ic3kr2p0_38476_1_1 File Name: /rmanbak/ForStandby_ib3kr1ok_38475_1_1 File Name: /rmanbak/ForStandby_ia3kr1ok_38474_1_1 Do you really want to catalog the above files (enter YES or NO)? yes cataloging files... cataloging done List of Cataloged Files ======================= File Name: /rmanbak/ForStandby_ic3kr2p0_38476_1_1 File Name: /rmanbak/ForStandby_ib3kr1ok_38475_1_1 File Name: /rmanbak/ForStandby_ia3kr1ok_38474_1_1 5.使用增量备份集恢复备库 RMAN\> recover database noredo; Starting recover at 20-MAR-2025 20:14:28 allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=304 instance=hisdb1 device type=DISK allocated channel: ORA_DISK_2 channel ORA_DISK_2: SID=908 instance=hisdb1 device type=DISK allocated channel: ORA_DISK_3 channel ORA_DISK_3: SID=2570 instance=hisdb1 device type=DISK allocated channel: ORA_DISK_4 channel ORA_DISK_4: SID=3174 instance=hisdb1 device type=DISK channel ORA_DISK_1: starting incremental datafile backup set restore channel ORA_DISK_1: specifying datafile(s) to restore from backup set destination for restore of datafile 00001: +DATADG/hisdb/datafile/system01.dbf destination for restore of datafile 00002: +DATADG/hisdb/datafile/sysaux01.dbf ...... destination for restore of datafile 00074: +DATADG/hisdb/datafile/portal_his.366.1186787373 destination for restore of datafile 00077: +DATADG/hisdb/datafile/portal_his.369.1186787431 destination for restore of datafile 00080: +DATADG/hisdb/datafile/undotbs2.396.1195663885 channel ORA_DISK_1: reading from backup piece /rmanbak/ForStandby_ia3kr1ok_38474_1_1 channel ORA_DISK_2: starting incremental datafile backup set restore channel ORA_DISK_2: specifying datafile(s) to restore from backup set destination for restore of datafile 00008: +DATADG/hisdb/datafile/sysaux04.dbf destination for restore of datafile 00009: +DATADG/hisdb/datafile/portal01.dbf destination for restore of datafile 00013: +DATADG/hisdb/datafile/portal_his04.dbf destination for restore of datafile 00015: +DATADG/hisdb/datafile/portal_his06.dbf destination for restore of datafile 00017: +DATADG/hisdb/datafile/portal_his08.dbf destination for restore of datafile 00019: +DATADG/hisdb/datafile/portal_his11.dbf destination for restore of datafile 00021: +DATADG/hisdb/datafile/portal_his13.dbf destination for restore of datafile 00024: +DATADG/hisdb/datafile/portal_his16.dbf destination for restore of datafile 00027: +DATADG/hisdb/datafile/portal_his10.dbf ...... destination for restore of datafile 00075: +DATADG/hisdb/datafile/portal_his.367.1186787375 destination for restore of datafile 00076: +DATADG/hisdb/datafile/portal_his.368.1186787429 destination for restore of datafile 00078: +DATADG/hisdb/datafile/portal_his_2025_0208.dbf destination for restore of datafile 00079: +DATADG/hisdb/datafile/undotbs1.395.1195663875 channel ORA_DISK_2: reading from backup piece /rmanbak/ForStandby_ib3kr1ok_38475_1_1 channel ORA_DISK_2: piece handle=/rmanbak/ForStandby_ib3kr1ok_38475_1_1 tag=FORSTANDBY channel ORA_DISK_2: restored backup piece 1 channel ORA_DISK_2: restore complete, elapsed time: 00:20:46 channel ORA_DISK_1: piece handle=/rmanbak/ForStandby_ia3kr1ok_38474_1_1 tag=FORSTANDBY channel ORA_DISK_1: restored backup piece 1 channel ORA_DISK_1: restore complete, elapsed time: 00:28:16 Finished recover at 20-MAR-2025 20:42:46 RMAN\> exit 恢复多出来的数据文件 RMAN\> catalog backuppiece '/datafile_%U.bak'; RMAN\> restore datafile 60,61; 6.恢复控制文件 SYS@hisdb1\>shutdown immediate ORA-01109: database not open Database dismounted. ORACLE instance shut down. SYS@hisdb1\>startup nomount ORACLE instance started. Total System Global Area 8.1068E+10 bytes Fixed Size 37218536 bytes Variable Size 1.3422E+10 bytes Database Buffers 6.7377E+10 bytes Redo Buffers 231215104 bytes RMAN\> restore standby controlfile from '/rmanbak/ForStandby_ic3kr2p0_38476_1_1'; Starting restore at 20-MAR-2025 21:38:01 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=908 instance=hisdb1 device type=DISK channel ORA_DISK_1: restoring control file channel ORA_DISK_1: restore complete, elapsed time: 00:00:02 output file name=+DATADG/HISDB/CONTROLFILE/current.267.1196261129 Finished restore at 20-MAR-2025 21:38:03 7.catalog datafilecopy hisdg01:/home/oracle$rman target / Recovery Manager: Release 19.0.0.0.0 - Production on Thu Mar 20 21:50:41 2025 Version 19.16.0.0.0 Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved. connected to target database: HISDB (DBID=1936455435, not open) RMAN\> catalog datafilecopy '+DATADG/hisdb/datafile/LOGMINER_TBS.261.1145745771'; catalog datafilecopy '+DATADG/hisdb/datafile/LOGMINER_TBS.397.1196189189'; catalog datafilecopy '+DATADG/hisdb/datafile/PORTAL.278.1145744523'; catalog datafilecopy '+DATADG/hisdb/datafile/PORTAL.297.1145740519'; catalog datafilecopy '+DATADG/hisdb/datafile/PORTAL.401.1196189295'; catalog datafilecopy '+DATADG/hisdb/datafile/PORTAL_HIS.256.1152206447'; catalog datafilecopy '+DATADG/hisdb/datafile/PORTAL_HIS.257.1145737777'; catalog datafilecopy '+DATADG/hisdb/datafile/PORTAL_HIS.260.1145737775'; catalog datafilecopy '+DATADG/hisdb/datafile/PORTAL_HIS.262.1145737777'; ...... catalog datafilecopy '+DATADG/hisdb/datafile/PORTAL_HIS.347.1184327183'; catalog datafilecopy '+DATADG/hisdb/datafile/PORTAL_HIS.348.1184327185'; catalog datafilecopy '+DATADG/hisdb/datafile/PORTAL_HIS.349.1184327263'; catalog datafilecopy '+DATADG/hisdb/datafile/PORTAL_HIS.350.1184327263'; catalog datafilecopy '+DATADG/hisdb/datafile/PORTAL_HIS.351.1184327263'; catalog datafilecusing target database control file instead of recovery catalog cataloged datafile copy datafile copy file name=+DATADG/hisdb/datafile/logminer_tbs.261.1145745771 RECID=11 STAMP=1196286653 ...... catalog datafilecopy '+DATADG/hisdb/datafile/portal_his09.dbf' cataloged datafile copy datafile copy file name=+DATADG/hisdb/datafile/portal_his.394.1192550351 RECID=88 STAMP=1196286659 RMAN\> 8.SWITCH DATABASE TO COPY; RMAN\> SWITCH DATABASE TO COPY; datafile 1 switched to datafile copy "+DATADG/hisdb/datafile/system01.dbf" datafile 2 switched to datafile copy "+DATADG/hisdb/datafile/sysaux01.dbf" datafile 3 switched to datafile copy "+DATADG/hisdb/datafile/undotbs01.dbf" ........................ datafile 79 switched to datafile copy "+DATADG/hisdb/datafile/undotbs1.395.1195663875" datafile 80 switched to datafile copy "+DATADG/hisdb/datafile/undotbs2.396.1195663885" RMAN\> 9.开启MRP进程 SYS@hisdb1\>ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT USING CURRENT LOGFILE; Database altered. SYS@hisdb1\>SYS@hisdb1\> PROCESS STATUS THREAD# SEQUENCE# BLOCK# --------- ------------ ---------- ---------- ---------- ARCH CLOSING 2 52552 36864 ARCH CLOSING 1 59424 51200 RFS IDLE 1 59425 24784 RFS IDLE 2 52553 44835 RFS RECEIVING 2 52265 126977 RFS RECEIVING 2 52264 57345 RFS RECEIVING 2 52263 436225 RFS RECEIVING 2 52335 14337 RFS RECEIVING 2 52334 221185 RFS RECEIVING 2 52333 348161 MRP0 APPLYING_LOG 2 52262 191805 11 rows selected. 10.第一次增量备份未备份至最新(可通过查找数据文件scn号找出最小scn号) SYS@hisdb1\>select file#,TO_CHAR(checkpoint_change#, 'FM999999999999999999999999') from v$datafile_header; FILE# TO_CHAR(CHECKPOINT_CHANGE ---------- ------------------------- 1 75578048600 2 75578048600 3 75578048600 4 75578048600 5 75578048600 6 75578048600 7 75578048600 8 75578048600 9 75578048600 10 75578048600 11 75578048600