Saturday, August 15, 2020

Backup Oracle database to OCI Object storage.

4:54 AM Posted by Dilli Raj Maharjan , 1 comment
       

 

        Recovery Manager (RMAN) is an Oracle Database client to perform Oracle database backup and recovery. It is used to automate the administration of our backup strategies and greatly simplifies backing up, restoring, and recovering database files. RMAN connects and authenticates to a database in the same way as SQL*Plus connections to a database. The RMAN client is started by issuing the rman command at the command prompt of your operating system. If a database runs in ARCHIVELOG mode, then we can back up the database while it is open. If the database is not in ARCHIVELOG mode , database needs to stop to create a consistent backup. If the database is backed up during the database is running, the backup is called an inconsistent backup and redo is required during recovery to bring the database to a consistent state. Use the BACKUP command to back up files. Oracle RMAN has a lot of features to backup and restore the database. 

     The Oracle Cloud Infrastructure Object Storage service is an internet-scale, high-performance storage platform. It offers reliable and cost-efficient data durability. The Object Storage service can store an unlimited amount of unstructured data of any content type as analytic data, images, videos, backups, and a lot. Object storage is considered as hot storage. It can be used for data that needs fast, immediate, and frequent access. Data accessibility and performance justifies a higher price to store data in the Object Storage tier. Object Storage can be used to preserve backup and archive data. 

Components of Object storage.
  1. OBJECT
  2. BUCKET
  3. NAMESPACE
  4. COMPARTMENT
Object Storage Features
  1. STRONG CONSISTENCY
  2. DURABILITY
  3. CUSTOM METADATA
  4. ENCRYPTION
    We can directly backup our Oracle database using RMAN to Object Storage. Backups in Object Storage are durable, secure, and efficient. Following is the step by step guide to add opc driver to backup database to OCI object storage.

Create an OCI bucket to store RMAN backup.

Click on Navigation Menu > Object Storage > Object Storage



On the landing page, click on Create Bucket to create new bucket.



Provide the name of Bucket, leave everything default and click on Create Bucket.



Click on Bucket name to upload a file. The Object storage URL is required to install oci. Upload a file and view the Object Detail.


Click on Upload.


Click on Select files. Once the file is selected the name of file will be displayed as below. In my case, I am going to upload Screenshot. Click on Upload to being upload.



Once the upload is completed, we can view status as Finished. Click on Close.



Click on three vertical dots at the right of the object.

Click on View Object Details to view the details of the object.


Now we can see the URL Path, Please note the URL Path. URL path is in the syntax https://objectstorage.<region_name>.oraclecloud.com. For my case https://objectstorage.us-ashburn-1.oraclecloud.com.

Create API key and add key to OCI.

Create a directory to store API key.
mkdir -p /home/oracle/oci/keys
cd /home/oracle/oci/keys



Execute openssl command to create a private API key.
openssl genrsa -out oci_api_key.pem 2048



Execute openssl command to create a public API key.
openssl rsa -pubout -in oci_api_key.pem -out oci_api_key_public.pem
 


Copy the content of the Public API key
cat oci_api_key_public.pem



Click on the profile icon. Click on username.


Click on API Keys option under Resources in bottom left.


On API Keys page click on Add Public Key button.


Click on PASTE PUBLIC KEYS, Paste the key in the text area, and click on Add to add public keys.


Note the Fingerprint value. This value will be required to install OCI library.

Install OCI library to backup database to OCI object storage.

Download opc_installer.zip file from URL https://www.oracle.com/database/technologies/oracle-cloud-backup-downloads.html. Once the installer file is downloaded, unzip it.
unzip opc_installer.zip



Check if Java is installed in your machine. Make sure java is installed and the version is greater than or equal to 1.7.
which java
java -version



Create directories to store library files and encryption key files.
mkdir /home/oracle/oci/lib
mkdir /home/oracle/oci/wallet



Install OCI using command below. Please provide the config file location. This location can be any and all the details are written on the configFile. This file will be used while defining the SBT channel inside RMAN. Please note OCI tenancy ocid, OCI user ocid, Fingerprint value,  API key file location, URL of the object storage, and name of the bucket. Provide all these details. Use the lib directory and wallet directory created in the earlier section.

java -jar oci_install.jar \
  -configFile /home/oracle/oci/configfile.ora \
  -host https://objectstorage.us-ashburn-1.oraclecloud.com \
  -pvtKeyFile /home/oracle/oci/keys/oci_api_key.pem \
  -pubFingerPrint 22:97:d0:5b:50:00:00:00:00:00:00:00:00:11:da:78 \
  -tOCID ocid1.tenancy.oc1..********************************l7ygvujdqjkaq \
  -uOCID ocid1.user.oc1..**********************************lyz3uo2jqq \
  -libDir /home/oracle/oci/lib \
  -walletDir /home/oracle/oci/wallet \
  -bucket RMAN_BACKUP



Check library and wallet directory content to make sure library files and encryption wallet key files are placed under them.
cd /home/oracle/oci/lib
ls
cd ../wallet
ls


Check the library file and the configuration file. These files are used while defining SBT driver.


Configure RMAN channel and start database backup.

Now login to rman.
rman target /


Verify existing configuration.
show all;



Configure channel from sbt device with command below.
configure channel device type sbt parms='SBT_LIBRARY=/home/oracle/oci/lib/libopc.so, SBT_PARMS=(OPC_PFILE=/home/oracle/oci/configfile.ora)';




Backup database using the command below.
backup device type sbt database;


Once backup is completed, it looks something like below. 


Restore database from OCI object storage.

In my case, I have deleted all the datafiles. I have mounted database. Connect rman target.
rman target /


Check the current configuration.
show all;



Configure channel for SBT
configure channel device type sbt parms='SBT_LIBRARY=/home/oracle/oci/lib/libopc.so, SBT_PARMS=(OPC_PFILE=/home/oracle/oci/configfile.ora)';


If decryption key is not provided, then error will be displayed. ORA-19913: unable to decrypt backup



Provide a decryption key.
set decryption identified by "N01_cAn_FIND";



Execute the restore and recover the database. Once it is complete we can notice the Finish restore and Finish recover message.
run{
restore database;
recover database;
}



Open database with command below
sql 'alter database open';




1 comment:

  1. You may want have a peek for MOS Doc ID 2363679.1 Bck2Cloud “1Button” Cloud Backup/Restore Automation Utility

    ReplyDelete