Duplicate a Database Using RMAN

posted Sep 10, 2010, 2:15 PM by Sachchida Ojha

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.

 Step1: Create a password file for the duplicate instance

orapwd file=/u01/app/oracle/product/9.2.0.1.0/dbs/orapwDUP password=password entries=10

Step2: add the appropriate entries into the tnsnames.ora and listener.ora files in the $ORACLE_HOME/network/admin directory. Remember to load the new configuration into the listener:

# Added to the listener.ora SID_LIST
(SID_DESC =
  (ORACLE_HOME = /u01/app/oracle/product/9.2.0.1.0)
  (SID_NAME = DUP)
)

# Added to the tnsnames.ora
DUP =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)
(HOST = server1.tshcomputing.com)(PORT = 1521))
    )
    (CONNECT_DATA =
      (ORACLE_SID = DUP)
    )
  )

# Reload listener
lsnrctl reload
create an init.ora file for the duplicate database. Since we are duplicating the database onto the same server as the original we must convert the file
names so there is no conflict:
# Minimum Requirement.
DB_NAME=DUP
CONTROL_FILES=(/u02/oradata/DUP/control01.ctl,
               /u02/oradata/DUP/control02.ctl,
               /u02/oradata/DUP/control03.ctl)

# Convert file names to allow for different directory structure.
DB_FILE_NAME_CONVERT=(/u02/oradata/TSH1/,/u02/oradata/DUP/)
LOG_FILE_NAME_CONVERT=(/u01/oradata/TSH1/,/u01/oradata/DUP/)

# make sure block_size and compatible parameters
# match if you are not using the default.
DB_BLOCK_SIZE=8192
COMPATIBLE=9.2.0.0.0
Next we connect to the duplicate instance:
ORACLE_SID=DUP; export ORACLE_SID
sqlplus /nolog
conn / as sysdba
Next we create an SPFILE based on the init.ora:
CREATE SPFILE FROM PFILE='/u01/app/oracle/admin/DUP/pfile/init.ora';
Next we start the database in NOMOUNT mode:
STARTUP FORCE NOMOUNT;
With the duplicate database started we can now connect to it from RMAN. 
For the duplication to work we must connect to the original database 
(TARGET), the recovery catalog (CATALOG) and our duplicate database 
(AUXILIARY): 
ORACLE_SID=DUP; export ORACLE_SID
rman TARGET sys/password@tsh1 CATALOG rman/rman@tshadm AUXILIARY /
We can then dupicate the database using one of the following commands:
# Duplicate database to TARGET's current state.
DUPLICATE TARGET DATABASE TO DUP;

# Duplicate database to TARGET's state 4 days ago.
DUPLICATE TARGET DATABASE TO DUP UNTIL TIME 'SYSDATE-4';
The time it takes to complete varies depending on the size of the database and the specification of the server. Once the process 
is finished RMAN produces a completion message and you have your duplicate instance.
Comments