How to take Immutable backups in Oracle Database

Some organizations need to comply with Government regulations about backup retention and protection, in OCI we have a feature called Retention Rule in Object Storage, combine this feature with the new version of RMAN opc module and we can achieve Immutability in Oracle backups (running in cloud or on premises).

In this article I will show how to implement the module and run a backup of Oracle DB to Object storage, this is an interpretation of the this documentation, always consult the oficial documentation!

Installation

The installation process is straightforward, you need to get the installer from this link https://docs.oracle.com/en/cloud/paas/db-backup-cloud/csdbb/installing-oracle-database-cloud-backup-module-oci.html the module supports from version 11.2.0.4 (Enterprise or Standard) and for Standard you need a patch to enable the encryption option.

Besides the installer, you will need an account from OCI with rights to write and manage objects in buckets.

Go to OCI console and create two buckets, one to store the protected backups(bucket-imutavel in my case) and another to keep temporary metadatas files(bucket-imutavel-tmp).

For the backup bucket, create a retention rule, you can find it in the left side of the page, this option will guarantee the backup security.

In OCI you could have a retention based on time (the recommended) and an Indefinite option, the Time-bound option guarantee the protection based on a time defined by user and the Indefinite could be deleted at any time.

The retention time is based on the Last modified metadata of file and you can define it in days or years, my tip here is to start with a lower retention time and grow it after you feel safe about the options.

Besides the retention time, you can enable a Rule Lock, this mean if you have objects in the retention period, no one can delete the Retention Rule, this is a nice feature and I suggest to you to enable it.

With buckets and retention rule in place we need to run the installer:

[oracle@dbcs19c opc_imm]$ java -jar oci_install.jar \
> -host https://objectstorage.us-ashburn-1.oraclecloud.com \
> -pvtKeyFile /home/oracle/.oci/api_key.pem \
> -pubFingerPrint xxxxxxxxx\
> -uOCID ocid1.user.oc1..xxxxxxxx \
> -tOCID ocid1.tenancy.oc1..xxxxxxxxxx \
> -walletDir /u01/app/oracle/product/19.0.0/dbhome_1/dbs/wallet_opc/ \
> -libDir /u01/app/oracle/product/19.0.0/dbhome_1/lib/ \
> -cOCID ocid1.compartment.oc1..xxxxxxxxx 

And after it, adjust the opc file with the new parameters:

OPC_CONTAINER=bucket-imutavel
OPC_TEMP_CONTAINER=bucket-imutave-tmp

Tests

Now that we have everything in place, we can configure our RMAN channel to use the library file and run a simple backup.

RMAN> CONFIGURE CHANNEL DEVICE TYPE 'SBT_TAPE' PARMS  'SBT_LIBRARY=/u01/app/oracle/product/19.0.0/dbhome_1/lib/libopc.so,SBT_PARMS=(OPC_PFILE=/u01/app/oracle/product/19.0.0/dbhome_1/dbs/opcorcl19.ora)';

old RMAN configuration parameters:
CONFIGURE CHANNEL DEVICE TYPE 'SBT_TAPE' PARMS  'SBT_LIBRARY=/u01/app/oracle/product/19.0.0/dbhome_1/dbs/lib_bkp/libopc.so,SBT_PARMS=(OPC_PFILE=/u01/app/oracle/product/19.0.0/dbhome_1/dbs/opcorcl19.ora)';
new RMAN configuration parameters:
CONFIGURE CHANNEL DEVICE TYPE 'SBT_TAPE' PARMS  'SBT_LIBRARY=/u01/app/oracle/product/19.0.0/dbhome_1/lib/libopc.so,SBT_PARMS=(OPC_PFILE=/u01/app/oracle/product/19.0.0/dbhome_1/dbs/opcorcl19.ora)';
new RMAN configuration parameters are successfully stored

The opcSID.ora file store the parameters that you used to install the module:

[oracle@dbcs19c ~]$ cat /u01/app/oracle/product/19.0.0/dbhome_1/dbs/opcorcl19.ora
OPC_HOST=https://objectstorage.us-ashburn-1.oraclecloud.com/n/NAMESPACE
OPC_WALLET='LOCATION=file:/u01/app/oracle/product/19.0.0/dbhome_1/dbs/wallet_opc CREDENTIAL_ALIAS=alias_oci'
OPC_CONTAINER=bucket-imutavel
OPC_TEMP_CONTAINER=bucket-imutavel-tmp
OPC_COMPARTMENT_ID=ocid1.compartment.oc1..XXXXX
OPC_AUTH_SCHEME=BMC

We need to specify one type of encryption, to keep it simple, I will use a password based encryption:

RMAN> set encryption on identified by 'PASSWORD' only;

I can run a backup

RMAN> backup current controlfile;

Starting backup at xxxxxxxxx
allocated channel: ORA_SBT_TAPE_1
channel ORA_SBT_TAPE_1: SID=49 device type=SBT_TAPE
channel ORA_SBT_TAPE_1: Oracle Database Backup Service Library VER=xxxxxxx
channel ORA_SBT_TAPE_1: starting compressed full datafile backup set
channel ORA_SBT_TAPE_1: specifying datafile(s) in backup set
including current control file in backup set
channel ORA_SBT_TAPE_1: starting piece 1 at xxxxxxx
channel ORA_SBT_TAPE_1: finished piece 1 at xxxxxxx
piece handle=da0s5jds_28074_1_1 tag=TAGxxxxxxxxx comment=API Version 2.0,MMS Version xxxxxxx
channel ORA_SBT_TAPE_1: backup set complete, elapsed time: 00:00:03
Finished backup at xxxx

Starting Control File and SPFILE Autobackup at xxxxxxx

piece handle=c-xxxxxxxxx comment=API Version 2.0,MMS Version xxxxxxx
Finished Control File and SPFILE Autobackup at xxxxxxx


RMAN>

And confirm it in the right bucket

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
27830   Full    3.00M      SBT_TAPE    00:00:02     xxxxx      
        BP Key: 27830   Status: AVAILABLE  Compressed: YES  Tag: TAGxxxxx
        Handle: c-xxxxx-xxxxx   Media: objectstorag~.us-ashburn-~.oraclecloud.com/n/id~/bucket-imutavel
  Control File Included: Ckp SCN: 106913659    Ckp time: 2xxxx

If I try to remove the backup I will get an error

RMAN> delete backuppiece 27830;

using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=69 device type=DISK
allocated channel: ORA_SBT_TAPE_1
channel ORA_SBT_TAPE_1: SID=204 device type=SBT_TAPE
channel ORA_SBT_TAPE_1: Oracle Database Backup Service Library VER=xxxxxx

List of Backup Pieces
BP Key  BS Key  Pc# Cp# Status      Device Type Piece Name
------- ------- --- --- ----------- ----------- ----------
27830   27830   1   1   AVAILABLE   SBT_TAPE   c-xxxxx-xxxxx

Do you really want to delete the above objects (enter YES or NO)? yes
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03009: failure of delete command on ORA_SBT_TAPE_1 channel at xxxxxxx 14:05:54
ORA-19509: failed to delete sequential file, handle="c-xxxxxxxxxxx", parms=""
ORA-27027: sbtremove2 returned error
ORA-19511: non RMAN, but media manager or vendor specific failure, error text:
   KBHS-01404: See trace file /u01/app/oracle/diag/rdbms/orcl19_iad224/orcl19/trace/sbtio_53270_140555879019520.log for details
KBHS-00719: Error 'RetentionRuleViolation'; The operation was blocked by a retention rule.
KBHS-00700: HTTP response error 'Forbi

Bonus tip

You can configure Service connector Hub to monitor the logs from bucket and send notifications if someone try to delete files.

Monitor the data.message when it have RetentionRuleViolation value.

chevron_left
chevron_right