You are on page 1of 10

What is Cloning?

Database Cloning is a procedure that can be used to create an identical copy of


the existing Oracle database. DBA s sometimes need to clone databases to test back
up and recovery strategies or export a table that was dropped from the productio
n database and import it back into the production database. Cloning can be done
on separate hosts or on the same host and is different from standby database.
Reason for Cloning
In every oracle development and production environment there will become the nee
d to transport the entire database from one physical machine to another. This co
py may be used for development, production testing, beta testing, etc, but rest
assured that this need will arise and management will ask you to perform this ta
sk quickly. Listed below are the most typical uses:

1.
Relocating an Oracle database to another machine.
2.
Moving Oracle database to new Storage media.
3.
Renaming Oracle database.

Database Cloning can be done using the following methods,


1.
Cold Cloning
2.
Hot Cloning
3.
Cloning using RMAN

Here is a brief explanation how to perform cloning in all these three methods

METHOD 1: COLD CLONING


Cold Cloning is one the reliable methods that is done using the Cold Backup. The
drawback of this method is that the database has to be shutdown while taking th
e cold backup.
Considerations:
Source Database Name: RIS
Clone Database Name: RISCLON
Source Database physical files path=/u01/RIS/oradata
Cloned Database physical files path=/u02/RISCLON/oradata
Steps to be followed:
1.
Startup the source database (if not open)
$ export ORACLE_SID=RIS
$ sqlplus / as sysdba
SQL> startup

2.
Find out the path and names of datafiles, control files, and redo log file
s.
SQL> select name from v$datafile;
SQL> select member from v$logfile;
SQL> select name from v$controlfile;

3.
Take the control file backup.
SQL> alter database backup controlfile to trace;

4.
Parameter file backup.
If RIS database is using spfile,
SQL> create pfile= /u02/RISCLON/initRISCLON.ora from spfile;

If database is using pfile, use OS command to copy the pfile to a backup l


ocation.
5.
Shutdown the RIS database
SQL> shutdown

6.
Copy all data files, control files, and redo log files of RIS database to a
target database location.
$ mkdir /u02/RISCLON/oradata
$ cp /u01/RIS/oradata/* /u02/RISCLON/oradata/
7.
Create appropriate directory structure in clone database for dumps and spe
cify them in the parameter file.
$ mkdir -p /u02/RISCLON/{bdump,udump}

8.
Edit the clone database parameter file
$ cd /u02/RISCLON/
$ vi initYASHCLON.ora
db_name=RISCLON
control_files=/u02/RISCLON/oradata/cntrl01.ctl
background_dump_dest=/u02/RISCLON/bdump
user_dump_dest=/u02/RISCLON/udump
. . .
. . .
:wq!

9.
Startup the clone database in NOMOUNT stage.
$ export ORACLE_SID=RISCLON
SQL> startup nomount pfile= /u02/RISCLON/initYASHCLON.ora

10.
Create the control file for the clone database using the trace control fil
e and specify the appropriate paths for redolog and datafiles.
CREATE CONTROLFILE SET DATABASE RISCLON RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 /u02/RISCLON/oradata/redo01.log SIZE 5M,
GROUP 2 /u02/RISCLON/oradata/redo02.log SIZE 5M,
DATAFILE
/u02/RISCLON/oradata/system01.dbf ,
/u02/RISCLON/oradata/undotbs01.dbf ,
/u02/RISCLON/oradata/sysaux01.dbf ,
/u02/RISCLON/oradata/users01.dbf ,
/u02/RISCLON/oradata/example01.dbf
CHARACTER SET AL32UTF8

11.
Create the control file by running from the trace
SQL> @u01/RIS/source/udump/cntrl.sql

12.
Once the control file s successfully created, open the database with resetlo
gs option.
SQL> alter database open resetlogs;

METHOD 2: HOT CLONING


Hot database cloning is more suitable for databases which are running 24X7X365 t
ype of databases and is done using the hot backup. For hot database cloning, dat
abase has to be in archivelog mode and there no need to shutdown the database.
Considerations:
Source Database Name: RIS
Clone Database Name: RISCLON
Source Database physical files path=/u01/RIS/oradata
Cloned Database physical files path=/u02/RISCLON/oradata
Steps to be followed:
1. Find out the path and names of datafiles.
SQL> select name from v$datafile;

2. Parameter file backup.


If RIS database is using spfile,
SQL> create pfile= /u02/RISCLON/initYASHCLON.ora from spfile;

If database is using pfile, use OS command to copy the pfile to a backup locatio
n.

3. Note down the oldest log sequence number.


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

4. Place the database to backup mode


SQL> alter database begin backup;

5. Copy all data files of RIS database to a clone location.


$ mkdir /u02/RISCLON/oradata
$ cp /u01/RIS/source/oradata/*.dbf /u02/RISCLON/oradata/

6. After copying all datafiles, release the database from backup mode.
SQL> alter database end backup;

7. Switch the current log file and note down the oldest log sequence number
SQL> alter system switch logfile;
SQL> archive log list;

8. Copy all archive log files generated during FIRST old log sequence no. to the
LAST old log sequence no. during which the database was in backup mode.

9. Take the control file backup.


SQL> alter database backup controlfile to trace;

10. Create appropriate directory structure for the clone database and specify th
e same
$ cd /u02/RISCLON
$ mkdir bdump udump

11. Edit the clone database parameter file


$ cd /u02/RISCLON
$ vi inityashcln.ora
db_name=RISCLON
control_files=/u02/RISCLON/oradata/cntrl01.ctl
background_dump_dest=/u02/RISCLON/bdump
user_dump_dest=/u02/RISCLON/udump
. . .
. . .
:wq!

12. Startup the cloned database in NOMOUNT stage.


$ export ORACLE_SID=RISCLON
SQL> startup nomount pfile= /u02/RISCLON/initRISCLON.ora

13. Create the control file for the clone database using the trace control file.
CREATE CONTROLFILE SET DATABASE RISCLON RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 /u02/RISCLON/oradata/redo01.log SIZE 5M,
GROUP 2 /u02/RISCLON/oradata/redo02.log SIZE 5M,
DATAFILE
/u02/RISCLON/oradata/system01.dbf ,
/u02/RISCLON/oradata/undotbs01.dbf ,
/u02/RISCLON/oradata/sysaux01.dbf ,
/u02/RISCLON/oradata/users01.dbf ,
/u02/RISCLON/oradata/example01.dbf
CHARACTER SET AL32UTF8;

14. Create the control file by running from the trace


SQL> @u01/RIS/source/udump/cntrl.sql

15. Recover the database using backup controlfile option.


SQL> recover database using backup controlfile until cancel;

16. You will be prompted to feed the archive log files henceforth. Specify the a
bsolute path and file name for the archive log files and keep feeding them until
you cross the LAST old sequence no. (Refer: Step 8), type CANCEL to end the med
ia recovery.

17. Open the database with resetlogs option.


SQL> alter database open resetlogs;

METHOD 3 : RMAN CLONING


RMAN provides the DUPLICATE command, which uses the backups of the database to c
reate the clone database. Files are restored to the target database, after which
an incomplete recovery is performed and the clone database is opened using RESE
TLOGS option. All the preceding steps are performed automatically by RMAN withou
t any intervention from the DBA.
Considerations:
Source Database Name: RIS
Clone Database Name: RISCLON
Source Database physical files path=/u01/RIS/oradata
Cloned Database physical files path=/u02/RISCLON/oradata
Steps to be followed:
1. Parameter file backup.
If RIS database is using spfile,
SQL> create pfile= /u02/RISCLON/initRISCLON.ora from spfile;

If database is using pfile, use OS command to copy the pfile to a backup locatio
n.

2. Create appropriate directory structure for the clone database


$ cd /u02/RISCLON
$ mkdir bdump udump

3. Edit the clone database parameter file


$ cd /u02/RISCLON
$ vi initRISCLON.ora
db_name=RISCLON
control_files=/u02/RISCLON/oradata/cntrl01.ctl

db_file_name_convert=( /u01/RIS/oradata ,'/u02/RISCLON/oradata )


# This parameter specifies from where to where the datafiles should be cloned
log_file_name_convert=( /u01/RIS/oradata ,'/u02/RISCLON/oradata )
# This parameter specifies from where to where the redologfiles should be cloned
background_dump_dest=/u02/RISCLON/bdump
user_dump_dest=/u02/RISCLON/udump
. . .
. . .
:wq!

NOTE: db_file_name_convert and log_file_name_convert parameters are required onl


y if the source database directory structure and clone database directory struct
ure differs.

4. Configure the listener using listener.ora file and start the listener
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = RIS)
(ORACLE_HOME = /u01/oracle/product/10.2.0/db_1/)
(SID_NAME =RIS)
)
(SID_DESC =
(GLOBAL_DBNAME = RISCLON)
(ORACLE_HOME = /u02/oracle/product/10.2.0/db_1/)
(SID_NAME =RISCLON)
)
)

5. Add the following information to the tnsnames.ora file.


con_RISCLON =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 200.168.1.22)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = RISCLON)
)
)

6. Startup the database in NOMOUNT stage and exit.


$ export ORACLE_SID=RISCLON
SQL> startup nomount pfile= /u02/RISCLON/initRISCLON.ora
SQL> exit

7. Start RMAN, make RIS as target and RISCLON as auxiliary.


$ export ORACLE_SID=RIS
SQL> rman target / auxiliary sys/sys@con_RISCLON

8. Issue the RMAN DUPLICATE command to start the cloning process.


RMAN> duplicate target database to RISCLON ;

NOTE: The preceding command restores all files from the backup of the target dat
abase to the clone database destination using all available archive log files an
d also RMAN opens the clone database with resetlogs option.

You might also like