oracle 11g ADG GAP修復
阿新 • • 發佈:2022-05-18
一、模擬產生GAP 1.備庫停止DG同步程序: SQL> archive log list Database log mode Archive Mode Automatic archival Enabled Archive destination /oracle/archive Oldest online log sequence 72 Next log sequence to archive 0 Current log sequence 74 SQL> alter database recover managed standby database cancel; Database altered. SQL> SQL> shutdown immediate Database closed. Database dismounted. ORACLE instance shut down. 2.主庫切換多次歸檔: SQL> archive log list Database log mode Archive Mode Automatic archival Enabled Archive destination /oracle/archive Oldest online log sequence 72 Next log sequence to archive 74 Current log sequence 74 SQL> SQL> SQL> SQL> alter system switch logfile; System altered. SQL> / System altered. SQL> / System altered. SQL> / System altered. SQL> archive log list Database log mode Archive Mode Automatic archival Enabled Archive destination /oracle/archive Oldest online log sequence 76 Next log sequence to archive 78 Current log sequence 78 3.主庫刪除/移動最近幾個歸檔日誌: [oracle@dgdb1 ~]$ cd /oracle/archive/ [oracle@dgdb1 archive]$ mv 1_74_1024761634.dbf 1_75_1024761634.dbf 1_76_1024761634.dbf 1_77_1024761634.dbf /home/oracle 4.備庫開啟同步程序: SQL> alter database recover managed standby database using current logfile disconnect from session; Database altered. 5.檢視GAP: SQL> select * from v$archive_gap; THREAD# LOW_SEQUENCE# HIGH_SEQUENCE# ---------- ------------- -------------- 1 73 77 SQL> SELECT max(sequence#) from v$archived_log where applied='YES'; MAX(SEQUENCE#) -------------- 73 丟失了74-77四個日誌 二、恢復備庫: 1.在主庫上建立一個備庫的控制檔案: SQL> alter database create standby controlfile as '/home/oracle/standby.ctl'; Database altered. 2.以備庫的當前SCN號為起點,在主庫上做一個增量備份 查詢備庫當前SCN: SQL> select current_scn from v$database; CURRENT_SCN ----------- 1248633 確認主備GAP期間是否新增資料檔案: SQL> select file# from v$datafile where creation_change# > =1248633; 如果存在新增資料檔案,備庫恢復時需要先restore新新增的資料檔案。 主庫根據備庫scn號進行增量備份: RMAN> run{ allocate channel c1 type disk; allocate channel c2 type disk; backup INCREMENTAL from scn 1248633 database format '/home//oracle/incre_%U'; release channel c1; release channel c2; } 2> 3> 4> 5> 6> 7> allocated channel: c1 channel c1: SID=52 device type=DISK allocated channel: c2 channel c2: SID=54 device type=DISK Starting backup at 10-MAY-22 channel c1: starting full datafile backup set channel c1: specifying datafile(s) in backup set input datafile file number=00001 name=/u01/app/oracle/oradata/rmanpri/system01.dbf input datafile file number=00004 name=/u01/app/oracle/oradata/rmanpri/users01.dbf channel c1: starting piece 1 at 10-MAY-22 channel c2: starting full datafile backup set channel c2: specifying datafile(s) in backup set input datafile file number=00002 name=/u01/app/oracle/oradata/rmanpri/sysaux01.dbf input datafile file number=00003 name=/u01/app/oracle/oradata/rmanpri/undotbs01.dbf channel c2: starting piece 1 at 10-MAY-22 channel c2: finished piece 1 at 10-MAY-22 piece handle=/home/oracle/incre_0u0t5vb9_1_1 tag=TAG20220510T185433 comment=NONE channel c2: backup set complete, elapsed time: 00:01:06 channel c2: starting full datafile backup set channel c2: specifying datafile(s) in backup set including current control file in backup set channel c2: starting piece 1 at 10-MAY-22 channel c2: finished piece 1 at 10-MAY-22 piece handle=/home/oracle/incre_0v0t5vdb_1_1 tag=TAG20220510T185433 comment=NONE channel c2: backup set complete, elapsed time: 00:00:01 channel c1: finished piece 1 at 10-MAY-22 piece handle=/home/oracle/incre_0t0t5vb9_1_1 tag=TAG20220510T185433 comment=NONE channel c1: backup set complete, elapsed time: 00:01:10 Finished backup at 10-MAY-22 released channel: c1 released channel: c2 [oracle@dgdb1 trace]$ ll /home/oracle/ total 20404 -rw-r----- 1 oracle oinstall 221184 May 10 18:55 incre_0t0t5vb9_1_1 -rw-r----- 1 oracle oinstall 344064 May 10 18:55 incre_0u0t5vb9_1_1 -rw-r----- 1 oracle oinstall 10092544 May 10 18:55 incre_0v0t5vdb_1_1 -rw-r----- 1 oracle oinstall 10043392 May 10 18:48 standby.ctl 將增量備份和控制檔案拷貝到備庫上: [oracle@dgdb1 trace]$ scp /home/oracle/incre_0* dgdb2:/home/oracle oracle@dgdb2's password: incre_0t0t5vb9_1_1 100% 216KB 216.0KB/s 00:00 incre_0u0t5vb9_1_1 100% 336KB 336.0KB/s 00:00 incre_0v0t5vdb_1_1 100% 9856KB 9.6MB/s 00:01 [oracle@dgdb1 trace]$ scp /home/oracle/standby.ctl dgdb2:/home/oracle oracle@dgdb2's password: standby.ctl [oracle@dgdb2 trace]$ ll /home/oracle/ total 20216 -rw-r----- 1 oracle oinstall 221184 May 11 17:49 incre_0t0t5vb9_1_1 -rw-r----- 1 oracle oinstall 344064 May 11 17:49 incre_0u0t5vb9_1_1 -rw-r----- 1 oracle oinstall 10092544 May 11 17:49 incre_0v0t5vdb_1_1 -rw-r----- 1 oracle oinstall 10043392 May 11 17:50 standby.ctl 備庫關閉資料庫例項,開啟至nomount狀態: SQL> alter database recover managed standby database cancel; Database altered. SQL> shutdown immediate Database closed. Database dismounted. ORACLE instance shut down. SQL> startup nomount ORACLE instance started. Total System Global Area 584568832 bytes Fixed Size 2255432 bytes Variable Size 226493880 bytes Database Buffers 352321536 bytes Redo Buffers 3497984 bytes 備庫恢復新的控制檔案: RMAN> restore controlfile from '/home/oracle/standby.ctl'; Starting restore at 11-MAY-22 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=19 device type=DISK channel ORA_DISK_1: copied control file copy output file name=/u01/app/oracle/oradata/rmanstd/control01.ctl output file name=/u01/app/oracle/fast_recovery_area/rmanstd/control02.ctl Finished restore at 11-MAY-22 備庫開啟到mount狀態: SQL> alter database mount; Database altered. 確認取消日誌應用: SQL> alter database recover managed standby database cancel; Database altered. 增量備份註冊到RMAN的catalog: RMAN> catalog start with '/home/oracle'; released channel: ORA_DISK_1 Starting implicit crosscheck backup at 11-MAY-22 allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=19 device type=DISK Crosschecked 9 objects Finished implicit crosscheck backup at 11-MAY-22 Starting implicit crosscheck copy at 11-MAY-22 using channel ORA_DISK_1 Crosschecked 4 objects Finished implicit crosscheck copy at 11-MAY-22 searching for all files in the recovery area cataloging files... no files cataloged searching for all files that match the pattern /home/oracle List of Files Unknown to the Database ===================================== File Name: /home/oracle/.bashrc File Name: /home/oracle/.bash_logout File Name: /home/oracle/incre_0v0t5vdb_1_1 File Name: /home/oracle/.bash_history File Name: /home/oracle/.oracle/logs/installActions2019-11-04_11-00-39AM.log File Name: /home/oracle/.oracle/logs/oraInstall2019-11-04_11-00-39AM.out File Name: /home/oracle/.oracle/logs/oraInstall2019-11-04_11-00-39AM.err File Name: /home/oracle/.bash_profile File Name: /home/oracle/incre_0u0t5vb9_1_1 File Name: /home/oracle/incre_0t0t5vb9_1_1 File Name: /home/oracle/.kshrc File Name: /home/oracle/standby.ctl File Name: /home/oracle/.viminfo Do you really want to catalog the above files (enter YES or NO)? yes cataloging files... cataloging done List of Cataloged Files ======================= File Name: /home/oracle/incre_0v0t5vdb_1_1 File Name: /home/oracle/incre_0u0t5vb9_1_1 File Name: /home/oracle/incre_0t0t5vb9_1_1 File Name: /home/oracle/standby.ctl 備庫開啟恢復增量備份: RMAN> recover database noredo; Starting recover at 11-MAY-22 using channel ORA_DISK_1 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: /u01/app/oracle/oradata/rmanstd/system01.dbf destination for restore of datafile 00004: /u01/app/oracle/oradata/rmanstd/users01.dbf channel ORA_DISK_1: reading from backup piece /home/oracle/incre_0t0t5vb9_1_1 channel ORA_DISK_1: piece handle=/home/oracle/incre_0t0t5vb9_1_1 tag=TAG20220510T185433 channel ORA_DISK_1: restored backup piece 1 channel ORA_DISK_1: restore complete, elapsed time: 00:00:01 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 00002: /u01/app/oracle/oradata/rmanstd/sysaux01.dbf destination for restore of datafile 00003: /u01/app/oracle/oradata/rmanstd/undotbs01.dbf channel ORA_DISK_1: reading from backup piece /home/oracle/incre_0u0t5vb9_1_1 channel ORA_DISK_1: piece handle=/home/oracle/incre_0u0t5vb9_1_1 tag=TAG20220510T185433 channel ORA_DISK_1: restored backup piece 1 channel ORA_DISK_1: restore complete, elapsed time: 00:00:01 Finished recover at 11-MAY-22 備庫開啟日誌同步程序: SQL> alter database recover managed standby database using current logfile disconnect from session; Database altered. 檢視GAP: SQL> select * from v$archive_gap; no rows selected SQL> SELECT max(sequence#) from v$archived_log where applied='YES'; MAX(SEQUENCE#) -------------- 主庫: SQL> alter system switch logfile; System altered. SQL> archive log list Database log mode Archive Mode Automatic archival Enabled Archive destination /oracle/archive Oldest online log sequence 79 Next log sequence to archive 81 Current log sequence 81 備庫: SQL> archive log list Database log mode Archive Mode Automatic archival Enabled Archive destination /oracle/archive Oldest online log sequence 79 Next log sequence to archive 0 Current log sequence 81 GAP修復完成。