Clone database with RMAN (Duplicate database)
                                                 Last update (2013-12-18 10:18:49)
                                                                                                                   Date added (2009-11-11 14:18:53)

RMAN can be used to duplicate, or clone, a database from a previous full online backup. The clone can be done in the same server or on a remote server.

Here I will demonstrate how to do it, with Oracle9i (or Oracle8i, Oracle10g, Oracle11g), RMAN and on a remote server with different filesystems.

Prepare the environment on the remote server
In order to make the clone on the new remote server you must set up:
1. A new unix user with the same privileges like the production unix user. 
   A profile for the unix user with $ORACLE_HOME, $PATH, $TNS_ADMIN, $ORACLE_SID

2. Copy the $ORACLE_HOME binaries from the production server to the new remote server.
    This will be your new $ORACLE_HOME for the clone. Relink to make it valid!

3. Add alias entries in tnsnames.ora for production database, duplicate database and catalog database.

    In the example the production database is ANDR
    DUP will be the clone (duplicate) and
    RMAN is the rman catalog database.

    (ADDRESS = (PROTOCOL = TCP)(HOST = crmcc)(PORT = 1521))
      (SID = ANDR)))

    (ADDRESS = (PROTOCOL = TCP)(HOST = rp1dev)(PORT = 1551))
      (SID = DUP)))

    (ADDRESS = (PROTOCOL = TCP)(HOST = bserver)(PORT = 1521))
      (SID = RMAN)))

check that you can tnsping the aliases, for example:
$ tnsping RMAN

4. Add a new listener.ora on the remote server and start the listener
    $ lsnrctl start DUP

   A listener example configuration file follows:

# LISTENER.ORA Network Configuration File: /ora1/androm/9.2.0/network/admin/listener.ora
# Generated by Oracle configuration tools.

    (ADDRESS = (PROTOCOL = TCP)(HOST = rp1dev)(PORT = 1551)))

    (SID_DESC =
      (ORACLE_HOME = /orandr/ANDR/9.2.0)
      (SID_NAME = DUP)))

5. Create on the new server the paths for the following:
    a. for the new controlfiles
    b. for the new datafiles
    c. for the new redologs
    d. for the new trace files

6. Create a new init.ora file for the process on the remote server at $ORACLE_HOME/dbs location
   Now you have to create the initDUP.ora, at $ORACLE_HOME/dbs. Follow the example:

db_name = "DUP"
instance_name = DUP
control_files = (/orandr/ANDR/controlfiles/control01.ctl, /orandr/ANDR/controlfiles/control02.ctl)
db_block_size = 8192
compatible =
background_dump_dest = '/orandr/ANDR/9.2.0/admin/DUP/bdump/'
user_dump_dest = '/orandr/ANDR/9.2.0/admin/DUP/udump/'
core_dump_dest = '/orandr/ANDR/9.2.0/admin/DUP/cdump/'
undo_management = 'AUTO'

Tip: In case you use Oracle11g then set the parameter:

control_files is where the new controlfiles will be created

db_file_name_convert are the matching pairs of production database filesystems to the clone filesystems.

for example if at the production database server the datafiles where stored in 3 filesystems


then you must create 3 filesystems also in the new server, lets say:


and the parameter db_file_name_convert will be:

db_file_name_convert=(/production/oradata1/, /clone/oradata1/, 
/production/oradata2/, /clone/oradata2/, 
/production/oradata3/, /clone/oradata3/)

log_file_name_convert are the matching pairs of production redologs filesystems to the redologs of clone filesystems.
It is the same concept like the parameter db_file_name_convert.

After setting new $ORACLE_HOME, $ORACLE_SID, $PATH for the new clone execute on the remote server the following:
sqlplus "/ as sysdba"
STARTUP nomount PFILE=$ORACLE_HOME/dbs/initDUP.ora
exit sqlplus and run from the shell
rman TARGET sys/*****@ANDR CATALOG rman/****@RMAN AUXILIARY / 

Recovery Manager: Release - 64bit Production

Copyright (c) 1995, 2002, Oracle Corporation.  All rights reserved.

connected to target database: ANDR (DBID=1620364522)
connected to recovery catalog database
connected to auxiliary database: DUP (not mounted)

allocate auxiliary channel ch01 TYPE 'SBT_TAPE';
allocate auxiliary channel ch02 TYPE 'SBT_TAPE';
allocate auxiliary channel ch03 TYPE 'SBT_TAPE';
send 'NB_ORA_CLIENT=crmcc';
SET until time "To_Date('23-JUL-2013 17:10:00','DD-MON-YYYY HH24:MI:SS')";

In case you have Oracle11g then use:

RUN { 
allocate auxiliary channel ch01 type 'SBT_TAPE' parms="ENV=(NB_ORA_POLICY=CRMCC_ANDR_ONLINE,NB_ORA_CLIENT=crmcc)";
allocate auxiliary channel ch02 type 'SBT_TAPE' parms="ENV=(NB_ORA_POLICY=CRMCC_ANDR_ONLINE,NB_ORA_CLIENT=crmcc)";
allocate auxiliary channel ch03 type 'SBT_TAPE' parms="ENV=(NB_ORA_POLICY=CRMCC_ANDR_ONLINE,NB_ORA_CLIENT=crmcc)";
SET until time "To_Date('23-JUL-2013 17:10:00','DD-MON-YYYY HH24:MI:SS')";

*** NB_ORA_CLIENT=crmcc is the production server!

if you get errors like this
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ==========================================================
RMAN-03009: failure of allocate command on ch01 channel at 07/05/2010 15:51:45
ORA-19554: error allocating device, device type: SBT_TAPE, device name: 
ORA-27211: Failed to load Media Management Library
Additional information: 2

then go to /usr/openv/netbackup/bin and run the script 
$ oracle_link
Note: Before you run the duplicate rman script you may have to
Find which media tapes have the latest backup
so you can attach them directly to the server

The script steps executed in RMAN can be found here :
Rman output script for creating DUPLICATE database

The contents of alert log while doing the Clone can be found here:
Alert log contents while cloning with RMAN

Usually get this error after the cloning:
ORA-01552: cannot use system rollback segment for non-system tablespace
Oracle DBA-> (147)
  Alertlog (3)
  Archivelog (5)
  Auditing (1)
  Backup - Recovery (19)
  Database files (6)
  Database options (2)
  DB links (2)
  Dependencies (1)
  Dictionary (2)
  Exp-Imp Datapump (6)
  Jobs (2)
  Mview (2)
  Networking (3)
  Objects (7)
  Parameters (2)
  Redologs (6)
  Roles - Grants (2)
  Rollback - Undo (8)
  Segments (3)
  Sequences (2)
  Sessions (14)
  SGA (14)
  Tables (10)
  Tablespaces (10)
  Temp (4)
  Toad (5)
  Transactions (1)
  Upgrade (2)
  Users (3)
Oracle APPS DBA-> (66)
Exadata (1)
Performance Tuning-> (59)
Oracle Real Cases (24)
Oracle Errors (23)
Oracle SQL tricks (32)
Oracle RAC (3)
Oracle Security (8)