In a previous blog I demonstrated how to migrate an Oracle database from AWS to Oracle OCI using Data Guard. But what if you want to migrate to the Oracle Cloud, but don’t have a direct connection between the Cloud Providers, neither of the database servers are available in the public internet or you are using Oracle Standard Edition where Data Guard isn’t available?

You could backup the database to disk, copy the files by hand to a temporary location, copy from the temporary location to the Oracle Cloud and then restore the database.

Or you could use the Oracle Database Backup Cloud Service to simplify the process. This service allows us to perform RMAN backup / restore directly to an Object Store (Bucket) in the Oracle Cloud Infrastructure. And, there’s nothing stopping us from restoring the backups to a different Cloud provider.

In this blog I’ll demonstrate how to backup a database running on AWS to the Oracle Database Backup Cloud Service and then restore the database to a instance running in the Oracle Cloud Infrastructure. This method will also work for migrating on-premise databases to a cloud provider.

Environment

Original Database – AWS
Servercda-aws-test
Operating SystemRed Hat Enterprise Linux release 8.5
Database Version19.17.0.0.0
Database NameCDB01
Target – Oracle Cloud Infrastructure
Servercda-oci-test
Operating SystemOracle Linux Server release 8.6
Database Version19.17.0.0.0
Database NameCDB01

Prerequisites & Parameters

To setup the Oracle Database Cloud Backup Module for OCI you need to collect the following information about your Oracle OCI environment:

Parameter DescriptionParameterExamples used below
Endpoint of the OCI Object store
(Region dependant)
-hosthttps://objectstorage.eu-zurich-1.oraclecloud.com
Private Key file of your API Key-pvtKeyFile/u01/app/oracle/admin/secrets/id_oiam.pem
Public Fingerprint of your API Key-pubFingerPrintb5:xx:xx:xx:5f
Your Tenancy OCID-tOCIDocid1.tenancy.oc1..xxxxxxxxxxxx
User OCID-uOCIDocid1.user.oc1..xxxxxxxxxxxx
Compartment OCID for the bucket-cOCIDocid1.compartment.oc1..xxxxxxxxxxx
Bucket name-bucket orabackup
Folder where the wallet will be saved-walletDir/u01/app/oracle/admin/wallet
Where to save the libopc.so library-libDir$ORACLE_HOME/lib
Where to save the configuration to-configfile/u01/app/oracle/admin/ocibackup/ocibackup.conf

The OCIDs have been masked & shortened for readability and you can find your information in the Oracle OCI console.

Both servers will have to have been granted access through the firewall to the Oracle Object Store, in my example this is https://objectstorage.eu-zurich-1.oraclecloud.com. You can also configure the backup module to use a HTTP proxy if required.

Install the Oracle Database Cloud Backup Module for OCI

This java module performs the following tasks:

  • Installs the Media Management Library in $ORACLE_HOME/lib
  • Creates a Bucket in the Oracle OCI Compartment if it doesn’t already exist
  • Creates a configuration file for use with RMAN
  • Creates a wallet with the credentials for Oracle OCI

The software can be download from Oracle: https://www.oracle.com/database/technologies/oracle-cloud-backup-downloads.html

Supported Oracle Database Versions (EE,SE,SE1,SE2): 10gR2 and above

Supported Platforms (64-bit) : Linux, Solaris, SPARC, Windows, HP-UX, AIX, zLinux

Copy the zip file to both servers and unpack it:

oracle@cda-aws-test:/home/oracle/ [CDB01] unzip -q opc_installer.zip
oracle@cda-aws-test:/home/oracle/ [CDB01] cd opc_installer/oci_installer/
oracle@cda-aws-test:/home/oracle/opc_installer/oci_installer/ [CDB01]$ ls
oci_install.jar  oci_readme.txt
oracle@cda-aws-test:/home/oracle/opc_installer/oci_installer/ [CDB01]

Run java to install the library and setup the configuration file:

$ORACLE_HOME/jdk/bin/java -jar oci_install.jar \
   -host https://objectstorage.eu-zurich-1.oraclecloud.com \
   -pvtKeyFile /u01/app/oracle/admin/secrets/id_oiam.pem \
   -pubFingerPrint b5:xx:xx:xx:5f \
   -tOCID ocid1.tenancy.oc1..xxxxxxxxxxxx \
   -uOCID ocid1.user.oc1..xxxxxxxxxxxx \
   -cOCID ocid1.compartment.oc1..xxxxxxxxxxx \
   -bucket orabackup \
   -walletDir /u01/app/oracle/admin/wallet \
   -libDir $ORACLE_HOME/lib \
   -configfile /u01/app/oracle/admin/ocibackup/ocibackup.conf

Example: Install the Cloud Backup Module for OCI

oracle@cda-aws-test:/home/oracle/opc_installer/oci_installer/ [CDB01] $ORACLE_HOME/jdk/bin/java -jar oci_install.jar \
>   -host https://objectstorage.eu-zurich-1.oraclecloud.com \
>   -pvtKeyFile /u01/app/oracle/admin/secrets/id_oiam.pem \
>   -pubFingerPrint b5:xx:xx:xx:5f \
>   -tOCID ocid1.tenancy.oc1..xxxxxxxxxxxx \
>   -uOCID ocid1.user.oc1..xxxxxxxxxxxx \
>   -cOCID ocid1.compartment.oc1..xxxxxxxxxxx \
>   -bucket orabackup \
>   -walletDir /u01/app/oracle/admin/wallet \
>   -libDir $ORACLE_HOME/lib \
>   -configfile /u01/app/oracle/admin/ocibackup/ocibackup.conf

Oracle Database Cloud Backup Module Install Tool, build 19.3.0.0.0DBBKPCSBP_2019-10-16
Oracle Database Cloud Backup Module credentials are valid.
Backups would be sent to bucket orabackup.
Oracle Database Cloud Backup Module wallet created in directory /u01/app/oracle/admin/wallet.
Oracle Database Cloud Backup Module initialization file /u01/app/oracle/admin/ocibackup/ocibackup.conf created.
Downloading Oracle Database Cloud Backup Module Software Library from Oracle Cloud Infrastructure.
Download complete.
oracle@cda-aws-test:/home/oracle/opc_installer/oci_installer/ [CDB01]

Oracle Recovery Manager Configuration

Now the the module has been installed and configured on the operating system, we now need to setup Oracle Recovery Manager (RMAN) to use it:

CONFIGURE DEFAULT DEVICE TYPE TO SBT;
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CHANNEL DEVICE TYPE SBT
   PARMS='SBT_LIBRARY=libopc.so,
   SBT_PARMS=(OPC_PFILE=/u01/app/oracle/admin/ocibackup/ocibackup.conf)';

Take a database backup with RMAN

We can now take our first backup to the Oracle Cloud. As I’m migrating the database, I’ll take an offline backup.

All database backups to the Oracle Cloud must be encrypted, otherwise the back fails with the following error:

channel ORA_SBT_TAPE_1: starting piece 1 at 10-MAR-2023 12:09:57
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of backup plus archivelog command at 03/10/2023 12:10:00
ORA-27030: skgfwrt: sbtwrite2 returned error
ORA-19511: non RMAN, but media manager or vendor specific failure, error text:
   KBHS-01602: backup piece 031mmjsl_3_1_1 is not encrypted

For simplicity’s sake, I’ll encrypt with the backups with a password and take a full backup including archivelogs:

shutdown immediate
startup mount
set encryption on identified by "orabackup" only;
backup incremental level 0 database;

Example: Database backup:

oracle@cda-aws-test:/home/oracle/ [CDB01] rman target /

Recovery Manager: Release 19.0.0.0.0 - Production on Mon Mar 13 10:53:06 2023
Version 19.17.0.0.0

Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.

connected to target database: CDB01 (DBID=1666982163)

RMAN> shutdown immediate

using target database control file instead of recovery catalog
database closed
database dismounted
Oracle instance shut down

RMAN> startup mount

connected to target database (not started)
Oracle instance started
database mounted

Total System Global Area    2147482744 bytes

Fixed Size                     9137272 bytes
Variable Size                520093696 bytes
Database Buffers            1610612736 bytes
Redo Buffers                   7639040 bytes

RMAN> set encryption on identified by "orabackup" only;

executing command: SET encryption

RMAN> backup incremental level 0 database;

Starting backup at 13-MAR-2023 10:56:30
allocated channel: ORA_SBT_TAPE_1
channel ORA_SBT_TAPE_1: SID=406 device type=SBT_TAPE
channel ORA_SBT_TAPE_1: Oracle Database Backup Service Library VER=19.0.0.1
channel ORA_SBT_TAPE_1: starting incremental level 0 datafile backup set
channel ORA_SBT_TAPE_1: specifying datafile(s) in backup set
input datafile file number=00005 name=/u02/oradata/CDB01/undotbs01CDB01.dbf
input datafile file number=00001 name=/u02/oradata/CDB01/system01CDB01.dbf
input datafile file number=00003 name=/u02/oradata/CDB01/sysaux01CDB01.dbf
input datafile file number=00007 name=/u02/oradata/CDB01/users01CDB01.dbf
channel ORA_SBT_TAPE_1: starting piece 1 at 13-MAR-2023 10:56:33
channel ORA_SBT_TAPE_1: finished piece 1 at 13-MAR-2023 10:56:59
piece handle=2b1mucn1_75_1_1 tag=TAG20230313T105633 comment=API Version 2.0,MMS Version 19.0.0.1
channel ORA_SBT_TAPE_1: backup set complete, elapsed time: 00:00:26
channel ORA_SBT_TAPE_1: starting incremental level 0 datafile backup set
channel ORA_SBT_TAPE_1: specifying datafile(s) in backup set
input datafile file number=00006 name=/u02/oradata/CDB01/pdbseed/undotbs01CDB01.dbf
input datafile file number=00002 name=/u02/oradata/CDB01/pdbseed/system01CDB01.dbf
input datafile file number=00004 name=/u02/oradata/CDB01/pdbseed/sysaux01CDB01.dbf
channel ORA_SBT_TAPE_1: starting piece 1 at 13-MAR-2023 10:56:59
channel ORA_SBT_TAPE_1: finished piece 1 at 13-MAR-2023 10:57:14
piece handle=2c1mucnr_76_1_1 tag=TAG20230313T105633 comment=API Version 2.0,MMS Version 19.0.0.1
channel ORA_SBT_TAPE_1: backup set complete, elapsed time: 00:00:15
Finished backup at 13-MAR-2023 10:57:14

Starting Control File and SPFILE Autobackup at 13-MAR-2023 10:57:15
piece handle=c-1666982163-20230313-01 comment=API Version 2.0,MMS Version 19.0.0.1
Finished Control File and SPFILE Autobackup at 13-MAR-2023 10:57:18

RMAN>

These backup files are visible in the Oracle Cloud Storage Bucket:

Restore the Database to an Oracle OCI Instance

On the new server the Oracle Database Cloud Backup Module for OCI should have been installed in the Oracle Home which is being used for the restore.

As we don’t have a spfile or controlfiles for the database, we can’t save the RMAN SBT Library configuration, so we’ll have to allocate the RMAN channel in each restore manually, until we have restored the controlfiles.

Restore the spfile:

rman target /
startup nomount

set decryption identified by "orabackup";
set dbid=1666982163;

run {
   allocate channel oci1 device type sbt parms 
      'SBT_LIBRARY=libopc.so ENV=(OPC_PFILE=/u01/app/oracle/admin/ocibackup/ocibackup.conf)';
   restore spfile to pfile '/u01/app/oracle/product/19.0.0/dbhome_1/dbs/initCDB01.ora'
      from autobackup;
   release channel oci1;
}

Example: Restore spfile

oracle@cda-oci-test:/home/oracle/ [CDB01]  rman target /

Recovery Manager: Release 19.0.0.0.0 - Production on Mon Mar 13 10:16:49 2023
Version 19.17.0.0.0

Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.

connected to target database (not started)

RMAN> startup nomount

startup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/u01/app/oracle/product/19.0.0/dbhome_1/dbs/initCDB01.ora'

starting Oracle instance without parameter file for retrieval of spfile
Oracle instance started

Total System Global Area    1073737800 bytes

Fixed Size                     8904776 bytes
Variable Size                276824064 bytes
Database Buffers             780140544 bytes
Redo Buffers                   7868416 bytes

RMAN> set decryption identified by "orabackup";

executing command: SET decryption
using target database control file instead of recovery catalog

RMAN> set dbid=1666982163;

executing command: SET DBID

RMAN> run {
2>    allocate channel oci1 device type sbt parms
3>       'SBT_LIBRARY=libopc.so ENV=(OPC_PFILE=/u01/app/oracle/admin/ocibackup/ocibackup.conf)';
4>    restore spfile to pfile '/u01/app/oracle/product/19.0.0/dbhome_1/dbs/initCDB01.ora'
5>       from autobackup;
6>    release channel oci1;
7> }

allocated channel: oci1
channel oci1: SID=19 device type=SBT_TAPE
channel oci1: Oracle Database Backup Service Library VER=19.0.0.1

Starting restore at 13-MAR-2023 10:17:58

channel oci1: looking for AUTOBACKUP on day: 20230313
channel oci1: AUTOBACKUP found: c-1666982163-20230313-01
channel oci1: restoring spfile from AUTOBACKUP c-1666982163-20230313-01
channel oci1: SPFILE restore from AUTOBACKUP complete
Finished restore at 13-MAR-2023 10:18:04

released channel: oci1

RMAN>

Stop the database and modify the restored init.ora if required. As both my servers have the same filesystem structure, I can just restart the database with the restored init.ora and restore the control file.

shutdown immediate
startup nomount pfile=/u01/app/oracle/product/19.0.0/dbhome_1/dbs/initCDB01.ora
set decryption identified by "orabackup";
set dbid=1666982163;
run {
   allocate channel oci1 device type sbt parms 
      'SBT_LIBRARY=libopc.so ENV=(OPC_PFILE=/u01/app/oracle/admin/ocibackup/ocibackup.conf)';
   restore controlfile from autobackup;
   release channel oci1;
}
alter database mount;

Example: Restore controlfile

RMAN> shutdown immediate
Oracle instance shut down
RMAN> startup nomount pfile=/u01/app/oracle/product/19.0.0/dbhome_1/dbs/initCDB01.ora

connected to target database (not started)
Oracle instance started

Total System Global Area    2147482744 bytes

Fixed Size                     9137272 bytes
Variable Size                520093696 bytes
Database Buffers            1610612736 bytes
Redo Buffers                   7639040 bytes

RMAN> set decryption identified by "orabackup";

executing command: SET decryption

RMAN> set dbid=1666982163;

executing command: SET DBID

RMAN> run {
2>    allocate channel oci1 device type sbt parms
3>       'SBT_LIBRARY=libopc.so ENV=(OPC_PFILE=/u01/app/oracle/admin/ocibackup/ocibackup.conf)';
4>    restore controlfile from autobackup;
5>    release channel oci1;
6> }

allocated channel: oci1
channel oci1: SID=20 device type=SBT_TAPE
channel oci1: Oracle Database Backup Service Library VER=19.0.0.1

Starting restore at 13-MAR-2023 10:19:11

channel oci1: looking for AUTOBACKUP on day: 20230313
channel oci1: AUTOBACKUP found: c-1666982163-20230313-01
channel oci1: restoring control file from AUTOBACKUP c-1666982163-20230313-01
channel oci1: control file restore from AUTOBACKUP complete
output file name=/u02/oradata/CDB01/control01CDB01.dbf
output file name=/u03/oradata/CDB01/control02CDB01.dbf
output file name=/u04/oradata/CDB01/control03CDB01.dbf
Finished restore at 13-MAR-2023 10:19:19

released channel: oci1

RMAN> alter database mount;

Statement processed

RMAN>

Now we can set the default device and it’s parameters:

CONFIGURE CHANNEL DEVICE TYPE sbt 
   PARMS='SBT_LIBRARY=libopc.so,
   SBT_PARMS=(OPC_PFILE=/u01/app/oracle/admin/ocibackup/ocibackup.conf)';

The database can be restored on the target system with normal RMAN commands:

restore database;
alter database open resetlogs;

Example: Database restore and recover

RMAN> restore database;

Starting restore at 13-MAR-2023 10:19:51
using channel ORA_SBT_TAPE_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=409 device type=DISK

channel ORA_SBT_TAPE_1: starting datafile backup set restore
channel ORA_SBT_TAPE_1: specifying datafile(s) to restore from backup set
channel ORA_SBT_TAPE_1: restoring datafile 00001 to /u02/oradata/CDB01/system01CDB01.dbf
channel ORA_SBT_TAPE_1: restoring datafile 00003 to /u02/oradata/CDB01/sysaux01CDB01.dbf
channel ORA_SBT_TAPE_1: restoring datafile 00005 to /u02/oradata/CDB01/undotbs01CDB01.dbf
channel ORA_SBT_TAPE_1: restoring datafile 00007 to /u02/oradata/CDB01/users01CDB01.dbf
channel ORA_SBT_TAPE_1: reading from backup piece 2b1mucn1_75_1_1
channel ORA_SBT_TAPE_1: piece handle=2b1mucn1_75_1_1 tag=TAG20230313T105633
channel ORA_SBT_TAPE_1: restored backup piece 1
channel ORA_SBT_TAPE_1: restore complete, elapsed time: 00:01:15
channel ORA_SBT_TAPE_1: starting datafile backup set restore
channel ORA_SBT_TAPE_1: specifying datafile(s) to restore from backup set
channel ORA_SBT_TAPE_1: restoring datafile 00002 to /u02/oradata/CDB01/pdbseed/system01CDB01.dbf
channel ORA_SBT_TAPE_1: restoring datafile 00004 to /u02/oradata/CDB01/pdbseed/sysaux01CDB01.dbf
channel ORA_SBT_TAPE_1: restoring datafile 00006 to /u02/oradata/CDB01/pdbseed/undotbs01CDB01.dbf
channel ORA_SBT_TAPE_1: reading from backup piece 2c1mucnr_76_1_1
channel ORA_SBT_TAPE_1: piece handle=2c1mucnr_76_1_1 tag=TAG20230313T105633
channel ORA_SBT_TAPE_1: restored backup piece 1
channel ORA_SBT_TAPE_1: restore complete, elapsed time: 00:00:35
Finished restore at 13-MAR-2023 10:21:42

RMAN> alter database open resetlogs;

Statement processed

RMAN>

Conclusion

The Oracle Database Backup Cloud Service has been around for a while and provides a simple to setup and use cloud backup for your on-premise or cloud hosted databases.

Once stored in the Oracle Cloud Object Store the backups can be moved to different storage tiers to reduce costs and they can even be replicated to other Oracle Cloud Regions using OCI Object Storage Replication to increase your disaster recovery capabilities.

And as we have seen, it can also be used to migrate databases between cloud providers.