Introduction Use the DUPLICATE command to create a copy of a source database. RMAN can create either of the following types of databases: A duplicate database, which is a copy of the source database (or a subset of the source database) with a unique DBID. Because a duplicate database has a unique DBID, it is independent of the source database and can be registered in the same recovery catalog. Typically, duplicate databases are used for testing. A standby database, which is a special copy of the source database (called a primary database in a Data Guard environment) that is updated by applying archived redo log files from the primary database. A standby database is not assigned a new DBID. Prerequisites 1. Backup should be taken. 2. RMAN must be connected as TARGET to the source database, which is the database that is being copied. The source database must be mounted or open. The source database must not be a standby database. 3. RMAN must be connected as AUXILIARY to the instance of the duplicate database. The instance of the duplicate database is called the auxiliary instance. The auxiliary instance must be started with the NOMOUNT option. Prerequisites Specific to Backup-Based Duplication 1. When you execute DUPLICATE without FROM ACTIVE DATABASE, at least one auxiliary channel is required, but no normal channels are required in the source database. 2. When you duplicate the database from backups, all backups and archived redo logs used for creating and recovering the duplicate database must be accessible by the server session on the destination host. If the destination host is not the same as the source host, then you must make backups on disk on the source host available to the destination host with the same full path name as in the source database. RMAN can perform the duplication in any of the following supported modes: 1. Active duplication 2. RMAN duplicates the files directly from either an open or mounted database. 3. Backup-based duplication without a target connection 4. RMAN creates duplicate files from pre-existing RMAN backups and copies. The DUPLICATE command must have been issued with the DATABASE clause. This form requires a connection to an auxiliary instance and a recovery catalog. 5. This mode is useful when the target database is not available or a connection to it is not desirable (as mandated by security policy restrictions or a firewall). 6. Backup-based duplication with a target connection. 7. RMAN creates duplicate files from pre-existing RMAN backups and copies. 8. Backup-based duplication without connection to target and recovery catalog 9. RMAN creates duplicate files from RMAN backups and copies that were placed in a designated BACKUP LOCATION. Procedure 1. Create Listener for the Database and add the entry of the following SID_LIST_LISTENER_TEST = (SID_LIST = (SID_DESC = (SID_NAME = TEST) (ORACLE_HOME = /oracle/product/11.2.0/dbhome_1) ) )
2. Make entry in tnsnames.ora TEST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.10.10)(PORT = 1529)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = TEST) ) )
3. Create an Oracle password file for the auxiliary instance. $orapwd file=/oracle/product/11.2.0/dbhome_1/dbs/orapwTEST password=<passwd> entries=10
4. Create an initialization parameter file for the auziliary instance and make the following changes. SQL> create pfile='/oracle/product/11.2.0/dbhome_1/dbs/initTEST.ora' from spfile; File created.
5. Create directories necessary to start the duplicate database. $mkdir p /data9/tbs/TEST/ $mkdir p /data9/redo/TEST/ $mkdir p /data9/controlfile/TEST/
$mkdir p /data10 /tbs/TEST/ $mkdir p /data10 /redo/TEST/ $mkdir p /data10 /controlfile/TEST/
$mkdir p /index5/tbs/TEST/ $mkdir p /index5/redo/TEST/ $mkdir p /index5/controlfile/TEST/
$mkdir p /archive4/archives/TEST
$mkdir p /oracle/admin/TEST/adump
6. Connect to the auxiliary instance. $ORACLE_SID=TEST; export ORACLE_SID $ sqlplus / as sysdba 7. Start the auxiliary instance with SQL*Plus. SQL> STARTUP NOMOUNT pfile='/oracle/product/11.2.0/dbhome_1/initTEST.ora; ORACLE instance started. Total System Global Area 1.2827E+10 bytes Fixed Size 2233480 bytes Variable Size 7583304568 bytes Database Buffers 5234491392 bytes Redo Buffers 7340032 bytes SQL>
8. Connect to RMAN $rman auxiliary sys/<passwd>@TEST run { allocate auxiliary channel c1 type disk; allocate auxiliary channel c2 type disk; set newname for datafile 1 to '/data9/tbs/TEST/system01.dbf'; set newname for datafile 2 to '/data9 /tbs/TEST/sysaux01.dbf'; set newname for datafile 3 to '/data9 /tbs/TEST/undotbs01.dbf'; set newname for datafile 4 to '/data9 /tbs/TEST/users01.dbf'; set newname for datafile 33 to '/data9/tbs/TEST/undotbs02.dbf'; set newname for tempfile 1 to '/data9/tbs/TEST/temp01.dbf'; duplicate target database to TEST backup location '/backup5/rmanbkp/08052014'; }
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 Duplicate Db at 09-MAY-14
contents of Memory Script: { sql clone "create spfile from memory"; } executing Memory Script
contents of Memory Script: { set until scn 426152786; set newname for datafile 1 to "/data9/tbs/TEST/system01.dbf"; set newname for datafile 2 to "/data9/tbs/TEST/sysaux01.dbf"; set newname for datafile 3 to "/data9/tbs/TEST/undotbs01.dbf"; set newname for datafile 4 to "/data9/tbs/TEST/users01.dbf"; set newname for datafile 33 to "/data9/tbs/TEST/undotbs02.dbf"; restore clone database ; } executing Memory Script
executing command: SET until clause 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 09-MAY-14
channel c1: starting datafile backup set restore channel c1: specifying datafile(s) to restore from backup set channel c1: restoring datafile 00001 to /data9/tbs/TEST/system01.dbf channel c1: restoring datafile 00003 to /data9/tbs/TEST/undotbs01.dbf channel c1: restoring datafile 00033 to /data9/tbs/TEST/undotbs02.dbf channel c1: reading from backup piece /backup5/rmanbkp/08052014/SRCTEST_T847062007_S7151.bkp channel c1: piece handle=/backup5/rmanbkp/08052014/SRCTEST_T847062007_S7151.bkp tag=TAG20140508T230007 channel c1: restored backup piece 1 channel c1: restore complete, elapsed time: 00:03:45 channel c1: starting datafile backup set restore channel c1: specifying datafile(s) to restore from backup set channel c1: restoring datafile 00002 to /data9/tbs/TEST/sysaux01.dbf channel c1: restoring datafile 00004 to /data9/tbs/TEST/users01.dbf
contents of Memory Script: { sql clone "alter system set db_name = ''TEST'' comment= ''Reset to original value by RMAN'' scope=spfile"; sql clone "alter system reset db_unique_name scope=spfile"; shutdown clone immediate; startup clone nomount; } executing Memory Script
sql statement: alter system set db_name = ''TEST'' comment= ''Reset to original value by RMAN'' scope=spfile
sql statement: alter system reset db_unique_name scope=spfile
Oracle instance shut down
connected to auxiliary database (not started) Oracle instance started
Total System Global Area 12827369472 bytes
Fixed Size 2233480 bytes Variable Size 7616859000 bytes Database Buffers 5200936960 bytes Redo Buffers 7340032 bytes allocated channel: c1 channel c1: SID=156 device type=DISK allocated channel: c2 channel c2: SID=189 device type=DISK sql statement: CREATE CONTROLFILE REUSE SET DATABASE "TEST" RESETLOGS ARCHIVELOG MAXLOGFILES 40 MAXLOGMEMBERS 3 MAXDATAFILES 100 MAXINSTANCES 8 MAXLOGHISTORY 18688 LOGFILE GROUP 1 ( '/index5/redo/TEST/redo01b.log', '/data9/redo/TEST/redo01a.log' ) SIZE 50 M REUSE, GROUP 2 ( '/data9/redo/TEST/redo02b.log', '/data10/redo/TEST/redo02a.log' ) SIZE 50 M REUSE, GROUP 3 ( '/index5/redo/TEST/redo03a.log', '/data10/redo/TEST/redo03b.log' ) SIZE 50 M REUSE, GROUP 4 ( '/data9/redo/TEST/redo04a.log', '/index5/redo/TEST/redo04b.log' ) SIZE 50 M REUSE, GROUP 5 ( '/data10/redo/TEST/redo05a.log', '/data9/redo/TEST/redo05b.log' ) SIZE 50 M REUSE, GROUP 6 ( '/index5/redo/TEST/redo06a.log', '/data10/redo/TEST/redo06b.log' ) SIZE 50 M REUSE DATAFILE '/data9/tbs/TEST/system01.dbf' CHARACTER SET WE8ISO8859P1
contents of Memory Script: { set newname for tempfile 1 to "/data9/tbs/TEST/temp01.dbf"; set newname for tempfile 2 to "/data9/tbs/TEST/temp_TEST_01.dbf"; switch clone tempfile all; catalog clone datafilecopy "/data9/tbs/TEST/sysaux01.dbf", "/data9/tbs/TEST/undotbs01.dbf", "/data9/tbs/TEST/users01.dbf", "/data9/tbs/TEST/undotbs02.dbf", switch clone datafile all; switch clone datafile 2 to datafilecopy "/data9/tbs/TEST/sysaux01.dbf"; switch clone datafile 3 to datafilecopy "/data9/tbs/TEST/undotbs01.dbf"; switch clone datafile 4 to datafilecopy "/data9/tbs/TEST/users01.dbf"; switch clone datafile 33 to datafilecopy "/data9/tbs/TEST/undotbs02.dbf"; } executing Memory Script
executing command: SET NEWNAME
renamed tempfile 1 to /data9/tbs/TEST/temp01.dbf in control file