Back Up a Database to Object Storage Using RMAN
This article explains how to use Recovery Manager (RMAN) to manage backups of your DB system database to your own Object Storage.
To back up to the service you'll need to create an Object Storage bucket for the backups, generate a password for the service, install the Oracle Database Cloud Backup Module, and then configure RMAN to send backups to the service. The backup module is a system backup to tape (SBT) interface that's tightly integrated with RMAN, so you can use familiar RMAN commands to perform backup and recovery operations.
You'll notice Swift mentioned in the Console and in the endpoint URL for the service. That's because the backup module is typically used to back up to the Oracle Database Backup Cloud Service, which is an OpenStack Swift object store.
Tip:
On a single-node DB system, you can use the DBCLI to back up to Object Storage. This is an alternative to installing the backup module and using RMAN for backups. For more information, see Objectstoreswift Commands. Note that thedbcli
commands are not available for multi-node RAC DB systems.
Prerequisites
You'll need the following:
- A DB system and a database to back up.
- The DB system's cloud network (VCN) must be configured with access to Object Storage:
- For Object Storage access in the same region as the DB system: Oracle recommends using a service gateway.
- For Object Storage access in a different region than the DB system: Use an internet gateway. Note that the network traffic between the DB system and Object Storage does not leave the cloud and never reaches the public internet.
For more information, see VCN and Subnets.
- An existing Object Storage bucket to use as the backup destination. You can use the Console or the Object Storage API to create the bucket.
For more information, see Managing Buckets.
- An auth token generated by OCI. You can use the Console or the IAM API to generate the password.
For more information, see working with auth tokens in Managing User Credentials.
-
The user name (specified when you install and use the backup module) must have tenancy-level access to Object Storage. An easy way to do this is to add the user name to the Administrators group. However, that allows access to all of the cloud services. Instead, an administrator should create a policy like the following that limits access to only the required resources in Object Storage for backing up and restoring the database:
Allow group <group_name> to manage objects in compartment <compartment_name> where target.bucket.name = '<bucket_name>' Allow group <group_name> to read buckets in compartment <compartment_name>
For more information about adding a user to a group, see Managing Groups. For more information about policies, see Getting Started with Policies.
Install the Backup Module On the DB System
- SSH to the DB system.
ssh -i <SSH_key_used_when_launching_the_DB_system> opc@<DB_system_IP_address_or_hostname>
- Log in as
opc
user.login as: opc
sudo
to theoracle
user.sudo su - oracle
- Change to the directory that contains the backup module
opc_install.jar
file.cd /opt/oracle/oak/pkgrepos/oss/odbcs
- Use the following command syntax to install the backup module.
java -jar opc_install.jar -opcId <user_id> -opcPass '<auth_token>' -container <bucket_name>;-walletDir ~/hsbtwallet/ -libDir ~/lib/ -configfile ~/config -host https://swiftobjectstorage.<region_name>.oraclecloud.com/v1/<object_storage_namespace>
The parameters are:
Parameter Description -opcId
The user name for the Oracle Cloud Infrastructure user account, for example:
-opcId <username>@<example>.com
.This is the user name you use to sign in to the Console.
The user name must be a member of the Administrators group, as described in the Prerequisites section.
You can also specify the user name in single quotes. This might be necessary if the name contains special characters, for example:
-opcId 'j~smith@<example>.com'
Make sure to use straight single quotes and not slanted apostrophes.
-opcPass
The auth token generated by using the Console or IAM API, in single quotes, for example:
-opcPass <password>
Make sure to use straight single quotes and not slanted apostrophes.
For more information, see Managing User Credentials.
This is not the password for the Oracle Cloud Infrastructure user.
-container
The name of an existing bucket in Object Storage to use as the backup destination, for example:
-container DBBackups
-walletDir
The directory where the install tool will create an Oracle Wallet containing the Oracle Cloud Infrastructure user name and auth token.
-walletDir ~/hsbtwallet
creates the wallet in the current user (oracle) home directory.-libDir
The directory where the SBT library is stored. The directory must already exist before you run the command. This parameter causes the latest SBT library to be downloaded.
-libDir ~/lib/
downloads thelibopc.so
file to the current user's home directory, for example,/home/oracle/lib/libopc.so
.-configfile
The name of the initialization parameter file that will be created by the install tool. This file will be referenced by your RMAN jobs.
-configfile ~/config
creates the file in the current user's home directory, for example,/home/oracle/config
.-host
The endpoint URL to which backups are to be sent:
https://swiftobjectstorage.<region_name>.oraclecloud.com/v1/<object_storage_namespace>
where
object_storage_namespace
is your tenancy's Object Storage namespace. For more information, see Understanding Object Storage Namespaces.Do not add a slash after the Object Storage namespace.
To look up the region name, see Regions and Availability Domains.
Configure RMAN
This topic describes how to configure RMAN to use the bucket as the default backup destination. The following assumes you are still logged in to the DB system.
- On the DB system, set the
ORACLE_HOME
andORACLE_SID
environment variables using theoraenv
utility.. oraenv
- Connect to the database using RMAN.
rman target /
- Configure RMAN to use the SBT device and point to the
config
file that was created when you installed the backup module. A sample command for a version 12 database is shown here.CONFIGURE CHANNEL DEVICE TYPE 'SBT_TAPE' PARMS 'SBT_LIBRARY=/home/oracle/lib/libopc.so, SBT_PARMS=(OPC_PFILE=/home/oracle/config)';
- Configure RMAN to use SBT_TAPE by default. The following sample enables the controlfile and spfile autobackup to SBT_TAPE and configures encryption. There are other settings that may apply to your installation such as compression, number of backup and recovery channels to use, backup retention policy, archived log deletion policy, and more. See the Oracle Backup and Recovery documentation for your version of Oracle for more information on choosing the appropriate settings.
CONFIGURE DEFAULT DEVICE TYPE TO SBT_TAPE; CONFIGURE BACKUP OPTIMIZATION ON; CONFIGURE CONTROLFILE AUTOBACKUP ON; CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE SBT_TAPE TO '%F'; CONFIGURE ENCRYPTION FOR DATABASE ON;
Note
Backups must be encrypted. You will specify encryption when you perform a backup. You will get an error if a backup is not encrypted.
Once the RMAN configuration is complete, you can use the same RMAN commands that you regularly use for tape backups.
Back Up the Database
This topic provides examples of commonly used backup commands.
- Set the database encryption:
SET ENCRYPTION IDENTIFIED BY "password" ONLY;
Note that this setting is not permanent; you must set it for each new RMAN session.
- Back up the database and archivelogs. Below are some example commands. See the Oracle Backup and Recovery documentation for your version of Oracle for more information about choosing a back up procedure that meets your needs. Be sure to back up regularly to minimize potential data loss and always include a copy of the spfile and controlfile. Note that the example below uses multi-section incremental backups, which is a feature introduced in 12c. When using 11g, omit the
section size
clause.BACKUP INCREMENTAL LEVEL 0 SECTION SIZE 512M DATABASE PLUS ARCHIVELOG;
BACKUP INCREMENTAL LEVEL 1 SECTION SIZE 512M DATABASE PLUS ARCHIVELOG;
BACKUP INCREMENTAL LEVEL 1 CUMULATIVE SECTION SIZE 512M DATABASE PLUS ARCHIVELOG;
- Backup archivelogs frequently to minimize potential data loss, and keep multiple backup copies as a precaution.
BACKUP ARCHIVELOG ALL NOT BACKED UP 2 TIMES;
When the backup job completes, you can display the backup files in your bucket in the Console on the Storage page, by selecting Object Storage.