Sunday, September 28, 2014

RMAN Duplicate Cloning RAC ASM to NON RAC File-system using Duplicate

Duplicate a Database Using RMAN in Oracle Database 11g Release 2



Introduction

RMAN has the ability to duplicate, or clone, a database from a backup or from an active database. It is possible to create a duplicate database on a remote server with the same file structure, a remote server will a different file structure or the local server with a different file structure.
The article assumes the duplicate database is being created on a separate server, using the same SID (TEST) and the same file structure as the source database.


Backup-Based Duplication


Bash$ rman target /
RMAN> CONFIGURE CONTROLFILE AUTOBACKUP ON;
RMAN> BACKUP DATABASE PLUS ARCHIVELOG;



Create password file for Duplicate Database (TEST) 


orapwd file=$ORACLE_HOME/dbs/orapwTEST password=password entries=10


Add the appropriate entries into the "tnsnames.ora" file

 in the "$ORACLE_HOME/network/admin" directory to allow connections to the target database from the duplicate server.

# Added to the tnsnames.ora
PROD-SOURCE =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = database-hostname)(PORT = 1521))
    )
    (CONNECT_DATA =
      (ORACLE_SID = PROD)
    )


Create a PFILE for the duplicate database

Since we are duplicating the database onto a separate server with the same filesystem as the original, we don't need to convert the file names. In this case, the PFILE is called "initDB11G.ora" and is placed in the "$ORACLE_HOME/dbs" directory.

# Minimum Requirement.
DB_NAME=TEST

# Convert file names to allow for different directory structure if necessary.
#DB_FILE_NAME_CONVERT='+DATA/datafile/PROD-Source/','/u01/app/oracle/oradata/TEST/'
#LOG_FILE_NAME_CONVERT='+DATA/datafile/PROD-Source/','/u02/app/oracle/oradata/TEST/'

We don't need all the other parameters as the clone will copy the SPFILE from the primary database. If you are duplicating a database on the same machine you will probably need to create a PFFILE/SPFILE manually from the primary database SPFILE, manually change the values and avoid the SPFILE clause in the duplicate command.

Create any directories necessary for start the duplicate database.

$ mkdir -p /u01/app/oracle/oradata/TEST
$ mkdir -p /u01/app/oracle/fast_recovery_area/TEST
$ mkdir -p /u01/app/oracle/admin/TEST/adump

Make the backup files from the source database available to the destination server. That can be done by either copying them to the matching location on the destination server, or placing them on a shared drive. If you are copying the files, you may want to use the following type of commands.

$ scp -r oracle@ol5-112-dup1:/u01/app/oracle/fast_recovery_area/PROD-Source/archivelog /u01/app/oracle/fast_recovery_area/TEST
$ scp -r oracle@ol5-112-dup1:/u01/app/oracle/fast_recovery_area/PROD-Source/backupset /u01/app/oracle/fast_recovery_area/TEST
$ scp -r oracle@ol5-112-dup1:/u01/app/oracle/fast_recovery_area/PROD-Source/autobackup /u01/app/oracle/fast_recovery_area/TEST

Connect to the duplicate instance.

$ ORACLE_SID=TEST; export ORACLE_SID
$ sqlplus / as sysdba
Start the database in NOMOUNT mode.

SQL> STARTUP NOMOUNT;

Once Done startup nomount .

bash-4.2$ ./rman target sys/password@PROD-SOURCE auxiliary /

Recovery Manager: Release 11.2.0.3.0 - Production on Fri Jul 11 14:14:34 2014

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: PROD-SOURCE (DBID=2989196308)

connected to auxiliary database: TEST (not mounted)

RMAN> DUPLICATE TARGET DATABASE TO TEST
  SPFILE
  NOFILENAMECHECK;

  

using target database control file instead of recovery catalog
allocated channel: C1
channel C1: SID=253 device type=DISK

Starting Duplicate Db at 11-JUL-14

contents of Memory Script:
{
   sql clone "create spfile from memory";
}
executing Memory Script

sql statement: create spfile from memory

contents of Memory Script:
{
   shutdown clone immediate;
   startup clone nomount;
}
executing Memory Script

Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area    5344731136 bytes

Fixed Size                     2192008 bytes
Variable Size                956304760 bytes
Database Buffers            4362076160 bytes
Redo Buffers                  24158208 bytes
allocated channel: C1
channel C1: SID=254 device type=DISK

contents of Memory Script:
{
   sql clone "alter system set  db_name =
 ''PROD-SOURCE'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
   sql clone "alter system set  db_unique_name =
 ''TEST'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
   shutdown clone immediate;
   startup clone force nomount
   restore clone primary controlfile;
   alter clone database mount;
}
executing Memory Script

sql statement: alter system set  db_name =  ''PROD-SOURCE'' comment= ''Modified by RMAN duplicate'' scope=spfile

sql statement: alter system set  db_unique_name =  ''TEST'' comment= ''Modified by RMAN duplicate'' scope=spfile

Oracle instance shut down

Oracle instance started

Total System Global Area    5344731136 bytes

Fixed Size                     2192008 bytes
Variable Size                956304760 bytes
Database Buffers            4362076160 bytes
Redo Buffers                  24158208 bytes
allocated channel: C1
channel C1: SID=254 device type=DISK

Starting restore at 11-JUL-14

channel C1: starting datafile backup set restore
channel C1: restoring control file
channel C1: reading from backup piece /u02/oracle/PROD-SOURCEuct/11.2.0/dbs/c-198916508-20140711-01
channel C1: piece handle=/u02/oracle/PROD-SOURCE/11.2.0/dbs/c-198916508-20140711-01 tag=TAG20140711T134203
channel C1: restored backup piece 1
channel C1: restore complete, elapsed time: 00:00:01
output file name=/u01/controlfile/controlfile.ctl
Finished restore at 11-JUL-14

database mounted


contents of Memory Script:



ontents of Memory Script:
{
   Alter clone database open resetlogs;
}
executing Memory Script

database opened
Finished Duplicate Db at 11-JUL-14
released channel: C1


RMAN>