All Things Database: Education, Best Practices,
Use Cases & More

Migrating an On-Premises Database to Oracle Cloud Infrastructure: Create a Backup in the Cloud

Brian Spendolini
Database Cloud Services Product Manager

Updated version can be found here:



One of the most common questions we get about our cloud is how to migrate existing databases into the Oracle Cloud. Are there tools? Is there an automated process? How difficult it is?

The last comment is always the one that catches you...how difficult is it. It assumes that its going to be hard; that the process has so many pitfalls that its just an impossible task. But what if it was easy? Just what if there was a way that I could move my database into the cloud quickly and without much effort?

In this blog, we are going to go over just that, a method to move your database into the Oracle's cloud with a single command. Now granted, there are some setups to be done; but once the environments are prepared, it really is a single command.

So lets start with some background on the process. In Oracle Cloud Infrastructure, we can take a database backup and place it into the cloud. This backup can be from a database already in OCI or could be on premises or in another cloud. That second scenario is the one we will concentrate on and the process is quite simple. We can use the Database Backup Cloud Service to take a full backup of a selected database then create a database in OCI from that backup.

We are going to follow the process outlined in our documentation here, but we are going to walk through it step by step. Please ensure that you meet the requirements outline in the Compatibility section of the docs and are using Oracle Managed Files.

To start, we need to get our host system ready. For this we need to do the following:

1) Set up outbound internet connectivity for installing Python packages, running yum install, and access to the Oracle Cloud Infrastructure API and Object Storage on the source system.

2) Set up RMAN to autobackup the controlfile and spfile of the source database

Starting with the first task, we need to set up python on out system if not already there, and python 3.6 no less. We are going to use an Oracle Linux based system for this example; starting with OL 6.10.

With OL6.10, we do not have python 3.6, its 2.6.6 to be exact. We will need to upgrade via the following method.

If on OL7, you can skip this section and move on to Installing the OCI CLI.

Software Collection Library for Oracle Linux

To use python 3.6 without causing any long term issues with your service, we are going to use the Software Collection Library for Oracle Linux. The software collection library in essence allows you install and use several different versions of the same software at the same time on a system; in our case python. Using the library, we can install and use Python 3.6 with no downstream effects.

Lets first ensure we have the OL6 repo downloaded and ready to go. In this example, im going to not have it configured so I would do the following:

$ cd /etc/yum.repos.d
$ wget http://yum.oracle.com/public-yum-ol6.repo

Now run yum repolist to show the registered channels we have access to:

$ yum repolist

To set up OL6 to use the software collection library, we start by installing the utility from our OCI YUM repositories as root.

$ yum install oraclelinux-release-el6

$ /usr/bin/ol_yum_configure.sh

Next,  we enable the software_collections repository for Oracle Linux 6, ensure that the ol6_latest repository is also enabled:

$ yum-config-manager --enable ol6_latest

$ yum-config-manager --enable software_collections

Lastly, we install the scl-utils package:

$ yum install scl-utils

The scl-utils package is ready to go so we now install python 3

$ yum install rh-python36

And once installed, we can switch between the two versions:

$ scl enable rh-python36 bash

For example, a little test:

$ python --version
Python 2.6.6
$ scl enable rh-python36 bash
$ python --version
Python 3.6.3

Now on to installing the OCI CLI on our local system.

Installing the OCI CLI

We are going to install the CLI into the oracle user's home at /home/oracle/migrate. If the directory is not present, we can create it:

$ mkdir -p /home/oracle/migrate

The CLI needs a key exchange for secure communications. We are going to create a public and private key but you can use an existing pair if you wish. To start on the linux system, run the following (this key will have no pass-phrase):

$ openssl genrsa -out /home/oracle/migrate/oci_cli_key.pem 2048

ensure the correct permissions are on the key:

$ chmod 600 /home/oracle/migrate/oci_cli_key.pem

and now generate the matching public key:

$ openssl rsa -pubout -in /home/oracle/migrate/oci_cli_key.pem -out /home/oracle/migrate/oci_cli_key_public.pem

We also need to get the Oracle Database Backup Service zip file. Get the zip file from here, copy it to your system and place it in to the /home/oracle/migrate directory. Once there, unzip the file.

$ pwd
$ ls
$ unzip opc_installer.zip
Archive:  opc_installer.zip
  inflating: readme.txt              
   creating: oci_installer/
  inflating: oci_installer/oci_install.jar  
  inflating: oci_installer/oci_readme.txt  
   creating: opc_installer/
  inflating: opc_installer/opc_install.jar  
  inflating: opc_installer/opc_readme.txt  
$ cp opc_installer/*.jar .
$ ls
oci_cli_key.pem         oci_installer  opc_installer.zip  readme.txt
oci_cli_key_public.pem  opc_installer  opc_install.jar

As root, install the CLI using the following command, but first, remember to use python 3 if on an OL6 system:

$ scl enable rh-python36 bash

Install Command:

$ bash -c "$(curl -L https://raw.githubusercontent.com/oracle/oci-cli/master/scripts/install/install.sh)"

During this install, answer the prompts with the following values in bold red:

This first question may or may not be displayed. Its dependent on your system configuration/installed options.

===> Missing native dependencies. Continue and install the following dependencies: gcc, libffi-devel, python36u-devel, openssl-devel? (Y/n): Y

If you do not see this first question, move to the next one:

===> In what directory would you like to place the install? (leave blank to use '/root/lib/oracle-cli'): /home/oracle/migrate/lib/oracle-cli
===> In what directory would you like to place the 'oci' executable? (leave blank to use '/root/bin'): /home/oracle/migrate/bin
===> In what directory would you like to place the OCI scripts? (leave blank to use '/root/bin/oci-cli-scripts'): /home/oracle/migrate/bin/oci-cli-scripts
===> Currently supported optional packages are: ['db (will install cx_Oracle)'] What optional CLI packages would you like to be installed (comma separated names; press enter if you don't need any optional packages)?: db
===> Modify profile to update your $PATH and enable shell/tab completion now? (Y/n): Y
===> Enter a path to an rc file to update (leave blank to use '/root/.bashrc'): /home/oracle/.bashrc

We need to create a config file for the CLI to use. Start by editing or creating the config.txt file in the /home/oracle/migrate directory:

$ vi /home/oracle/migrate/config.txt

and use the following text, the variables in bold red can be found in the OCI web console with the key file location (in bold orange) being in the /home/oracle/migrate directory:


Tenancy ID can be found in the web console. Just click your tenancy name under the profile icon in the upper right.

and on the next page, you can click the copy link next to OCID under Tenancy Information.

User OCID is found on your user details page in the web console in the user information section of the page.

If you do not know your API signing key's fingerprint, see How to Get the Key's Fingerprint.

The region field would be the region you want this backup to go to. That can be found on the web console, upper right.

Once done with the config.txt file, set the correct permissions:

$ chmod 600 /home/oracle/migrate/config.txt

Now we give control over the CLI to the oracle user:

$ chown -R oracle:oinstall /home/oracle/migrate

Time to backup the database to the cloud.

Backing Up the Database to the Cloud

Start on the source system as the oracle user, we will no longer be using root. As mentioned above, we need to set up RMAN to auto backup the controlfile and spfile of the source database.

$ rman target=/

RMAN> configure controlfile autobackup on;

Next, we need to set up our Linux environment for the backup. Ensure you get the values for the red bold variables:

export AD=<destination_availability_domain>
export C=<destination_compartment_OCID>
export LC_ALL=en_US.UTF-8
export ORACLE_UNQNAME=<source_DB_unique_name>

To find the destination availability domain, we can use the OCI CLI to get a list of ADs in the region from the config.txt file. Start by making the following directory:

$ mkdir -p /home/oracle/.oci

now, we are going to copy the config.txt file to this directory and rename it to just config

$ cp /home/oracle/migrate/config.txt /home/oracle/.oci/config

set the permissions:

$ chmod 600 /home/oracle/.oci/config

and we can now run the following OCI CLI command to get the AD names:

$ oci iam availability-domain list

In my service, the name for AD1 is KKOA:US-ASHBURN-AD-1 and would use that for the environment variable.

The destination compartment OCID would be on the compartment details page, in the compartment information section.

The ORACLE_SID and ORACLE_HOME values will be distinct to your system. The ORACLE_UNQNAME can be found via the v$database table:

SQL> select db_unique_name from v$database;

Now we prepare the environment:

$ rm -rf /home/oracle/migrate/onprem_upload
$ cd /home/oracle/migrate/bin/oci-cli-scripts/

switch to python 3 if using OL6:

$ scl enable rh-python36 bash

and run the script to backup to the cloud. The variable in bold red can be changed to a display name more to your liking if you wish. Please take note of the edition variable. Set this based on the features you will be using in the Oracle Cloud. Use this chart to help make that decision and the value you will use:

Edition Features Script Variable to use
Standard Edition Oracle Database Standard Edition 2 STANDARD_EDITION
Enterprise Edition Includes the Oracle Database Enterprise Edition, Data Masking and Subsetting Pack, Diagnostics and Tuning Packs, and Real Application Testing ENTERPRISE_EDITION
Enterprise High Performance extends the Enterprise Edition with the following options: Multitenant, Partitioning, Advanced Compression, Advanced Security, Label Security, Database Vault, OLAP, Advanced Analytics, Spatial & Graph, Database Lifecycle Management Pack and Cloud Management Pack for Oracle Database. ENTERPRISE_EDITION_HIGH_PERFORMANCE
Enterprise Extreme Performance extends the High Performance package with the following options: In-Memory Database, Active Data Guard, and RAC ENTERPRISE_EDITION_EXTREME_PERFORMANCE

Once we have all the values set, we can run the script:

./create_backup_from_onprem --config-file /home/oracle/migrate/config.txt --display-name OnPremBackup --availability-domain $AD --edition ENTERPRISE_EDITION_EXTREME_PERFORMANCE --opc-installer-dir /home/oracle/migrate --tmp-dir /home/oracle/migrate/onprem_upload --compartment-id $C

If the script fails, correct the error, re-run the following command:

$ rm -rf /home/oracle/migrate/onprem_upload

then re-run the create_backup_from_onprem script again.

As the process runs, you will soon see the backup being created in the web console:

and once done, we can use this backup to create a new database.

Join the discussion

Comments ( 3 )
  • Ayman Alashqar Wednesday, July 3, 2019
    Thank you for the post. Migration of the Oracle database using the OCI Object Storage Database Backup method is practical for sites that tolerate down time during migration. By using the Oracle Hybrid Data Guard a minimum downtime migration can be achieved, it is just the time needed to point the application servers to the new IP/SCAN of the Oracle OCI instance weather it is Exadata, BareMetal or VM.
  • Brian Spendolini Wednesday, September 4, 2019
    Sure aitorito, but what if I have standard edition? No Data Guard.
  • Mike Salvatore Monday, October 28, 2019
    I used these steps to transfer our two production databases from the OCI-C platform to the new OCI. Aside from a little trouble getting Python 3.6 installed on the old Linux images, everything else worked without a hitch. Thanks to Brian for the detailed instructions.
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.