利用 RMAN 备份集部署DG

1:主备数据库版本一定要一样。
2:备库    安装数据库软件,根据主库数据文件、日志文件路径等创建相关文件夹,具体可以参考主库参数文件中有路径的参数
3:主库    全备,包括数据文件、归档日志文件、控制文件。

点击(此处)折叠或打开

  1. run{
  2. sql \"alter system archive log current\";
  3. sql \"alter database create standby controlfile as \'\'/home/oracle/standby.ctl\'\'\";
  4. backup database format \"/home/oracle/full_%U_%t.bak\" plus archivelog format \"/home/oracle/arch_%U_%t.bak\";
  5. sql \"alter system archive log current\";
  6. }

[oracle@redhat01 ~]$ tar zcvf standby.tar.gz *.bak standby.ctl
[oracle@redhat01 ~]$ scp standby.tar.gz 192.168.253.131:/home/oracle

拷贝完成之后,将备份集打包传送至备库。
4:备库    备份集解压、数据恢复

点击(此处)折叠或打开

  1. [oracle@redhat02 ~]$ tar zxvf standby.tar.gz
  2. rman target /
  3. RMAN> restore controlfile from '/home/oracle/standby.ctl';

    Starting restore at 29-JUN-15
    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=/opt/oracle/product/11.2.0/dbs/ora_control1
    output file name=/opt/oracle/product/11.2.0/dbs/ora_control2
    Finished restore at 29-JUN-15

    RMAN> alter database mount;

    database mounted
    released channel: ORA_DISK_1

    RMAN> crosscheck archivelog all;

    Starting implicit crosscheck backup at 29-JUN-15
    allocated channel: ORA_DISK_1
    channel ORA_DISK_1: SID=20 device type=DISK
    Crosschecked 4 objects
    Finished implicit crosscheck backup at 29-JUN-15

    Starting implicit crosscheck copy at 29-JUN-15
    using channel ORA_DISK_1
    Crosschecked 2 objects
    Finished implicit crosscheck copy at 29-JUN-15

    searching for all files in the recovery area
    cataloging files...
    no files cataloged

    released channel: ORA_DISK_1
    allocated channel: ORA_DISK_1
    channel ORA_DISK_1: SID=20 device type=DISK
    specification does not match any archived log in the repository

    RMAN> delete expired archivelog all;

    released channel: ORA_DISK_1
    allocated channel: ORA_DISK_1
    channel ORA_DISK_1: SID=20 device type=DISK
    specification does not match any archived log in the repository

    RMAN> crosscheck backupset;

    using channel ORA_DISK_1

    crosschecked backup piece: found to be 'EXPIRED'
    backup piece handle=/home/oracle/arch_03qamd61_1_1_883635393.bak RECID=2 STAMP=883987249
    crosschecked backup piece: found to be 'EXPIRED'
    backup piece handle=/home/oracle/full_04qamd62_1_1_883635394.bak RECID=3 STAMP=883987249
    crosschecked backup piece: found to be 'EXPIRED'
    backup piece handle=/home/oracle/full_05qamd76_1_1_883635430.bak RECID=4 STAMP=883987249
    crosschecked backup piece: found to be 'EXPIRED'
    backup piece handle=/home/oracle/arch_06qamd7a_1_1_883635434.bak RECID=5 STAMP=883987249
    Crosschecked 4 objects


    RMAN>
    RMAN> delete expired backupset;

  4. RMAN> catalog start with '/home/oracle/';
  5. RMAN> restore database;
  6. RMAN> recover database;
6:主备库 initorcl.ora、listener.ora、tnsnames.ora 配置,因为修改了 UNIQUE_NAME,所以需要重启数据库

点击(此处)折叠或打开

  1. //主库:
  2.   //initorcl.ora
  3. alter system set db_unique_name = orcl3 scope=spfile;
  4. alter system set LOG_ARCHIVE_CONFIG=\'DG_CONFIG=(orcl2,orcl3)\';
  5. alter system set LOG_ARCHIVE_DEST_1=\'LOCATION=/data/oracle/orcl/archive/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=orcl3\';
  6. alter system set LOG_ARCHIVE_DEST_2=\'SERVICE=orclsta LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orcl2\';
  7. alter system set LOG_ARCHIVE_DEST_STATE_1=ENABLE;
  8. alter system set LOG_ARCHIVE_DEST_STATE_2=ENABLE;

  9. alter system set FAL_SERVER=orclsta;
  10. alter system set FAL_CLIENT=orclpri;
  11. alter system set STANDBY_FILE_MANAGEMENT=AUTO;
  12.   //listener.ora
  13. [oracle@redhat02 ~]$ cat //opt/oracle/product/11.2.0/network/admin/listener.ora
    # listener.ora Network Configuration File: /opt/oracle/product/11.2.0/network/admin/listener.ora
    # Generated by Oracle configuration tools.

    LISTENER =
      (DESCRIPTION_LIST =
        (DESCRIPTION =
          (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
          (ADDRESS = (PROTOCOL = TCP)(HOST = redhat02.com)(PORT = 1521))
        )
      )

    ADR_BASE_LISTENER = /opt/oracle

        //tnsnames.ora
    [oracle@redhat02 ~]$ cat //opt/oracle/product/11.2.0/network/admin/tnsnames.ora
orclpri=
  (DESCRIPTION=
    (ADDRESS=
      (PROTOCOL=TCP)
      (HOST=192.168.253.131)
      (PORT=1521)
    )
    (CONNECT_DATA=
      (SID=orcl)
    )
  )

orclsta=
  (DESCRIPTION=
    (ADDRESS=
      (PROTOCOL=TCP)
      (HOST=192.168.253.130)
      (PORT=1521)
    )
    (CONNECT_DATA=
      (SID=orcl)
    )
  )


点击(此处)折叠或打开

  1. //备库:
  2. alter system set db_unique_name = orcl2 scope=spfile;
  3. alter system set LOG_ARCHIVE_CONFIG=\'DG_CONFIG=(orcl2,orcl3)\';
  4. alter system set LOG_ARCHIVE_DEST_1=\'LOCATION=/data/oracle/orcl/archive/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=orcl2\';
  5. alter system set LOG_ARCHIVE_DEST_2=\'SERVICE=orclpri LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orcl3\';
  6. alter system set LOG_ARCHIVE_DEST_STATE_1=ENABLE;
  7. alter system set LOG_ARCHIVE_DEST_STATE_2=ENABLE;
  8. alter system set FAL_SERVER=orclpri;
  9. alter system set FAL_CLIENT=orclsta;
  10. alter system set STANDBY_FILE_MANAGEMENT=AUTO;
    1. //listener.ora
    2. [oracle@redhat02 ~]$ cat //opt/oracle/product/11.2.0/network/admin/listener.ora
      # listener.ora Network Configuration File: /opt/oracle/product/11.2.0/network/admin/listener.ora
      # Generated by Oracle configuration tools.

      LISTENER =
        (DESCRIPTION_LIST =
          (DESCRIPTION =
            (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
            (ADDRESS = (PROTOCOL = TCP)(HOST = redhat01.com)(PORT = 1521))
          )
        )

      ADR_BASE_LISTENER = /opt/oracle

  11. //tnsnames.ora
        [oracle@redhat02 ~]$ cat //opt/oracle/product/11.2.0/network/admin/tnsnames.ora
    orclpri=
      (DESCRIPTION=
        (ADDRESS=
          (PROTOCOL=TCP)
          (HOST=192.168.253.131)
          (PORT=1521)
        )
        (CONNECT_DATA=
          (SID=orcl)
        )
      )

    orclsta=
      (DESCRIPTION=
        (ADDRESS=
          (PROTOCOL=TCP)
          (HOST=192.168.253.130)
          (PORT=1521)
        )
        (CONNECT_DATA=
          (SID=orcl)
        )
      )
7.将主库密码文件拷贝至备库
8.启用日志应用,查看是否正常,查看告警日志是否异常。

点击(此处)折叠或打开

  1. SQL> alter database open;

  2. Database altered.

  3. SQL> alter database recover managed standby database using current logfile disconnect from session;

  4. Database altered.

  5. SQL> select STATUS,THREAD#,SEQUENCE# from v$managed_standby;

  6. SQL> select sequence#,status,applied from v$archived_log;

  7.  SEQUENCE# S APPLIED
  8. ---------- - ---------
  9.      6 A YES
  10.      7 A YES
  11.      8 A YES
  12.      9 A YES
  13.     10 A YES
  14.     11 A YES
  15.     12 A YES

  16. 7 rows selected.
若告警日志中有如下错,需要取消日志应用,删除旧的 standby 日志组或文件,重建 standby 日志组/文件

点击(此处)折叠或打开

  1. [oracle@felixdb ~]$ oerr ora 19527
  2.         19527, 00000, \"physical standby redo log must be renamed\"
  3.         // *Cause: The CLEAR LOGFILE command was used at a physical standby
  4.         // database. This command cannot be used at a physical standby
  5.         // database unless the LOG_FILE_NAME_CONVERT initialization
  6.         // parameter is set. This is required to avoid overwriting
  7.         // the primary database\

点击(此处)折叠或打开

  1. alter database drop logfile group 11;
  2. alter database drop logfile group 12;
  3. alter database add standby logfile group 11 (\'/data/oradata/orcl/data/standby_redo11b.log\',\'/data/oradata/orcl/data/standby_redo11a.log\') size 100m;
  4. alter database add standby logfile group 12 (\'/data/oradata/orcl/data/standby_redo12b.log\',\'/data/oradata/orcl/data/standby_redo12a.log\') size 100m;

现在重启备库实时日志应用,可以测试一下


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29143715/viewspace-1730033/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/29143715/viewspace-1730033/

你可能感兴趣的:(利用 RMAN 备份集部署DG)