oracle利用scn增量備份來實現同步dataguard

paulyibinyi發表於2016-06-03
環境:主庫和備庫形成oracle dataguard環境
實施目標:利用scn增量備份來實現同步dataguard
主要解決以下問題:

The steps in this section can used to resolve problems of missing or corrupted archive log file, an unresolveable archive gap, or need to roll standby forward in time without applying a large number of archivelog files. 

1 :主庫不小心刪除歸檔,而這時歸檔還沒傳遞到備庫
2 :主庫由於資料變更生成大量的歸檔,而備庫不能及時應用,可能會導致幾天的延遲
3:主庫的歸檔檔案遭到破壞,導致備庫不能應用

步驟如下:
請嚴格按照以下步驟來實施:
     1) Stop the managed recovery process (MRP) on the STANDBY database
         停止備庫的日誌傳輸程式
        alter database recover managed standby database cancel;

    2) Determine the SCN of the STANDBY database.
       查出備庫的最小scn號,用以下命令:
       SQL> SELECT CURRENT_SCN FROM V$DATABASE;
                CURRENT_SCN
                     3164433
       SQL> select min(f.fhscn) from x$kcvfh f, v$datafile d
                 where f.hxfil =d.file#
               and d.enabled != 'READ ONLY'     ;
                    MIN(F.FHSCN)
                         3162298   --這裡我們取3162298

     3) Take an incremental backup of the PRIMARY database
         在主庫執行以下命令實現增量備份:
       RMAN> BACKUP INCREMENTAL FROM SCN 3162298 DATABASE FORMAT '/tmp/ForStandby_%U' tag 'FORSTANDBY';

     4) Transfer all backup sets to STANDBY server
       傳輸主庫的增量備份檔案到備庫
         scp /tmp/ForStandby_* standby:/tmp

     5) Catalog the backups in STANDBY controlfile.
         在備庫執行以下catalog命令,使得備庫控制檔案能夠識別到scn增量備份值
         RMAN> CATALOG START WITH '/tmp/ForStandby';
            List of Files Unknown to the Database
      =====================================
      File Name: /tmp/ForStandby_2lkglss4_1_1
      File Name: /tmp/ForStandby_2mkglst8_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: /tmp/ForStandby_2lkglss4_1_1
     File Name: /tmp/ForStandby_2mkglst8_1_1

     6) Recover the STANDBY database with the cataloged incremental backup:
         在備庫恢復增量備份集
       RMAN> RECOVER DATABASE NOREDO;
        starting recover at 03-JUN-09
        allocated channel: ORA_DISK_1
        channel ORA_DISK_1: sid=28 devtype=DISK
        channel ORA_DISK_1: starting incremental datafile backupset restore
        channel ORA_DISK_1: specifying datafile(s) to restore from backup set
        destination for restore of datafile 00001: +DATA/mystd/datafile/system.297.688213333
        destination for restore of datafile 00002: +DATA/mystd/datafile/undotbs1.268.688213335
        destination for restore of datafile 00003: +DATA/mystd/datafile/sysaux.267.688213333
        channel ORA_DISK_1: reading from backup piece /tmp/ForStandby_2lkglss4_1_1
        channel ORA_DISK_1: restored backup piece 1
        piece handle=/tmp/ForStandby_2lkglss4_1_1 tag=FORSTANDBY
        channel ORA_DISK_1: restore complete, elapsed time: 00:00:02
         Finished recover at 03-JUN-09

     7) In RMAN, connect to the PRIMARY database and create a standby control file backup:
         主庫建立standby控制檔案
        RMAN> BACKUP CURRENT CONTROLFILE FOR STANDBY FORMAT '/tmp/ForStandbyCTRL.bck';
     
     8) Copy the standby control file backup to the STANDBY system.
           從主庫庫複製standby控制檔案到備庫
          scp /tmp/ForStandbyCTRL.bck standby:/tmp

     9) Capture datafile information in STANDBY database.
          獲取備庫的資料檔案資訊,以便和主庫的資料檔案資訊對比,包括路徑,是否不一致等
         spool datafile_names_step8.txt
         set lines 200
         col name format a60
         select file#, name from v$datafile order by file# ;
          spool off

         
     10) From RMAN, connect to STANDBY database and restore the standby control file:
           備庫恢復從主庫複製過來的standby控制檔案
            RMAN> SHUTDOWN IMMEDIATE ;
            RMAN> STARTUP NOMOUNT;
            RMAN> RESTORE STANDBY CONTROLFILE FROM '/tmp/ForStandbyCTRL.bck';
           Starting restore at 03-JUN-09
           using target database control file instead of recovery catalog
           allocated channel: ORA_DISK_1
           channel ORA_DISK_1: sid=36 devtype=DISK
           channel ORA_DISK_1: restoring control file
           channel ORA_DISK_1: restore complete, elapsed time: 00:00:07
           output filename=+DATA/mystd/controlfile/current.257.688583989
            Finished restore at 03-JUN-09


     11) Shut down the STANDBY database and startup mount:
             備庫關閉後啟動到mount狀態
            RMAN> SHUTDOWN;
            RMAN> STARTUP MOUNT;


     12) Catalog datafiles in STANDBY if location/name of datafiles is different
            如果備庫和主庫的資料檔案路徑不同,則需要用以下方法進行路徑改名
            RMAN> CATALOG START WITH '+DATA/mystd/datafile/';
             List of Files Unknown to the Database
            =====================================
            File Name: +data/mystd/DATAFILE/SYSTEM.309.685535773
            File Name: +data/mystd/DATAFILE/SYSAUX.301.685535773
            File Name: +data/mystd/DATAFILE/UNDOTBS1.302.685535775
            File Name: +data/mystd/DATAFILE/SYSTEM.297.688213333
            File Name: +data/mystd/DATAFILE/SYSAUX.267.688213333
            File Name: +data/mystd/DATAFILE/UNDOTBS1.268.688213335
            Do you really want to catalog the above files (enter YES or NO)? YES
            cataloging files...
            cataloging done
            List of Cataloged Files
             =======================
            File Name: +data/mystd/DATAFILE/SYSTEM.297.688213333
            File Name: +data/mystd/DATAFILE/SYSAUX.267.688213333
            File Name: +data/mystd/DATAFILE/UNDOTBS1.268.688213335

            可以在主庫用以下sql,查出大於備庫scn後面主庫有沒有新增加資料檔案,如果有則參考Note 1531031.1
            SQL>SELECT FILE#, NAME FROM V$DATAFILE WHERE CREATION_CHANGE# > 3162298
           這裡的環境是沒有,則繼續往下走switch datafile:
          RMAN> SWITCH DATABASE TO COPY;
          datafile 1 switched to datafile copy "+DATA/mystd/datafile/system.297.688213333"
         datafile 2 switched to datafile copy "+DATA/mystd/datafile/undotbs1.268.688213335"
         datafile 3 switched to datafile copy "+DATA/mystd/datafile/sysaux.267.688213333"


     13) Configure the STANDBY database to use flashback (optional)
              如果備庫要配置flashback,則把它開啟,這步是可選的
          SQL> ALTER DATABASE FLASHBACK OFF; 
          SQL> ALTER DATABASE FLASHBACK ON;


     14) On STANDBY database, clear all standby redo log groups:
              在備庫清除所有的standby redo log
            SQL> ALTER DATABASE CLEAR LOGFILE GROUP 1;
           SQL> ALTER DATABASE CLEAR LOGFILE GROUP 2;
           SQL> ALTER DATABASE CLEAR LOGFILE GROUP 3;

     15) On the STANDBY database, start the MRP
               追加完成,啟用日誌恢復
            ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT;
          

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/7199859/viewspace-2113506/,如需轉載,請註明出處,否則將追究法律責任。

相關文章