Monday, July 28, 2025

Creating a Custom Backup Strategy for Oracle Databases on OCI Compute Using Object Storage

 

Introduction

While Oracle Cloud Infrastructure (OCI) offers built-in backup capabilities for Autonomous and DBCS databases, many DBAs run Oracle databases on OCI Compute (i.e., manually installed databases on VMs). For these, automated and cost-effective backups must be designed manually.

In this post, we’ll walk through how to implement a custom backup strategy using RMAN + shell scripts, and push backups to OCI Object Storage, ensuring secure, scalable, and low-cost storage of your database backups.

Why Use Object Storage for Backups?

  • Cost-effective (only pay for what you store)

  • Highly durable (99.999999999%)

  • Reduces local disk usage

  • Can be encrypted, versioned, and lifecycle-managed

  • Easily integrated with RMAN and shell scripts

Step 1: Set Up OCI Object Storage Bucket

  1. Go to OCI Console → Object Storage → Create Bucket

  2. Choose:

    • Bucket Name: db-backups-prod

    • Storage Tier: Standard

    • Visibility: Private

  3. Copy the namespace (you'll need this in the script)

Step 2: Install OCI CLI on the DB Server

curl -L https://raw.githubusercontent.com/oracle/oci-cli/master/scripts/install/install.sh | bash
 
After install, configure: 

oci setup config

Provide tenancy OCID, user OCID, region, private key path, etc. 

Step 3: Create the RMAN Backup Script

rman target / <<EOF
RUN {
  ALLOCATE CHANNEL ch1 DEVICE TYPE DISK;
  BACKUP AS COMPRESSED BACKUPSET DATABASE FORMAT '/u01/backups/DB_%U.bkp';
  BACKUP CURRENT CONTROLFILE FORMAT '/u01/backups/CTL_%U.ctl';
  RELEASE CHANNEL ch1;
}
EOF

Step 4: Upload Backup Files to Object Storage

Here’s the shell script to upload all .bkp files to OCI:

#!/bin/bash

# Variables
BACKUP_DIR="/u01/backups"
BUCKET_NAME="db-backups-prod"
NAMESPACE="your_namespace"
OCI_PROFILE="DEFAULT"

# Upload all backups
for file in $BACKUP_DIR/*.bkp $BACKUP_DIR/*.ctl; do
  oci os object put -ns $NAMESPACE -bn $BUCKET_NAME --file "$file" --profile $OCI_PROFILE
done

# Optional: Delete local backups after upload
rm -f $BACKUP_DIR/*.bkp $BACKUP_DIR/*.ctl
 

Step 5: Automate with Cron 

crontab -e

# Backup and upload every night at 2 AM
0 2 * * * /home/oracle/scripts/backup_and_upload.sh

Security Best Practices

  • Use an OCI dynamic group and IAM policy if using Instance Principals.

  • Encrypt backup sets with CONFIGURE ENCRYPTION in RMAN.

  • Use Object Storage lifecycle policies to auto-expire older backups.

Conclusion

Even without Autonomous DB or DBCS, you can create a robust and scalable backup system on OCI using just RMAN, shell scripting, and Object Storage. It gives you full control, reduces costs, and meets compliance needs with proper encryption and retention.


 


 

 

No comments:

Post a Comment

Auto Shutdown and Restart of Oracle DB Systems in OCI Using Functions

  🔹 Introduction Oracle Cloud Infrastructure (OCI) Database Systems incur compute costs even when idle. If you're running non-producti...