如何使用 RMAN 增量備份恢複 data guard log gap(日誌斷檔)
主庫查詢最小scn 資訊:
SQL> col current_scn for 999999999999999
SQL> SELECT CURRENT_SCN FROM V$DATABASE;
select min(fhscn) from x$kcvfh;
select min(f.fhscn) from x$kcvfh f, v$datafile d
where f.hxfil =d.file#
and d.enabled != 'READ ONLY' ;
CURRENT_SCN
----------------
12614205226673
MIN(FHSCN)
----------------
12614205076072
MIN(F.FHSCN)
----------------
12614205076072
+++++++++++++++++++++++++++++++++++++++++++++++=
1.----備庫取消歸檔應用
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
2.----備庫確定 lowest scn
col current_scn for 99999999999999
SELECT CURRENT_SCN FROM V$DATABASE;
select min(fhscn) from x$kcvfh;
select min(f.fhscn) from x$kcvfh f, v$datafile d
where f.hxfil =d.file#
and d.enabled != 'READ ONLY' ;
取上述查詢中的最小值
SQL> col current_scn for 999999999999999999
SQL> SELECT CURRENT_SCN FROM V$DATABASE;
CURRENT_SCN
-------------------
12611050666604
SQL> select min(fhscn) from x$kcvfh;
MIN(FHSCN)
----------------
12611050666605
SQL> select min(f.fhscn) from x$kcvfh f, v$datafile d
where f.hxfil =d.file#
and d.enabled != 'READ ONLY' ; 2 3
MIN(F.FHSCN)
----------------
12611050666605
3.-----on primary db 端根據第2步中擷取的最小scn 來進行增量備份
BACKUP INCREMENTAL FROM SCN 12611050666604 DATABASE FORMAT '/lixora/ForStandby_%U' tag 'FORSTANDBY';
4.-----拷貝備份到 備庫
$scp ForStandby_07pqprm4_1_1 192.168.0.10:/tmp
5.----on standby db 在備庫端註冊備份片,注意使用者屬主,許可權
RMAN> CATALOG START WITH '/lixora/ForStandby';
6.----執行恢複
RMAN> RECOVER DATABASE NOREDO;
7.-----on primary db 產生新的standby 控制檔案
RMAN> BACKUP CURRENT CONTROLFILE FOR STANDBY FORMAT '/lixora/ForStandbyCTRL.bck';
8.----把主庫端產生的standby 控制檔案拷貝到備庫,注意使用者屬主,許可權
RMAN> BACKUP CURRENT CONTROLFILE FOR STANDBY FORMAT '/lixora/ForStandbyCTRL.bck';
scp /lixora/ForStandbyCTRL.bck 192.168.0.10:/tmp
9.------備份備庫資料檔案資訊,用於在恢複新的standby 控制檔案後比對
spool datafile_names_step8.txt
set lines 200
col name format a60
select file#, name from v$datafile order by file# ;
spool off
10.------on standby Db 恢複新的standby 控制檔案
RMAN> SHUTDOWN IMMEDIATE ;
RMAN> STARTUP NOMOUNT;
RMAN> RESTORE STANDBY CONTROLFILE FROM '/tmp/ForStandbyCTRL.bck';
11.-----更新控制檔案中的資料檔案資訊
使新的standby 控制檔案生效
RMAN> SHUTDOWN;
RMAN> STARTUP MOUNT;
CATALOG START WITH '+DATA/zhglptdg/datafile/';
12.------on primary db。確保在備庫發生日誌gap 後,主庫沒有添加過新的資料檔案。
SELECT FILE#, NAME FROM V$DATAFILE WHERE CREATION_CHANGE# > 12611050666604;
如果有記錄,則不能進行witch 操作,可以參考一下文檔來恢複:
Note 1531031.1 Steps to perform for Rolling forward a standby database using RMAN incremental backup when datafile is added to primary
13.-----重新命名資料檔案
RMAN> SWITCH DATABASE TO COPY;
14.-----再次確認在恢複增量備份片後主庫和備庫scn 差距沒有太大
SQL> col current_scn for 99999999999999
SELECT CURRENT_SCN FROM V$DATABASE;
select min(fhscn) from x$kcvfh;
select min(f.fhscn) from x$kcvfh f, v$datafile d
where f.hxfil =d.file#
and d.enabled != 'READ ONLY' ;
CURRENT_SCN
---------------
12614205662375
MIN(FHSCN)
----------------
12614205076072
MIN(F.FHSCN)
----------------
12614205076072
15.------ On standby database, 清理standby 日誌組
select * from v$standby_log;
SQL> ALTER DATABASE CLEAR LOGFILE GROUP 1;
SQL> ALTER DATABASE CLEAR LOGFILE GROUP 2;
SQL> ALTER DATABASE CLEAR LOGFILE GROUP 3;
16.------啟動redo data apply
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT;
如果遇到一些由於設定 nologgling 而導致部分資料丟失,可以安裝下述方法來進行恢複
To resolve NOLOGGING operations only, see Note 958181.1.
In addition to this information, see the online documentation:
10.2: http://download.Oracle.com/docs/cd/B19306_01/server.102/b14239/scenarios.htm#CIHIAADC
11.1: http://download.oracle.com/docs/cd/B28359_01/server.111/b28294/rman.htm#SBYDB00759
11.2: http://download.oracle.com/docs/cd/E11882_01/server.112/e17022/rman.htm#CIHIAADC
後記
如果要啟用即時應用,需要在備庫添加standby redo log,大小應和主庫一樣,且比主庫多一組;
ALTER DATABASE add standby LOGFILE GROUP 6 size 500M;
ALTER DATABASE add standby LOGFILE GROUP 7 size 500M;
ALTER DATABASE add standby LOGFILE GROUP 8 size 500M;
ALTER DATABASE add standby LOGFILE GROUP 9 size 500M;
啟用命令:
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE;
具體內容參見:
Oracle 10g standby database 即時應用 redo 資料
如何確保dg 已經正常,後台日誌類似如下:
Mon Dec 22 10:03:04 CST 2014
RFS[1]: Archived Log: '+DATA/lixora/archivelog/1_23094_790186477.dbf'
Mon Dec 22 10:03:25 CST 2014
Media Recovery Log +DATA/lixora/archivelog/1_23094_790186477.dbf
Media Recovery Waiting for thread 1 sequence 23095 (in transit)
Mon Dec 22 10:05:53 CST 2014
RFS[2]: Archived Log: '+DATA/lixora/archivelog/1_23095_790186477.dbf'
Primary database is in MAXIMUM PERFORMANCE mode
RFS[2]: No standby redo logfiles of size 1024000 blocks exist
Mon Dec 22 10:05:55 CST 2014
Media Recovery Log +DATA/zhglptdg/archivelog/1_23095_790186477.dbf
Media Recovery Waiting for thread 1 sequence 23096 (in transit)
Mon Dec 22 10:05:57 CST 2014
RFS[2]: Archived Log: '+DATA/lixora/archivelog/1_23096_790186477.dbf'
Primary database is in MAXIMUM PERFORMANCE mode
RFS[2]: No standby redo logfiles of size 1024000 blocks exist
Mon Dec 22 10:06:00 CST 2014
Media Recovery Log +DATA/lixora/archivelog/1_23096_790186477.dbf
Media Recovery Waiting for thread 1 sequence 23097 (in transit)
類似一下日誌,表明日誌只是傳過來,但是沒有應用:
Tue Dec 16 17:28:48 CST 2014
Primary database is in MAXIMUM PERFORMANCE mode
RFS[3]: Successfully opened standby log 7: '+DATA/lixora/onlinelog/group_7.360.857131345'
Tue Dec 16 18:57:12 CST 2014
Primary database is in MAXIMUM PERFORMANCE mode
RFS[3]: Successfully opened standby log 8: '+DATA/lixora/onlinelog/group_8.361.857131375'
Tue Dec 16 20:12:13 CST 2014
Primary database is in MAXIMUM PERFORMANCE mode
RFS[3]: Successfully opened standby log 7: '+DATA/lixora/onlinelog/group_7.360.857131345'
Tue Dec 16 21:40:39 CST 2014
Primary database is in MAXIMUM PERFORMANCE mode
RFS[3]: Successfully opened standby log 8: '+DATA/lixora/onlinelog/group_8.361.857131375'
如何可以確保dg 正常:
1)v$archive_log.applied 是否為yes
2)主庫切換日誌:ALTER system swtich logfile;
看備庫v$database.CURRENT_SCN 是否有增長?
--------------------------------------推薦閱讀 --------------------------------------
RMAN 配置歸檔日誌刪除策略
Oracle基礎教程之通過RMAN複製資料庫
RMAN備份策略制定參考內容
RMAN備份學習筆記
OracleDatabase Backup加密 RMAN加密
--------------------------------------分割線 --------------------------------------
本文永久更新連結地址: