Disaster Recovery: Backing Up your Oracle Database with Oracle Database Cloud Backup Service, RMAN, and Object Storage
By: Ary Sharifian
Tags: Oracle Database, Disaster Recovery, Data Engineering, Cloud Computing, Iaas

Disaster Recovery: Backing Up your Oracle Database with Oracle Database Cloud Backup Service, RMAN, and Object Storage

how to back up your Oracle Cloud Database

Photo by Kevin Ku on Unsplash

How can we prepare for disaster? If a server crashes, a technician unplugs a machine, or a meteor hits a datacenter, how can the business recover crucial data? In this tutorial we demonstrate how to backup the Oracle Cloud Database with Oracle Database Cloud Backup Service, RMAN (Recovery Manager), and Object Storage. Here, Oracle Database Cloud Backup Service enables connection and communication with Oracle Cloud Infrastructure (OCI) while RMAN executes backups of your Oracle Cloud Database to OCI Object Storage.

Note: there are many different ways to backup an Oracle Cloud Database, this is meant to represent one option. Note: given the diversity of customer environments and the ever-changing landscape of Oracle Cloud Infrastructure, please take the commands and their explanations listed below with a grain of salt.

Outline:

Pre-Requisites for Using Oracle Database Cloud Backup Service Full List of Commands for installing Oracle Database Cloud Backup Service Pre-Requisites for Installing Oracle Cloud Backup Database Service Installing RMAN Configure RMAN and Backup Database Database Table Access through SQL Plus Conclusion

Pre-Requisites for Using Oracle Database Cloud Backup Service

Before we get started, here is a link to all the pre-requisites needed to use the Oracle Cloud Backup Service. I will try to provide as much context to each pre-requisite and provide helpful links and examples.

Check and make sure you are running the right database version and operating system. In this module I am using Enterprise Extreme Performance Edition version 19c.

Setup Object Storage in OCI (Oracle Cloud Infrastructure). I recommend simply using the console, accessing object storage, and creating a bucket.

In the virtual machine which hosts the database, generate keys to access OCI. Here is, in essence, how it will look. (The scripts below assume you are already in the VM instance which hosts the database.) This is how you will upload the key to OCI such that your virtual machine can communicate/connect with OCI.

Check that you have a JDK 1.7 or later. You can check which version you have by typing “java -version” in your linux terminal. You should get an output similar to the following:

java version “1.8.0_191”

Java(TM) SE Runtime Environment (build 1.8.0_191-b12)

Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)

Finally, you want to download the latest version of the Oracle Cloud Backup service. This is the link to download the backup service. This should download a zip file called opc_installer. When unzipped, you should two folders, opc_installer and oci_installer. These are the two ways to install the Cloud Backup Service. In this tutorial, I will be using the oci_installer for OCI (not OCI classic).

Note: If you have downloaded the Oracle Cloud Backup Service on a different machine than the one which hosts your database, you can use this command to copy your key from your local machine to your database host instance:

#generic command

cp -i <file/path/to/your/private_key> oci_install.jar opc@<vm_db_ip>:~”.

cp -i /Users/abibi/.ssh/id_rsa oci_install.jar #examplecp -i /Users/abibi/.ssh/id_rsa oci_install.jar opc@130.147.26.83 :~

Note: To SSH to the virtual machine which hosts your database:

Full List of Commands for installing Oracle Database Cloud Backup Service

I am doing this a bit backwards and providing a list of commands for installing the oci_install.jar file before detailing the pre-requisites for the command. I am doing this because I wanted to provide a nice flow of commands. If you like more detail about the commands or are running into issues, simply reference the pre-reqs listed in the next section.

Note: If you have executed some the commands listed above, no need to repeat them.

#copy the newly downloaded oci_install.jar file to your database instance, assumes that the oci_install file in your current directory scp -i <private_key> oci_install.jar opc@<db_ip>:~ #SSH into the instance

ssh -i <private_key> opc@<db_ip> #maybe log into your Oracle user--see note below

#sudo su - oracle #create directories for installing jar file

mkdir ~/lib

mkdir ~/wallet #directory for oci credentials

mkdir .oci #generating key for OCI

openssl genrsa -out ~/.oci/oci_api_key.pem 2048

openssl rsa -pubout -in ~/.oci/oci_api_key.pem -out ~/.oci/oci_api_key_public.pem #change directory to oci folder

cd .oci #note: to see hidden files, enter "ls -a" #output the key, copy and paste into user ssh key

cat oci_api_key_public.pem #cd into folder containing oci_install.jar file, should be in opc folder #I assume the opc directory is where the jar file is located

cd opc #generic command to install backup service

java -jar oci_install.jar -host <object storage endpoint> -pvtKeyFile ~/.oci/oci_api_key.pem -pubFingerprint <fingerprint> -tOCID <tOCID> -cOCID <cOCID> -uOCID <uOCID> -walletDir ~/wallet -libDir ~/lib -bucket <bucketname>

N ote: depending on the version of the database you are installing, you may need to copy files from one directory to another within the database instance. To do this, I recommend accessing the root user, copying files, and changing permissions for a file:

#becoming root user

sudo su #example of copying wallet credentials from opc to oracle user

cp /home/opc/wallet/cwallet.sso /u01/app/oracle #changing permission access for a particular file such that other users can access the file

chmod 775 /home/opc/wallet/cwallet.sso

Note: another option is to log in as the instance’s Oracle user and run the commands above. To do this you can enter the following command after you have SSH’d into the instance:

sudo su - oracle

Pre-Requisites for Installing Oracle Cloud Backup Database Service

To execute the jar file that will install the Oracle Cloud Backup Database Service, we need to gather some information from our Oracle Cloud Tenancy:

Host: our object storage endpoint indicating the region where we created a bucket. Here is a list of valid value.

pvtKeyFile: the location to the oci_api_key which we generated earlier in our database virtual machine.

pubFingerprint: the fingerprint corresponding to the oci_api_key.

tOCID: our tenancy OCID

cOCID: the compartment OCID which holds object storage and our database instance.

uOCID: our user’s OCID.

Note: OCID is a unique value which identifies specific components of OCI like user, compartments, tenancy, and services. Learn more about OCIDs, here.

walletDir: location for newly created wallet.

Note: simply type the following if you want to create a folder in your current working directory:

mkdir ~/wallet

libDir: location for newly created library.

Note: simply type the following if you want to create a folder in your current working directory.

mkdir ~/lib

Here is the GENERIC command that installs the Oracle Cloud Backup Database Service:

Here is an EXAMPLE command:

Note: I’ve spaced out the commands so that it is easier to understand, but when executing these commands in linux, they should all be in one line separated by a space. Note: if you are getting errors, here is some documentation that helps diagnose some common issues.

We can validate successfully installing the jar file by checking if wallet and lib folders were created and if we see a “config” file which contains the OPC_HOST, OPC_WALLET, OPC_CONTAINER, OPC_COMPARTMENT, and OPC_AUTH_SCHEME values.

Note: To open and read linux files, I recommend installing nano by typing the following (assuming you are in a directory with access to the config file):

yum install nano

nano config

Installing RMAN

Now that we have successfully installed Oracle Database Cloud Backup Service and established a connection to OCI, let’s setup RMAN (Oracle Recovery Manager) to manage our database backup to object storage.

Pre-requisite:

Oracle DB Password, the password entered when provisioning the Oracle Cloud Database instance.

RMAN binaries location for installation

#to find the rman binaries

find / -iname rman

Note: if there is a permission error, please enter the command to become a root user

#example output should look something like this:

/opt/oracle/dcs/log/ary/rman

/tmp/dcsserver/rman

/u01/app/19.0.0.0/grid/bin/rman

/u01/app/oracle/product/19.0.0.0/dbhome_1/bin/rman

Add RMAN binary location to current path

#generic example of path

export PATH=/u01/app/oracle/product/<insert DB version number>/dbhome_1/bin

Set environment variables, ORACLE_HOME and ORACLE_SID

#not really sure how important this, but points to database path

export ORACLE_HOME=/u01/app/oracle/product/19.0.0.0/dbhome_1 #a unique identifier for your database, can find this in the console where you database is provisioned

export ORACLE_SID=DB1111 #outputs all environment variables to confirm

env #outputs config info for the database

srvctl config database -d <database unique identifier>

Configure RMAN and Backup Database

Now we are ready to configure RMAN for backing up the Oracle Cloud Database to object storage. Simply enter this command to set/authorize RMAN connection to the database:

#generic, TARGET is the command, SYS is the user, oracle is the password, and trgt2 is the database unique identifier

rman TARGET SYS/oracle@trgt2 #example

rman TARGET SYS/mypassword@DB111_asc3fp

By this point, you should see a lingering “RMAN” at the bottom of the terminal and a message above stating that you have successfully connected to the database.

Note: Here is some additional documentation and another source that is helpful for logging into the database using RMAN.

Next, we need to configure some RMAN parameters before backing up the database:

CONFIGURE CHANNEL DEVICE TYPE 'SBT_TAPE' PARMS 'SBT_LIBRARY=/path/to/libopc.so, SBT_PARMS=(OPC_PFILE=/path/to/config)';

Some additional commands:

CONFIGURE CONTROLFILE AUTOBACKUP ON;

CONFIGURE DEFAULT DEVICE TYPE TO SBT_TAPE;

CONFIGURE BACKUP OPTIMIZATION ON;

CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE SBT_TAPE TO '%F';

CONFIGURE ENCRYPTION FOR DATABASE ON;

SET ENCRYPTION IDENTIFIED BY "password" ONLY;

Note: details about the commands listed above and other options can be found here.

Finally:

BACKUP DATABASE;

At this point, the command should result in the database being backed up into the object storage defined earlier. To confirm the backup is successful simply check object storage for database content and metadata files along with other related objects.

Database Table Access through SQL Plus

As an aside, to connect to the database tables, here is a link to some documentation. More information about connecting to a database. Below is a command that accesses the database tables through SQL Plus.

#generic script to access database tables as system user

sqlplus system/@(DESCRIPTION=(CONNECT_TIMEOUT=5)(TRANSPORT_CONNECT_TIMEOUT=3)(RETRY_COUNT=3)(ADDRESS_LIST=(LOAD_BALANCE=on)(ADDRESS=(PROTOCOL=TCP)(HOST=10.0.0.3)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=<unique service name defined in database console under database connection>))) #example script to access database tables as system user

sqlplus system/@meee.subnet.vcn.oraclevcn.com:1521/DB1111_asb3bs.subnet.vcn.oraclevcn.com

Conclusion

There are other ways of backing up an Oracle Cloud Database, why choose this option? I believe this provides find-grained control and the ability to set a cron job for scheduling the backup. With object storage involved, the database can be backed up to another region where the database is not running to provide high availability during a disaster. Nevertheless, there are automatic backups available in the console, the Oracle OCI Python SDK, and a number of other options to backup your database. I recommend considering the use case, RPO, RTO, and other factors before choosing this backup solution as it is tedious and time consuming to implement.