HowTo: Clone a VM and change the DBID

As a DBA, having a test environment is very important. I value having somewhere to test my ideas, practice, and build my skills, that's why I have a laptop that I use as my personal test lab. I installed CentOS to create a multi-boot Operating system with Oracle Virtualbox hypervisor to spin up multiple Virtual Machines (VM) that I have to come to rely on heavily. However, sometimes, I need a preconfigured environment for testing purposes. Instead of creating a new VM, creating a clone of an existing VM with a RDBMS installation can be a time saver.

I will be walking you through the steps I take to clone an existing VirtualBox Virtual Machine and changing the DBID of the database(if required). There is no need to change the DBID of the database unless you are storing backups to the same catalog or will have both VMs active at the same time. If you want to have both VMs active at the same time, you could also choose to change the hostname and IP of the cloned VM - it might be a faster solution.

To clone a VM, complete the following steps:

Click on the VM you want to clone to highlight it. Then click on Machine and then select “Clone”

On the pop-up window, name the clone you are creating then click Next.

“Full Clone” is automatically selected as clone type, click next.

“Current state” is automatically selected as snapshot type, click clone.

Once your clone is complete, open the virtual machine and log in – the log in will be the same as the original.

If you want to change the db name and dbid (if there is an existing oracle installation, follow the steps listed below)

Create the parameter file:

sqlplus / as sysdba

SQL>create pfile from spfile;

SQL>exit;

Take a backup of the parameter file:

cd $ORACLE_HOME/dbs

ls -al

cp initTheMatrix.ora initTheMatrixReloaded.ora

Bounce the Instance and start it up in MOUNT mode

sqlplus / as sysdba

            SQL> shutdown database

            SQL> startup mount

            SQL> exit

Change the Database name and Database ID

nid target=sys

nid target=sys dbname=TheMatrixReloaded

sqlplus / as sysdba

            SQL> shutdown database

Modify the Parameter File

vi initTheMatrixReloaded.ora

            change db_name=TheMatrixReloaded

            change instance_name=TheMatrixReloaded

Modify the oratab file: 

vi /etc/oratab

            change ORACLE_SID=TheMatrixReloaded

Update the tnsnames file so the listener can register the change

vi $ORACLE_HOME/network/admin/tnsnames.ora

              change SID=TheMatrixReloaded

              change service=TheMatrixReloaded

Update the configuration file

vi .bash_profile

            change SID=TheMatrixReloaded

source .bash_profile

Create a new Password File for the database

orapwd file=orapwTheMatrixReloaded password=PASSWORD

Start the Database with the RESETLOGS option

sqlplus / as sysdba

            SQL> startup mount pfile ='path of $ORACLE_HOME/dbs/initTheMatrixReloaded.ora';

            SQL> alter database open resetlogs; 

            SQL> exit

Take a backup of the database and controlfile

rman target /

            RMAN> backup database;

            RMAN> backup current controlfile;

  

*Cover Images from matrix.wikia.com