Using AWS Backup and Oracle RMAN for backup/restore of Oracle databases on Amazon EC2: Part 2
AWS Architecture BlogUsing AWS Backup and Oracle RMAN for backup/restore of Oracle databases on Amazon EC2: Part 2by Jeevan Shetty, Bhanu Ganesh Gudivada, Santhosh Kumar Adapa, and Srini Ramaswamy | on11 JUL 2022| inAmazon EC2,Amazon Elastic File System (EFS),Amazon Simple Storage Service (S3),Architecture,AWS Backup|Permalink|ShareCustomers running Oracle databases onAmazon Elastic Compute Cloud (Amazon EC2)often take database and schema backups using Oracle native tools like Data Pump and Recovery Manager (RMAN) to satisfy data protection, disaster recovery (DR), and compliance requirements. A priority is to reduce backup time as the data grows exponentially and recover sooner in case of failure/disaster.InPart 1of this two-part series, we explain how we can useAWS BackupandAmazon Simple Storage Service (Amazon S3)bucket to perform the backup and restore of an Oracle Database on AWS EC2.In Part 2, we provide a mechanism to use AWS Backup to create a full backup of the EC2 instance, including the OS image, Oracle binaries, logs, and data files. The mechanism also uses Oracle RMAN to perform archived redo log backup toAmazon Elastic File System (Amazon EFS). Then, we demonstrate the steps to restore a database to a specific point-in-time using AWS Backup and Oracle RMAN.Solution overviewFigure 1 demonstrates the workflow:Oracle database on Amazon EC2 configured withOracle Secure Backup.AWS Backup service to backup EC2 instance at regular intervals.Amazon EFS for storing Oracle RMAN archive log backups.Figure 1. Oracle Database in Amazon EC2 using AWS Backup and EFS for backup and restorePrerequisitesAn AWS accountOracle database and AWS CLI in an EC2 instanceAccess to configure AWS BackupAccess to configure EFS to store the Oracle RMAN archive log backups1. Configure AWS BackupConfigure AWS Backup as detailed in Step 1 ofPart 1.Oracle RMAN archive log backupWhile AWS Backup is now creating a daily backup of the EC2 instance, we also want to make sure we backup the archived log files to a protected location. This will let us do point-in-time restores and restore to more recent times than just the last daily EC2 backup. Below we provide the steps to backup archive log using RMAN to Amazon EFS.Backup/restore archive logs to/from Amazon EFSBacking up theOracle Archivelogs is an important part of the process. In this section, we will describe how you can backup their Oracle archive logs to Amazon EFS. One advantage of this option (as compared with using Oracle Secure Backup [detailed inPart 1of this series]) is that it does not require any additional Oracle licensing.2. Configure Amazon EFSa.Create an Amazon EFS file systemthat will be used to store Oracle RMAN Archive log backups. The image below details the steps involved in creation of an Amazon EFS. Consider that a sample file system ID:fs-0123abcdef012345is created and will be used to store RMAN archive log backup.Figure 2. Configure Amazon EFS which is used to store Oracle RMAN archive log backupsb. Install theAmazon EFS Clientand follow instructions to install EFS client on RHEL EC2 instance. Note: next steps were tested on RHEL 7.9.sudo yum -y install git
sudo yum -y install rpm-build
git clone https://github.com/aws/efs-utils
cd efs-utils/
sudo yum -y install make
sudo make rpm
sudo yum -y install ./build/amazon-efs-utils*rpmc.Mount the EFS file systemon your EC2 instance. In this example, we show the steps to mount EFS filesystem on EC2 Instance (if the command requests to upgradestunnel, refer toUpgrading stunnel. Ensure that the EC2 instance profile attached has necessary policies to access EFS./rmanfor mount point and file system ID:fs-0123abcdef012345are examples for EFS file system.sudo mkdir /rman
sudo mount -t efs -o tls,iam fs-0123abcdef012345 /rmand. To mount EFS file system automatically on EC2 instance reboot, add an entry in/etc/fstab. This example is for RHEL EC2 instance:fs-0123abcdef012345:/      /rman        efs     _netdev,tls,iam        0 03. Configure RMAN backup to Amazon EFSWith Amazon EFS mounted on EC2 instance, we can configure Oracle RMAN archive log backups to EFS. In below commandsoratstis used as an example of yourORACLE_SID.a. Configure RMAN repository to take control file backup to Amazon EFS automatically.CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/rman/ctrl-D_%d_%F';
CONFIGURE CONTROLFILE AUTOBACKUP ON;b. Create a script (for example, rman_archive.sh) with below commands and schedule usingcrontab(example entry:*/5 * * * * rman_archive.sh) to run every 5 minutes. This will ensure that Oracle Archive logs are backed up to Amazon EFS (/rman) frequently, ensuring anrecovery point objective (RPO)of 5 minutes.dt=`date +%Y%m%d_%H%M%S`

rman target / log=/rman/rman_arch_bkup_oratst_${dt}.log <<EOF

RUN
{
    allocate channel c1_efs device type disk format '/rman/arch-D-%d_%T_s%s_p%p' MAXPIECESIZE 10G;
    BACKUP ARCHIVELOG ALL delete all input;
    release channel c1_efs;
}

EOF4. Perform database point-in-time recoveryIn event of a database crash/corruption, we can use AWS Backup service and Oracle RMAN archive log backup to recover database to a specific point-in-time.a. Typically, you would pick the most recent Recovery Point completed before the time to which you wish to recover. Using AWS Backup, identify the Recovery point ID to restore by following the steps fromRestoring an Amazon EC2 instance. Note: when following the steps, be sure to set the “User data” settings as described in the next bulleted item.After the EBS volumes are created from the snapshot, there is no need to wait for all of the data to transfer from Amazon S3 to your Amazon EBS volume before your attached instance can start accessing the volume. Amazon EBS Snapshots implement lazy loading, so that you can begin using them right away.b. Ensure that database does not start automatically after restoring the EC2 instance, by renaming/etc/oratab. Use below command in “User data” section while restoring EC2 instance. After database recovery, we can rename it back to/etc/oratab.#!/usr/bin/sh
sudo su - 
mv /etc/oratab /etc/oratab_bkc. Login to the EC2 instance once it is up and execute the RMAN recovery commands mentioned below. Identify theDBIDfrom RMAN logs saved in the EFS. Below commands use databaseoratstas an example.rman target /

RMAN> startup nomount

RMAN> set dbid DBID


# Below command is to restore the controlfile from autobackup

RMAN> RUN
{
    set controlfile autobackup format for device type disk to '/rman/ctrl-D_%d_%F';
    RESTORE CONTROLFILE FROM AUTOBACKUP;
    alter database mount;
}


#Identify the recovery point (sequence_number) by listing the backups available in catalog.

RMAN> list backup;In Figure 3, the most recent archive log backed up is 460, so you can use this sequence number in the next set of RMAN commands.RMAN> RUN
{
    allocate channel c1_efs device type disk format '/rman/arch-D-%d_%T_s%s_p%p';    
    recover database until sequence sequence_number;
    ALTER DATABASE OPEN RESETLOGS;
    release channel c1_efs;
}Figure 3. Sample output of Oracle RMAN “list backup” commandd. To avoid performance issues due to lazy loading, after the database is open, you can run below command to force a faster restoration of the blocks from S3 bucket to EBS volumes (below example allocates two channels and validates the entire database).RMAN> RUN
{
  ALLOCATE CHANNEL c1 DEVICE TYPE DISK;
  ALLOCATE CHANNEL c2 DEVICE TYPE DISK;
  VALIDATE database section size 1200M;
}e. This completes the recovery of database, and we can let the database to auto start by renaming file back to/etc/oratab.mv /etc/oratab_bk /etc/oratab5. Backup retentionEnsure that theAWS Backup Lifecycle policymatch Oracle archive log backup retention. Also, follow documentation to configure Oracle backupretentionand deletingexpiredbackup. Below is a sample command for Oracle backup retention.CONFIGURE BACKUP OPTIMIZATION ON;
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 31 DAYS; 

RMAN> RUN
{
    allocate channel c1_efs device type disk format '/rman/arch-D-%d_%T_s%s_p%p';

    crosscheck backup;
    delete noprompt obsolete;
    delete noprompt expired backup;
    
    release channel c1_efs;
}CleanupFollow below instructions to remove or cleanup the setup:Delete the backup plancreated in Step 1.Remove the cron entry from the EC2 instance configured in Step 3b.Delete the EFSthat was created in Step 2 to store Oracle RMAN archive log backups.ConclusionIn this post, we demonstrated the use for AWS Backup for EC2 snapshot and EFS as storage for Oracle RMAN archive log backups. With this strategy for backup, Oracle Database running on EC2 can be restored and recovered to a point-in-time faster than oracle native backup and recovery strategies. Also, by using EFS for Oracle RMAN archive log backups, we can avoid the additional licensing required to useOracle Secure Backup, explained inPart 1. You can leverage this solution to facilitate restoring copies of your production database for development or testing purposes and to Recover from a user error that removes data or corrupts existing data.To learn more about AWS Backup, refer to theAWS Backup Documentation.Jeevan ShettyJeevan Shetty is a Consultant with the AWS Proserve Team. He has been supporting and enabling customers to migrate their database from OnPrem data center to AWS cloud and also in migration from commercial database engines to open source database in Amazon.Bhanu Ganesh GudivadaBhanu Ganesh Gudivada is a Database Consultant with the Professional Services team at AWS and specializes in database migrations. He has been supporting and enabling customers to build high-available, cost-effective database solutions and migrate their commercial engines to AWS cloud. Bhanu is curious to learn and implement new technologies around the databases and orchestrate migrations through automation.Santhosh Kumar AdapaSanthosh Kumar Adapa is a Database Consultant with the Professional Services team at AWS. He works as a database migration specialist to help Amazon customers in design and implementing scalable, secure, performant, and robust database solutions on the cloud.Srini RamaswamySrini Ramaswamy is a Consultant with the AWS Proserve Team. He has been supporting and enabling customers to migrate their database from OnPrem data center to AWS cloud and also in migration from commercial database engines to open source database in Amazon.
Customers running Oracle databases on Amazon Elastic Compute Cloud (Amazon EC2) often take database and schema backups using Oracle native tools like Data Pump and Recovery Manager (RMAN) to satisfy data protection, disaster recovery (DR), and compliance requirements. A priority is to reduce backup time as the data grows exponentially and recover sooner in case […]
Jeevan Shetty
Amazon EC2 Amazon Elastic File System (EFS) Amazon Simple Storage Service (S3) Architecture AWS Backup