How to perform Database cloning

What is Database cloning:
A database clone is a complete and separate copy of a database system that includes the business data , the DBMS software and any other application tiers that make up the environment. The cloning can be done on same host or seperate host.

What is the need of Database cloning?

Cloning may be required for several reasons
1) Create a test env which is replica of Production. IT and Buisness can test the things before moving the changes to Production
2) Create a temporary env to recover the dropped table on Production.Suppose a user drop a table by mistake in Production. We can restore the Production backup on the seperate host and recover before the table drop to recover the table data. Then this table can be imported in Production
3) Many times system which hosts the database get retired then at that we need to reclocate the database to the new host.
4) Creating another Production env from the existing production

There could be many more things.
How the Database cloning is performed?

There are two parts of cloning
1) Oracle software cloning

2) Database  cloning basically the datafiles  and instance

We will specifically talk about DBMS software cloning in this post


How to clone DBMS software

Prerequiste: Please note that Perl 5.6 or higher is required when cloning Oracle11g Release 2.

Step 1 : Create a tarball of the source home

tar -cvf /tmp/clone_oracle.tar .

and copy it to the target host

Some points to note
1) Do not use the command “tar cvf /tmp/clone_oracle.tar $ORACLE_HOME” because the full path for the $ORACLE_HOME will be included in the clone_oracle.tar file and this will cause issues while extracting the tar files on the target note
2) There should be no requirement to shutdown any databases, listeners, agents etc. that are running from the source home before copying the source installation because any processes that load the static binaries or libraries into memory should not hold a write lock.
3) If you can run the tar with root owner,then it would be great as the permission and time would be preserved
We can also use cp or rcp in case tar is easily available, use -p option to preserved timestamp

For example:

cp -Rp /u064/app/oracle/11.2.0 /u01/app/oracle//11.2.0_clone

NOTE: This command can be executed by either the ‘root’ user or the owner of the $ORACLE_HOME (for example, ‘oracle’). The intention is to make sure that the ownership of the files is preserved correctly. Some files in $ORACLE_HOME/bin are owned by root and have the SUID / SGID set:

-rws–x— 1 root oinstall 20872 Apr 24 12:00 nmb
-rws–x— 1 root oinstall 28720 Apr 24 11:59 nmo
-rwsr-x— 1 root oinstall 1340408 Sep 25 2011 oradism

Step 2) Untar the tarball into the target location

cd <location>
tar -xvf /tmp/clone_oracle.tar

Again it would be good ,if it can be done with root user

Few things to check after the unpacking

1) If the target host username/group is different, the change the file owner and group
find . -user <UserA> -exec chown <userB> {} \;
find . -group <groupA> -exec chgrp <groupB> {} \;

2) check that the validity of any symbolic links has been preserved. Ensure that the links point to files/directories in the new target home, not files/directories in the source home. If necessary, re-create the links.

3) If you are cloning on AIX, make sure that the script has been executed on the target server. This can be found on the Oracle11g Release 2 media.
Step 3) Run the following command to clone the installation with the Oracle Universal Installer (OUI):

cd $ORACLE_HOME/clone/bin
perl ORACLE_HOME=”<target_home>” ORACLE_HOME_NAME=”<unique_home_name>” ORACLE_BASE=”<path_for_ORACLE_BASE>” OSDBA_GROUP=<OSDBA_privileged_group> OSOPER_GROUP=<OSOPER_privileged_group>

Important points to check
1) OSDBA_GROUP and OSOPER_GROUP can be ignored if the source and target OS username and group are same
If it is different,then it is very important to specify it otherwise you may experience an ORA-1031 error when using SQL*Plus
2) If no /etc/oraInst.loc (AIX, Linux) or /var/opt/oracle/oraInst.loc (Solaris, HP-UX) file exists on the server because Oracle has never been installed on the server before, create one. The file should contain a line like this:


For example:


If an oraInst.loc file exists on the server but is in a different location, edit the $ORACLE_HOME/clone/config/ file to add “-invPtrLoc <path>/oraInst.loc” to the clone_command_line.

This file can also be edited to add “-ignoreSysPrereqs” if required.

The alternative method of cloning is to use the following commands:

./runInstaller -clone -silent -ignorePreReq ORACLE_HOME=”<target_home>” ORACLE_HOME_NAME=”<unique_home_name>” ORACLE_BASE=”<path_for_ORACLE_BASE>” oracle_install_OSDBA=OSDBA_privileged_group oracle_install_OSOPER=OSOPER_privileged_group

If necessary, add “-invPtrLoc <path>/oraInst.loc” or “-ignoreSysPrereqs” to the command line.

3) If the server has more than one Perl version installed then it may be necessary to specify the PERL5LIB environment variable so that the versions of the Perl modules match with the Perl version used.

Note that the full path for the target ORACLE_HOME should be provided

4) ORACLE_HOME_NAME name must be unique (that is, it must not already exist in the central inventory file <path>/oraInventory/ContentsXML/inventory.xml).

NOTE: if you are cloning on a server which already has a central inventory and the target home already exists in <path>/oraInventory/ContentsXML/inventory.xml then you should run the following command to ‘detach’ this home from the central inventory before performing the clone operation:

./runInstaller -detachHome ORACLE_HOME=<target_home>

To clone an Oracle11g Release 2 client installation, run OUI directly:

./runInstaller -clone -silent -noconfig ORACLE_HOME=”<target_home>” ORACLE_HOME_NAME=”<unique_home_name>” ORACLE_BASE=”<path_for_ORACLE_BASE>” OSDBA_GROUP=OSDBA_privileged_group OSOPER_GROUP=OSOPER_privileged_group

Step 4

On Unix/Linux installations, you will now need to run (as root) from the target home.

NOTE: When running the in the clone it overwrites the files in /usr/local/bin (oraenv, coraenv, dbhome). It does not prompt if those files are to be overwritten or give a choice (as in a clean install). These files should be backed up if used.

FAQ about DBMS software cloning

Question 1: Do the source and the destination path (of the Oracle Home to be cloned) need to be the same ?

Answer: The source and the destination path (of the Oracle Home to be cloned) need not be the same.It can be different

Question 2: Are all the changes made by applying one-off patches or PSU or CPU on the source Oracle Home also present after the clone operation?

Answer: Yes, all the changes made by applying one-off patches or PSU or CPU on the source Oracle Home are also present after the clone operation.

Question 3: Can I use the cloned Oracle Home as the source for another cloning operation ?

Answer: Yes, you can also use the cloned Oracle Home as the source for another cloning operation. The cloned installation behaves the same as the source installation. For example, the cloned Oracle Home can be removed using OUI or patched using OPatch.

Question 4: Can I clone the Oracle Home across platforms?

Answer: No, cloning across platforms is not possible because the binaries across platforms are different . So you cannot copy the binary from solaris to linux

Question 5: Can you clone the Oracle Home across different OS versions ?

Answer:Yes, cloning across OS versions is possible provided the Oracle version is certified on the respective OS version.