Duplicate a Standby Database (2/4) - With Backup-Based Duplication

  • by

Backup-Based duplication requires to connect to the target database, and one copy of database backups files has to be stored in the same directories of both databases. But the next question will be how to transport the backup files to the standby database between two ASM instances. Here are the steps:

  1. Startup one instance of the standby cluster database to nomount state.
  2. [oracle@standby01 ~]$ srvctl stop database -d compdb
    [oracle@standby01 ~]$ sqlplus / as sysdba
    ...
    Connected to an idle instance.

    SQL> startup nomount;
    ...

  3. Make same directory on both sides of ASM instances for storing backup files.
  4. On the primary server.

    [oracle@primary02 ~]$ asmcmd
    ASMCMD> mkdir +data/backup

    On the standby server.

    [oracle@standby02 ~]$ asmcmd
    ASMCMD> mkdir +data/backup

  5. Backup the datafiles and controlfile in the primary database with RMAN.
  6. [oracle@primary01 ~]$ rman target /
    ...
    connected to target database: COMPDB (DBID=841830157)

    RMAN> backup database format '+data/backup/%U';

    Starting backup at 24-JAN-13
    using target database control file instead of recovery catalog
    allocated channel: ORA_DISK_1
    channel ORA_DISK_1: SID=134 instance=primdb1 device type=DISK
    channel ORA_DISK_1: starting full datafile backup set
    channel ORA_DISK_1: specifying datafile(s) in backup set
    input datafile file number=00001 name=+DATA/primdb/datafile/system.897.797943475
    input datafile file number=00002 name=+DATA/primdb/datafile/sysaux.898.797943569
    input datafile file number=00003 name=+DATA/primdb/datafile/undotbs1.899.797943687
    input datafile file number=00005 name=+DATA/primdb/datafile/example.900.797943711
    input datafile file number=00006 name=+DATA/primdb/datafile/undotbs2.901.797943737
    input datafile file number=00004 name=+DATA/primdb/datafile/users.902.797943753
    channel ORA_DISK_1: starting piece 1 at 24-JAN-13
    channel ORA_DISK_1: finished piece 1 at 24-JAN-13
    piece handle=+DATA/backup/0do07k9m_1_1 tag=TAG20130124T134213 comment=NONE
    channel ORA_DISK_1: backup set complete, elapsed time: 00:03:56
    Finished backup at 24-JAN-13

    Starting Control File and SPFILE Autobackup at 24-JAN-13
    piece handle=+DATA/primdb/autobackup/2013_01_24/s_805556771.1092.805556777 comment=NONE
    Finished Control File and SPFILE Autobackup at 24-JAN-13

    RMAN> backup current controlfile format '+data/backup/%U';

    Starting backup at 24-JAN-13
    using channel ORA_DISK_1
    channel ORA_DISK_1: starting full datafile backup set
    channel ORA_DISK_1: specifying datafile(s) in backup set
    including current control file in backup set
    channel ORA_DISK_1: starting piece 1 at 24-JAN-13
    channel ORA_DISK_1: finished piece 1 at 24-JAN-13
    piece handle=+DATA/backup/0fo07khm_1_1 tag=TAG20130124T134630 comment=NONE
    channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
    Finished backup at 24-JAN-13

    Starting Control File and SPFILE Autobackup at 24-JAN-13
    piece handle=+DATA/primdb/autobackup/2013_01_24/s_805556797.1090.805556803 comment=NONE
    Finished Control File and SPFILE Autobackup at 24-JAN-13

    RMAN>

  7. Transport the backup files to the same directory of the standby ASM instance.
  8. Copy the backup dumps from the remote primary server to the same directory of the local database.

    ASMCMD> cp sys@primary02-vip.1521.+ASM2:+DATA/backup/0do07k9m_1_1 +DATA/backup/0do07k9m_1_1
    Enter password: **********
    ASMCMD> cp sys@primary02-vip.1521.+ASM2:+DATA/backup/0fo07khm_1_1 +DATA/backup/0fo07khm_1_1
    Enter password: **********
    ASMCMD>

  9. Duplicate the standby database from already existed backups.
  10. In the process, there could be several ignorable errors that signal some of the backup files are not found in the standby ASM storage database. RMAN still can find out the available backup files to use them for duplication.

    RMAN> RUN {
    2> DUPLICATE TARGET DATABASE
    3> FOR STANDBY
    4> NOFILENAMECHECK;
    5> }

    Starting Duplicate Db at 24-JAN-13
    using target database control file instead of recovery catalog
    allocated channel: ORA_AUX_DISK_1
    channel ORA_AUX_DISK_1: SID=34 instance=standb1 device type=DISK

    contents of Memory Script:
    {
       sql clone "alter system set  control_files =
      ''+DATA/standb/controlfile/current.270.805557963'' comment=
     ''Set by RMAN'' scope=spfile";
       restore clone standby controlfile;
    }
    executing Memory Script

    sql statement: alter system set  control_files =   ''+DATA/standb/controlfile/current.270.805557963'' comment= ''Set by RMAN'' scope=spfile

    Starting restore at 24-JAN-13
    using channel ORA_AUX_DISK_1

    channel ORA_AUX_DISK_1: starting datafile backup set restore
    channel ORA_AUX_DISK_1: restoring control file
    channel ORA_AUX_DISK_1: reading from backup piece +DATA/primdb/autobackup/2013_01_24/s_805556797.1090.805556803
    channel ORA_AUX_DISK_1: ORA-19870: error while restoring backup piece +DATA/primdb/autobackup/2013_01_24/s_805556797.1090.805556803
    ORA-19505: failed to identify file "+DATA/primdb/autobackup/2013_01_24/s_805556797.1090.805556803"
    ORA-17503: ksfdopn:2 Failed to open file +DATA/primdb/autobackup/2013_01_24/s_805556797.1090.805556803
    ORA-15012: ASM file '+DATA/primdb/autobackup/2013_01_24/s_805556797.1090.805556803' does not exist

    failover to previous backup

    channel ORA_AUX_DISK_1: starting datafile backup set restore
    channel ORA_AUX_DISK_1: restoring control file
    channel ORA_AUX_DISK_1: reading from backup piece +DATA/backup/0fo07khm_1_1
    channel ORA_AUX_DISK_1: piece handle=+DATA/backup/0fo07khm_1_1 tag=TAG20130124T134630
    channel ORA_AUX_DISK_1: restored backup piece 1
    channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:15
    output file name=+DATA/standb/controlfile/current.271.805557967
    Finished restore at 24-JAN-13

    contents of Memory Script:
    {
       sql clone 'alter database mount standby database';
    }
    executing Memory Script

    sql statement: alter database mount standby database
    RMAN-05529: WARNING: DB_FILE_NAME_CONVERT resulted in invalid ASM names; names changed to disk group only.

    contents of Memory Script:
    {
       set newname for tempfile  1 to
     "+data";
       switch clone tempfile all;
       set newname for datafile  1 to
     "+data";
       set newname for datafile  2 to
     "+data";
       set newname for datafile  3 to
     "+data";
       set newname for datafile  4 to
     "+data";
       set newname for datafile  5 to
     "+data";
       set newname for datafile  6 to
     "+data";
       restore
       clone database
       ;
    }
    executing Memory Script

    executing command: SET NEWNAME

    renamed tempfile 1 to +data in control file

    executing command: SET NEWNAME

    executing command: SET NEWNAME

    executing command: SET NEWNAME

    executing command: SET NEWNAME

    executing command: SET NEWNAME

    executing command: SET NEWNAME

    Starting restore at 24-JAN-13
    using channel ORA_AUX_DISK_1

    channel ORA_AUX_DISK_1: starting datafile backup set restore
    channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
    channel ORA_AUX_DISK_1: restoring datafile 00001 to +data
    channel ORA_AUX_DISK_1: restoring datafile 00002 to +data
    channel ORA_AUX_DISK_1: restoring datafile 00003 to +data
    channel ORA_AUX_DISK_1: restoring datafile 00004 to +data
    channel ORA_AUX_DISK_1: restoring datafile 00005 to +data
    channel ORA_AUX_DISK_1: restoring datafile 00006 to +data
    channel ORA_AUX_DISK_1: reading from backup piece +DATA/backup/0do07k9m_1_1
    channel ORA_AUX_DISK_1: piece handle=+DATA/backup/0do07k9m_1_1 tag=TAG20130124T134213
    channel ORA_AUX_DISK_1: restored backup piece 1
    channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:06:17
    Finished restore at 24-JAN-13

    contents of Memory Script:
    {
       switch clone datafile all;
    }
    executing Memory Script

    datafile 1 switched to datafile copy
    input datafile copy RECID=22 STAMP=805558372 file name=+DATA/standb/datafile/system.272.805557997
    datafile 2 switched to datafile copy
    input datafile copy RECID=23 STAMP=805558372 file name=+DATA/standb/datafile/sysaux.273.805558003
    datafile 3 switched to datafile copy
    input datafile copy RECID=24 STAMP=805558372 file name=+DATA/standb/datafile/undotbs1.260.805558009
    datafile 4 switched to datafile copy
    input datafile copy RECID=25 STAMP=805558372 file name=+DATA/standb/datafile/users.1110.805558015
    datafile 5 switched to datafile copy
    input datafile copy RECID=26 STAMP=805558372 file name=+DATA/standb/datafile/example.1106.805558011
    datafile 6 switched to datafile copy
    input datafile copy RECID=27 STAMP=805558373 file name=+DATA/standb/datafile/undotbs2.1109.805558013
    Finished Duplicate Db at 24-JAN-13

    RMAN>

  11. Restart all instances of the standby cluster database to mount state, then check the status.
  12. SQL> shutdown immediate;
    ORA-01109: database not open


    Database dismounted.
    ORACLE instance shut down.
    ...
    [oracle@standby01 ~]$ srvctl start database -d compdb -o mount
    [oracle@standby01 ~]$ sqlplus / as sysdba
    ...
    SQL> select inst_id, open_mode, database_role, switchover_status from gv$database;

       INST_ID OPEN_MODE            DATABASE_ROLE    SWITCHOVER_STATUS
    ---------- -------------------- ---------------- --------------------
             1 MOUNTED              PHYSICAL STANDBY RECOVERY NEEDED
             2 MOUNTED              PHYSICAL STANDBY RECOVERY NEEDED

    SQL> select inst_id, process, status, thread#, sequence#, block#, blocks from gv$managed_standby where process in ('RFS','LNS') or process like 'MR%';

       INST_ID PROCESS   STATUS          THREAD#  SEQUENCE#     BLOCK#     BLOCKS
    ---------- --------- ------------ ---------- ---------- ---------- ----------
             1 RFS       IDLE                  0          0          0          0
             1 RFS       IDLE                  1         85         45          1
             1 RFS       IDLE                  2         81         54          1
             2 RFS       IDLE                  0          0          0          0
             2 RFS       IDLE                  0          0          0          0
             2 RFS       IDLE                  0          0          0          0

    6 rows selected.

    DATABASE_ROLE is PHYSICAL STANDBY now.
  13. Start applying service.
  14. SQL> alter database recover managed standby database disconnect from session;

    Database altered.

    SQL> select inst_id, process, status, thread#, sequence#, block#, blocks from gv$managed_standby where process in ('RFS','LNS') or process like 'MR%';

       INST_ID PROCESS   STATUS          THREAD#  SEQUENCE#     BLOCK#     BLOCKS
    ---------- --------- ------------ ---------- ---------- ---------- ----------
             1 RFS       IDLE                  0          0          0          0
             1 MRP0      APPLYING_LOG          2         78       9168       9169
             1 RFS       RECEIVING             1         85        114          1
             1 RFS       RECEIVING             2         81        243          1
             2 RFS       IDLE                  0          0          0          0
             2 RFS       IDLE                  0          0          0          0
             2 RFS       IDLE                  0          0          0          0
             2 RFS       IDLE                  0          0          0          0

    8 rows selected.

    SQL> /

       INST_ID PROCESS   STATUS          THREAD#  SEQUENCE#     BLOCK#     BLOCKS
    ---------- --------- ------------ ---------- ---------- ---------- ----------
             1 RFS       IDLE                  0          0          0          0
             1 MRP0      WAIT_FOR_LOG          1         85          0          0
             1 RFS       IDLE                  1         85        128          1
             1 RFS       IDLE                  2         81        256          1
             2 RFS       IDLE                  0          0          0          0
             2 RFS       IDLE                  0          0          0          0
             2 RFS       IDLE                  0          0          0          0
             2 RFS       IDLE                  0          0          0          0

    8 rows selected.

Leave a Reply

Your email address will not be published. Required fields are marked *