RMAN DUPLICATE DATABASE CLONING

We have already learned manual hot backup cloning.Now we will provide the cloning steps through RMAN DUPLICATE DATABASE. RMAN provides the DUPLICATE command, which uses the backups of the database to create the clone database. Files are restored to the target database, after which an incomplete recovery is performed and the clone database is opened using RESETLOGS option. All the preceding steps are performed automatically by RMAN without any intervention from the DBA.

The high level steps for RMAN DUPLICATE DATABASE CLONING
1) Take the RMAN backup of the database to be cloned
2) Copy all the backup files to the destination server
3) Create the tnsnames.ora and init.ora files
4) Startup mount the database and run duplicate command to clone the database

Let us take an example

Source Database Name: TEST
Source Database physical files path=/u001/oracle/TEST/oradata
Source Server Name: mygoeasy1

Cloned Database Name: TEST_NEW
Target Database physical files path=/u001/oracle/TEST_NEW/oradata
Source Server Name: mygoeasy1

Detailed Steps for RMAN DUPLICATE DATABASE CLONING
Step 1

a) Find out the path and names of datafiles.
SQL> select name from v$datafile;

b) Backup the parameter file
If ‘TEST’ database is using spfile create pfile,
SQL> create pfile=’/tmp/initTEST.ora’ from spfile;
If database is using pfile, use OS command to copy the pfile to a new server location.

c)
SQL> alter system switch logfile;
SQL> archive log list;

select SEQUENCE#,ARCHIVED,STATUS from v$log where STATUS = ‘ACTIVE’;

d. Take the RMAN backup of the database

$ rman target=/

RMAN> CONFIGURE CONTROLFILE AUTOBACKUP ON;
RMAN> BACKUP DATABASE PLUS ARCHIVELOG

The above command will take the backup of the database and archive log files . First It will take the archive log backup then datafile backup and then again final archive log backup. I am assuming here flash recovery area is set on the source database. All the backup pieces will stored there

Step 2

Copy all backup peices of ‘TEST’ database to a Destination location location.
$scp -r oracle@mygoeasy2:/u01/app/oracle/recovery_area/TEST/archivelog /u01/app/oracle/recovery_area/TEST
$ scp -r oracle@mygoeasy2:/u01/app/oracle/recovery_area/TEST/backupset /u01/app/oracle/recovery_area/TEST
$ scp -r oracle@mygoeasy2:/u01/app/oracle/recovery_area/TEST/autobackup /u01/app/oracle/recovery_area/TEST

We are keeping same location of backup on Source and destination server. Incase it is different, we need to specify the location in duplicate command
Step 3

On the Destination node

a) Copy the backup init.ora to the $ORACLE_HOME/dbs and then change the db_name,control file paths ,dump parameter and other things as neccessary

$ cd $ORACLE_HOME/dbs
$ vi initTEST_NEW.ora
db_name=TEST_NEW
control_files=/u001/oracle/TEST_NEW/oradata
….

We need to put the two below parameter extra for RMAN cloning

db_file_name_convert=(‘/u001/oracle/TEST/oradata’,’/u001/oracle/TEST_NEW/oradata’)
# This parameter specifies from where to where the datafiles should be cloned
log_file_name_convert=(‘/u001/oracle/TEST/oradata’,’/u001/oracle/TEST_NEW/oradata’)

NOTE: db_file_name_convert and log_file_name_convert parameters are required only if the source database directory structure and clone database directory structure differs.

Step 4

Configure the tnsnames.ora at the destination server
TEST_NEW =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST =mygoeasy2)(PORT = 1529))
)
(CONNECT_DATA =
(SERVICE_NAME = TEST_NEW)
)
)

TEST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST =mygoeasy1)(PORT = 1529))
)
(CONNECT_DATA =
(SERVICE_NAME = TEST)
)
)

Step 5.

Startup the database in NOMOUNT stage and start the duplicate

rman target sys/oracle@TEST auxiliary sys/oracle@TEST_NEW

RMAN> duplicate target database to ‘TEST_NEW’;
The preceding command restores all files from the backup of the target database to the clone database destination using all available archive log files and also RMAN opens the clone database with resetlogs option.