Skip to content

Insight and analysis of technology and business strategy

Oracle Silent Mode, Part 3: Cloning Software and Databases

This post is the third of the series of ten posts that explore some of the Oracle Universal Installer (OUI), Network Assistant (NETCA), Database Creation Assistant (DBCA), Database Upgrade Assistant (DBUA) and other syntaxes you can use to script or speed up Oracle Installations. The complete series should look like this:

  1. Installation of 10.2 And 11.1 Databases
  2. Patches of 10.2 And 11.1 databases
  3. Cloning Software and databases (this post!)
  4. Install a 10.2 RAC Database
  5. Add a Node to a 10.2 RAC database
  6. Remove a Node from a 10.2 RAC database
  7. Install a 11.1 RAC Database
  8. Add a Node to a 11.1 RAC database
  9. Remove a Node from a 11.1 RAC database
  10. A ton of other stuff you should know

In the first post and second post, we focused on how to leverage these tool to perform a standard installation and apply patches on top of 10.2 and 11.1 databases. This post will dig into the cloning features of both the Universal Install (OUI) and the Database Configuration Assistant (DBCA).

Foreword

The Universal Install and Database Configuration Assistant Cloning features enable you to:

  • Install the database software once, apply to it all the patches you need, including Patch Set, CPU, and One-Off patches, and create a “Gold Image” of that software you’ll be able to deploy on all the servers you need as soon as they run the same Operating System.
  • Create a database, apply all the scripts you need including the catupgrd.sql, the cpu.sql or any other script associated with patches. You can also run any script that will create a skeleton for installing your application, create tablespaces, create objects, or set parameters. Once done, you’ll be able to create a template from that database and to use it on any servers that run the same operating system and the same database software.

How to clone Oracle database software

You can refer to the product documentation for the whole database software cloning process:

The process is straightforward and consists of three different steps:

    1. Step 1: Compress the Whole ORACLE_HOME directory of your database software.

On Unix or Linux you can start by creating a file that will contains all the files to exclude from the tarball. We’ll assume you have a directory to store the clone of the ORACLE_HOME in $CLONE. The commands below create the file, $CLONE/excludeFilesFromTarball.txt.

$ export CLONE=/home/oracle/clone
$ cd $ORACLE_HOME
$ find . -name *.log |grep -v "./log" \
         >$CLONE/excludeFilesFromTarball.txt
$ find ./network/admin                \
         >>$CLONE/excludeFilesFromTarball.txt
$ find ./oc4j/j2ee/OC4J_DBConsole_*   \
         >>$CLONE/excludeFilesFromTarball.txt
$ find `hostname |cut -d "." -f 1`*_* \
         >>$CLONE/excludeFilesFromTarball.txt
$ # If you don't want to embbed the 
$ # DBCA templates, add the line below
$ find ./assistants/dbca/templates \
         >>$CLONE/excludeFilesFromTarball.txt

Once that file is created, you can use the tar command to create a tarball of the ORACLE_HOME as below:

$ tar -X $CLONE/excludeFilesFromTarball.txt -cvf - . | \
    gzip -c >$CLONE/myOracleHomeClone.tar.gz

Note that you don’t need to stop any of the services working on the ORACLE_HOME you clone to do this.

  • Step 2: Extract the files you’ve copied in the new ORACLE_HOME.This step consists in creating a new ORACLE_HOME and extracting the tarball you’ve moved onto the server with the utility of your choice (scp, ftp, NFS…). The set of commands to run looks like the one below:
    $ # the CLONE environment variable should contain
    $ # the tarball you've pushed to the server
    $ export CLONE=/home/oracle/clone
    $ mkdir -p /u01/app/oracle/product/11.1.0/db_2
    $ export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_2
    $ cd $ORACLE_HOME
    $ tar -zxvf $CLONE/myOracleHomeClone.tar.gz
  • Step 3: Run the clone.pl script.In order to proceed, you need Perl 5.6 installed on the server. Navigate to the ORACLE_HOME you’ve just created and run the commands below (In the example, the new ORACLE_HOME will be /u01/app/oracle/product/11.1.0/db_2):
    $ cd $ORACLE_HOME/clone/bin
    $ perl -version
    $ perl clone.pl                                     \
        ORACLE_BASE=/u01/app/oracle                     \
        ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_2 \
        ORACLE_HOME_NAME=ORADB111Home2

    Note that in the case of a 10.2 database, you don’t need the ORACLE_BASE parameter to be set. Once the software is cloned, run the root.sh script as root:

    # /u01/app/oracle/product/11.1.0/db_2/root.sh

 

How to create a template or a clone from a database

Templates and clones are actually very different in their content and in the way they are collected, even if the syntaxes looks very similar:

  • A template is an XML file with the .dbt extension (“t” for “template”). It’s located in the $ORACLE_HOME/assistants/dbca/templates directory. It contains some information about the initialization parameters, the tablespaces, and the files. When you create a database from a template you’ve created with dbca -createTemplateFromDB, the parameters, tablespace and file properties will be created based on the content of the XML file. The database will be created with the CREATE DATABASE SQL command, and all the dictionaries will be created from the standard Oracle scripts. None of the content of the database (Tables, Users…) will be kept.
  • A clone or clone template also contains an XML file. Its extension is .dbc (“c” for “clone”) and it is located in the same $ORACLE_HOME/assistants/dbca/templates directory as a template. The .dbc file contains the same type of information as a template, and also contains an RMAN backup and a control file. As a result, a clone not only contains the initialization parameter and datafile meta data, it also contains the content of the database you’ve cloned, including the data dictionary, SQL patches, and any object you’ve created

Below are two examples of how to create and use both database templates and clones.

Database Template

Because a template is only an XML file generated with DBCA, it can be taken online. It uses a tns alias to connect to the database you want to use as a base for your template. Below is the command you’ll use to create a template:

dbca -silent -createTemplateFromDB       \
       -sourceSID BLACK                  \
       -templateName BLACKTemplate       \
       -sysDBAUserName SYS               \
       -sysDBAPassword change_on_install \

       -maintainFileLocations false

Note that because it connects via Oracle*Net, you need (1)the tns alias passed as the -sourceSID to be defined; (2) the database listener to be started; and (3) the password of the SYS user or any other SYSDBA user you want to use.

The parameters of that command are:

  • -silent — indicates you don’t need any X Display to use the command and no screen will pop up.
  • -createTemplateFromDB is the command to create a template.
  • -sourceSID — defines the tns alias of the database used to create the template (e.g BLACK).
  • -templateName is the name of the database template. In thhe example, the template is named BLACKTemplate and the file that will be generated in $ORACLE_HOME/assistants/dbca/templates is BLACKTemplate.dbt.
  • -sysDBAUserName is the name of the SYSDBA user you’ll use to create the database template. The default is SYS. That parameter is useful if you plan to use another user to connect to the database.
  • -sysDBAPassword — contains the password of the SYSDBA user you connect with.
  • -maintainFileLocations — defines if you want to keep the full path of the datafiles (true) or not (false).

To make the template available to any new ORACLE_HOME, just copy the template file to the $ORACLE_HOME/assistants/dbca/templates directory of the installed software you plan to use.

Once the database template is created, you can use it as the standard template as described in the first post of the series for the 10.2 databases or for the 11.1 databases. Below is an example of such a use of dbca -createDatabase with 11.1 and the template created earlier:

$ mkdir /u01/app/oracle/oradata/WHITE

$ dbca -silent -createDatabase           \
    -templateName BLACKTemplate.dbt      \
    -gdbName WHITE                       \
    -sysPassword change_on_install       \
    -systemPassword manager              \
    -datafileDestination /u01/app/oracle/oradata \
    -storageType FS                      \
    -totalMemory 250

Database Clone

A database clone is made of an XML file and a RMAN cold backup of the database taken with the dbms_backup_restore package. Below is the command you’ll use to create a clone:

$ export CLONE=/home/oracle/distribs/clone
$ dbca -silent -createCloneTemplate    \
     -sourceSID BLACK                  \
     -templateName BLACKClone          \
     -maintainFileLocations false      \
     -datafileJarLocation $CLONE

Note that the database doesn’t have to be in archivelog mode. The backup will always be a cold backup and the instance stopped and mounted during that phase.

The parameters of that command are:

  • -silent — indicates you don’t need any X Display to use the command and no screen will pop up.
  • -createCloneTemplate is the command to create a clone.
  • -sourceSID defines the ORACLE_SID of the database (e.g BLACK).
  • -templateName is the name of the database clone template; In that example, the template is named BLACKClone and the file that will be generated in $ORACLE_HOME/assistants/dbca/templates is BLACKClone.dbc.
  • -maintainFileLocations — defines if you want to keep the full path of the datafiles (true) or not (false).
  • -datafileJarLocation — defines the location where the controlfile and the rman backup are stored.

To make the clone template available to another ORACLE_HOME, copy the .dbc file to the $ORACLE_HOME/assistants/dbca/templates directory of the installed software you plan to use. Make sure the controlfile (.ctl) and rman backup set (.dfb) are in the same directory available from the target server.

You can create a clone of the database from the clone templates with DBCA. Below is an example for a 11.1 database:

$ mkdir /u01/app/oracle/oradata/WHITE
$ export CLONE=/home/oracle/clone 
$ dbca -silent -createDatabase           \
    -cloneTemplate                       \
    -templateName BLACKClone.dbc         \
    -gdbName WHITE                       \
    -sysPassword change_on_install       \
    -systemPassword manager              \
    -datafileDestination /u01/app/oracle/oradata \
    -redoLogFileSize 100                 \
    -datafileJarLocation $CLONE          \
    -storageType FS                      \
    -totalMemory 250

That’s it. You can find more details about the -createDatabase syntaxes in the first post of the series for the 10.2 databases or for the 11.1 databases.

This third post has demonstrated the basics of OUI and the other assistants. One last and easy-to-know syntax is how to delete a database and its instances:

$ dbca -silent -deleteDatabase           \
     -sourceDB WHITE

More to Come

Whether you’ve read these three first posts, or learned the use of the OUI and the assistants by yourself, they really speed up everything.

We are far from done with these syntaxes. Next we’ll dig into the various aspect of 10.2 and 11.1 RAC provisioning features.

Top Categories

  • There are no suggestions because the search field is empty.

Tell us how we can help!

dba-cloud-services
Upcoming-Events-banner