Skip to Content

How to Clone and Restore an Oracle Database on Linux

Learn how to create a backup of your Oracle database on one Linux machine and restore it on another Linux machine using RMAN and NFS. This article explains how to clone and restore an Oracle database on Linux using RMAN and NFS. It provides step-by-step instructions and examples for each stage of the process.

Cloning and restoring an Oracle database is a common task for testing, development, or disaster recovery purposes. It involves creating a copy of the Oracle database files on one Linux machine and transferring them to another Linux machine where they can be restored and opened. This way, you can have an exact replica of your original database on a different environment.

There are different methods and tools for cloning and restoring an Oracle database, but in this article, we will focus on using RMAN and NFS. RMAN is the Oracle Recovery Manager, a utility that allows you to backup, restore, and recover your Oracle database. NFS is the Network File System, a protocol that allows you to share files and directories over a network.

The following are the main steps for cloning and restoring an Oracle database on Linux using RMAN and NFS:

  1. Configure the NFS server and client on both machines
  2. Backup the database on the source machine using RMAN
  3. Copy the backup files to the NFS location
  4. Restore the database on the destination machine using RMAN
  5. Rename the database files and online redo logs
  6. Change the database name and ID using NID
  7. Open the database with resetlogs option

We will explain each step in detail and provide examples of the commands and outputs. We assume that you have a Linux machine with an Oracle database on it (the source machine) and another Linux machine where you want to clone the database (the destination machine). We also assume that you have root access and Oracle user credentials on both machines.

Step 1: Configure the NFS server and client on both machines

The first step is to configure the NFS server and client on both machines. NFS allows you to mount a remote directory on your local file system and access it as if it were a local directory. This way, you can copy the backup files from the source machine to the destination machine without using SCP or FTP.

To configure the NFS server and client on both machines, you need to do the following:

  1. Install the NFS packages on both machines
  2. Create a shared directory on the source machine and export it to the destination machine
  3. Mount the shared directory on the destination machine

Install the NFS packages on both machines

To install the NFS packages on both machines, you can use the following command as root:

# yum install nfs-utils

This will install the necessary packages for the NFS server and client, such as nfs-utils, rpcbind, and nfslock.

Create a shared directory on the source machine and export it to the destination machine

To create a shared directory on the source machine and export it to the destination machine, you need to do the following:

  • Create a directory on the source machine where you want to store the backup files. For example, you can create a directory called /u01/oracle/backup.
  • Change the ownership and permissions of the directory to allow the Oracle user to read and write to it. For example, you can use the following commands as root:
# chown oracle:oinstall /u01/oracle/backup
# chmod 755 /u01/oracle/backup
  • Edit the /etc/exports file on the source machine and add a line to export the directory to the destination machine. The line should specify the directory path, the destination machine IP address, and the options for the export. For example, you can add the following line to the /etc/exports file:
/u01/oracle/backup 192.168.2.136(rw,sync,no_root_squash)

This line means that the /u01/oracle/backup directory is exported to the destination machine with IP address 192.168.2.136, with read and write permissions, synchronous mode, and no root squash option. The synchronous mode ensures that the data is written to the disk before the NFS server replies to the client. The no root squash option allows the root user on the destination machine to access the files as the owner of the files on the source machine.

  • Restart the NFS service on the source machine to apply the changes. You can use the following command as root:
# systemctl restart nfs-server

Mount the shared directory on the destination machine

To mount the shared directory on the destination machine, you need to do the following:

  • Create a mount point on the destination machine where you want to access the shared directory. For example, you can create a directory called /mnt/backup.
  • Mount the shared directory on the mount point using the mount command. You need to specify the source machine IP address, the shared directory path, and the mount point. For example, you can use the following command as root:
# mount 192.168.2.135:/u01/oracle/backup /mnt/backup

This command will mount the /u01/oracle/backup directory from the source machine with IP address 192.168.2.135 on the /mnt/backup directory on the destination machine.

  • Verify that the mount was successful by listing the contents of the mount point. You should see the same files and directories as in the shared directory on the source machine. For example, you can use the following command as root:
# ls -l /mnt/backup

Step 2: Backup the database on the source machine using RMAN

The next step is to backup the database on the source machine using RMAN. RMAN is a command-line tool that allows you to perform backup, restore, and recovery operations on your Oracle database. You can use RMAN to create a full or incremental backup of your database, which includes the data files, control files, and archived redo logs.

To backup the database on the source machine using RMAN, you need to do the following:

  • Connect to the database as the Oracle user and start RMAN. You can use the following command:
$ rman target /

This will connect to the database using the operating system authentication and start the RMAN prompt.

  • Configure the backup destination and format. You can use the CONFIGURE command to set the backup destination and format for the backup files. For example, you can use the following command to configure the backup destination as the shared directory /u01/oracle/backup and the backup format as db_%U.bkp, where %U is a substitution variable that generates a unique filename for each backup piece.
RMAN> CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/u01/oracle/backup/db_%U.bkp';

This will configure the default backup channel to use the disk device type and the specified format.

  • Backup the database using the BACKUP command. You can use the BACKUP command to perform a full or incremental backup of the database. For example, you can use the following command to perform a full backup of the database, including the control file and the archived redo logs.
RMAN> BACKUP DATABASE PLUS ARCHIVELOG;

This will backup the entire database, the current control file, and all the archived redo logs to the backup destination. You can monitor the progress and status of the backup operation by looking at the output messages. You can also use the LIST command to view the details of the backup files. For example, you can use the following command to list the backup sets and backup pieces of the database.

RMAN> LIST BACKUP OF DATABASE;

This will display the backup sets and backup pieces of the database, along with their filenames, sizes, and statuses.

  • Exit RMAN and disconnect from the database. You can use the EXIT command to exit RMAN and return to the operating system prompt. For example, you can use the following command:
RMAN> EXIT

This will exit RMAN and disconnect from the database.

Step 3: Copy the backup files to the NFS location

The third step is to copy the backup files to the NFS location. This step is optional if you have already configured the backup destination as the NFS location in the previous step. However, if you have used a different backup destination, such as the FRA location, you need to copy the backup files to the NFS location so that they can be accessed by the destination machine.

To copy the backup files to the NFS location, you need to do the following:

  • Locate the backup files on the source machine. You can use the LIST command in RMAN or the ls command in the operating system to find the backup files. For example, if you have used the FRA location as the backup destination, you can use the following command as the Oracle user to list the backup files in the FRA location.
$ ls -l $ORACLE_BASE/fast_recovery_area/$ORACLE_SID/backupset

This will list the backup files in the backupset subdirectory of the FRA location, where $ORACLE_BASE is the Oracle base directory, and $ORACLE_SID is the Oracle system identifier.

  • Copy the backup files to the NFS location using the cp command. You can use the cp command to copy the backup files from the source location to the NFS location. For example, if you have mounted the NFS location on the /mnt/backup directory, you can use the following command as the Oracle user to copy the backup files to the NFS location.
$ cp $ORACLE_BASE/fast_recovery_area/$ORACLE_SID/backupset/*.bkp /mnt/backup

This will copy all the backup files with the .bkp extension to the NFS location.

Step 4: Restore the database on the destination machine using RMAN

The fourth step is to restore the database on the destination machine using RMAN. RMAN allows you to restore the backup files from the NFS location to the destination machine and apply the archived redo logs to recover the database to a consistent state.

To restore the database on the destination machine using RMAN, you need to do the following:

  • Connect to the database as the Oracle user and start RMAN. You can use the same command as in the previous step to connect to the database using the operating system authentication and start the RMAN prompt.
$ rman target /
  • Configure the backup location and format. You can use the same CONFIGURE command as in the previous step to set the backup location and format for the restore operation. For example, you can use the following command to configure the backup location as the NFS location /mnt/backup and the backup format as db_%U.bkp.
RMAN> CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/mnt/backup/db_%U.bkp';
  • Restore the database using the RESTORE command. You can use the RESTORE command to restore the backup files from the NFS location to the destination machine. For example, you can use the following command to restore the entire database, including the control file and the archived redo logs.
RMAN> RESTORE DATABASE;

This will restore the database files, the control file, and the archived redo logs from the NFS location to the destination machine. You can monitor the progress and status of the restore operation by looking at the output messages. You can also use the LIST command to view the details of the restored files. For example, you can use the following command to list the restored files of the database.

RMAN> LIST RESTORE OF DATABASE;

This will display the restored files of the database, along with their filenames, sizes, and statuses.

  • Recover the database using the RECOVER command. You can use the RECOVER command to apply the archived redo logs to the restored database and bring it to a consistent state. For example, you can use the following command to recover the database to the most recent point in time.
RMAN> RECOVER DATABASE;

This will apply the archived redo logs to the restored database and roll forward the changes until the last available log. You can monitor the progress and status of the recovery operation by looking at the output messages.

  • Exit RMAN and disconnect from the database. You can use the same EXIT command as in the previous step to exit RMAN and return to the operating system prompt.
RMAN> EXIT

Step 5: Rename the database files and online redo logs

The fifth step is to rename the database files and online redo logs on the destination machine. This step is necessary because the restored database files and online redo logs may have different names or locations than the original ones on the source machine. You need to rename them to match the destination machine file system and directory structure.

To rename the database files and online redo logs on the destination machine, you need to do the following:

  • Connect to the database as the Oracle user and start SQLPlus. You can use the following command to connect to the database using the operating system authentication and start the SQLPlus prompt.
$ sqlplus / as sysdba
  • Start the database in mount mode. You can use the STARTUP command to start the database in mount mode, which means that the database is mounted but not opened. For example, you can use the following command to start the database in mount mode.
SQL> STARTUP MOUNT;

This will mount the database but not open it.

  • Rename the data files using the ALTER DATABASE RENAME FILE command. You can use the ALTER DATABASE RENAME FILE command to rename the data files of the database. You need to specify the old and new filenames for each data file. For example, you can use the following command to rename the data file /u01/oracle/oradata/ORCL/system01.dbf to /u02/oracle/oradata/ORCL/system01.dbf.
SQL> ALTER DATABASE RENAME FILE '/u01/oracle/oradata/ORCL/system01.dbf' TO '/u02/oracle/oradata/ORCL/system01.dbf';

This will rename the data file /u01/oracle/oradata/ORCL/system01.dbf to /u02/oracle/oradata/ORCL/system01.dbf. You need to repeat this command for each data file that needs to be renamed.

  • Rename the online redo logs using the ALTER DATABASE RENAME FILE command. You can use the same ALTER DATABASE RENAME FILE command to rename the online redo logs of the database. You need to specify the old and new filenames for each online redo log. For example, you can use the following command to rename the online redo log /u01/oracle/oradata/ORCL/redo01.log to /u02/oracle/oradata/ORCL/redo01.log.
SQL> ALTER DATABASE RENAME FILE '/u01/oracle/oradata/ORCL/redo01.log' TO '/u02/oracle/oradata/ORCL/redo01.log';

This will rename the online redo log /u01/oracle/oradata/ORCL/redo01.log to /u02/oracle/oradata/ORCL/redo01.log. You need to repeat this command for each online redo log that needs to be renamed.

  • Exit SQLPlus and disconnect from the database. You can use the EXIT command to exit SQLPlus and return to the operating system prompt.
SQL> EXIT

Step 6: Change the database name and ID using NID

The sixth step is to change the database name and ID using NID. NID is the Database New ID Utility, a tool that allows you to change the name and ID of a database. This step is optional if you want to keep the same name and ID as the original database on the source machine. However, if you want to change the name and ID of the database on the destination machine, you need to use NID.

To change the database name and ID using NID, you need to do the following:

  • Connect to the database as the Oracle user and start NID. You can use the following command to connect to the database using the operating system authentication and start the NID prompt.
$ nid target=/

This will connect to the database and start the NID prompt.

  • Change the database name and ID using the DBNAME and SETNAME parameters. You can use the DBNAME parameter to specify the new name for the database and the SETNAME parameter to specify whether to change the ID of the database. For example, you can use the following command to change the database name to ORCL2 and the ID to a new value.
NID> DBNAME ORCL2 SETNAME=YES

This will change the database name to ORCL2 and the ID to a new value. You can monitor the progress and status of the change operation by looking at the output messages.

  • Exit NID and disconnect from the database. You can use the EXIT command to exit NID and return to the operating system prompt.
NID> EXIT

Step 7: Open the database with resetlogs option

The final step is to open the database with the resetlogs option on the destination machine. The resetlogs option allows you to open the database after a complete recovery and reset the online redo logs. This way, you can start a new incarnation of the database and avoid any conflicts with the previous logs.

To open the database with the resetlogs option on the destination machine, you need to do the following:

  • Connect to the database as the Oracle user and start SQLPlus. You can use the same command as in the previous step to connect to the database using the operating system authentication and start the SQLPlus prompt.
$ sqlplus / as sysdba
  • Start the database in mount mode. You can use the same STARTUP command as in the previous step to start the database in mount mode.
SQL> STARTUP MOUNT;
  • Open the database with the resetlogs option using the ALTER DATABASE OPEN RESETLOGS command. You can use the ALTER DATABASE OPEN RESETLOGS command to open the database with the resetlogs option. For example, you can use the following command to open the database with the resetlogs option.
SQL> ALTER DATABASE OPEN RESETLOGS;

This will open the database with the resetlogs option and reset the online redo logs. You can monitor the progress and status of the open operation by looking at the output messages.

  • Exit SQLPlus and disconnect from the database. You can use the same EXIT command as in the previous step to exit SQLPlus and return to the operating system prompt.
SQL> EXIT

You have successfully cloned and restored an Oracle database on Linux using RMAN and NFS. You can now use the database on the destination machine for your testing, development, or disaster recovery purposes.

Frequently Asked Questions (FAQs)

Question: What are the advantages and disadvantages of using RMAN and NFS for cloning and restoring an Oracle database on Linux?

Answer: Some of the advantages of using RMAN and NFS for cloning and restoring an Oracle database on Linux are:

  • RMAN is a powerful and flexible tool that allows you to perform backup, restore, and recovery operations on your Oracle database. You can use RMAN to create full or incremental backups of your database, which include the data files, control files, and archived redo logs. You can also use RMAN to restore the backup files from any location and recover the database to a consistent state. RMAN also supports compression, encryption, and parallelism for the backup and restore operations.
  • NFS is a simple and convenient protocol that allows you to share files and directories over a network. You can use NFS to mount a remote directory on your local file system and access it as if it were a local directory. This way, you can copy the backup files from the source machine to the destination machine without using SCP or FTP. NFS also supports different options for the file sharing, such as synchronous mode, no root squash, and read and write permissions.

Some of the disadvantages of using RMAN and NFS for cloning and restoring an Oracle database on Linux are:

  • RMAN and NFS require additional configuration and setup on both machines. You need to install the NFS packages, create and export the shared directory, and mount the shared directory on both machines. You also need to configure the backup and restore channels and formats in RMAN. These steps may be tedious and error-prone, especially if you are not familiar with the commands and options.
  • RMAN and NFS may have performance and security issues depending on the network and file system conditions. The backup and restore operations may be slow or fail if the network is unstable or congested. The file sharing may also expose the backup files to unauthorized access or modification if the NFS server or client is not properly secured. You need to ensure that the network and file system are reliable and secure before using RMAN and NFS.

Question: What are some alternatives to using RMAN and NFS for cloning and restoring an Oracle database on Linux?

Answer: Some alternatives to using RMAN and NFS for cloning and restoring an Oracle database on Linux are:

  • Using Data Pump Export and Import. Data Pump Export and Import are utilities that allow you to export and import the data and metadata of your Oracle database. You can use Data Pump Export to create a dump file of your database on the source machine and Data Pump Import to load the dump file into the database on the destination machine. Data Pump Export and Import also support compression, encryption, parallelism, and filtering for the export and import operations.
  • Using Oracle Cloud Backup and Restore. Oracle Cloud Backup and Restore are services that allow you to backup and restore your Oracle database to and from the Oracle Cloud. You can use Oracle Cloud Backup to create a backup of your database on the source machine and upload it to the Oracle Cloud. You can also use Oracle Cloud Restore to download the backup from the Oracle Cloud and restore it to the database on the destination machine. Oracle Cloud Backup and Restore also support compression, encryption, and incremental backups.

Summary

In this article, we have learned how to clone and restore an Oracle database on Linux using RMAN and NFS. We have followed the following steps:

  • Configure the NFS server and client on both machines
  • Backup the database on the source machine using RMAN
  • Copy the backup files to the NFS location
  • Restore the database on the destination machine using RMAN
  • Rename the database files and online redo logs
  • Change the database name and ID using NID
  • Open the database with resetlogs option

We have also answered some FAQs related to the topic and discussed some alternatives to using RMAN and NFS for cloning and restoring an Oracle database on Linux.

Disclaimer: This article is for informational purposes only and does not constitute professional advice. The author and the publisher are not liable for any errors or omissions, or for any consequences arising from the use of the information in this article. The user is responsible for verifying the accuracy and suitability of the information before applying it to their own situation. The user is also responsible for complying with the Oracle license agreement and any applicable laws and regulations when using the Oracle database and its tools.