Automate RMAN Backups using Shell Scripts

In a real environment, off course you will not manually trigger all the Oracle database backups. You need an automated mechanism to trigger RMAN backups.

In this article we will look at RMAN backup automation using shell scripts.

Create directory structure

On your database server, create a directory structure to hold RMAN backups and all related files. All the RMAN backups, logs and backup scripts are kept in one directoy.

mkdir /u02/rman

We will call this directory as rman base directory. Under the RMAN base directory, create below folders

  • /u02/rman/scripts = to hold RMAN script files
  • /u02/rman/logs = to hold RMAN backup logs
  • /u02/rman/backups = to hold all RMAN backups

Create RMAN backup script file

Under the scripts folder (/u02/rman/scripts), we will create a file that contains the rman run block. This file is the one which will take the database backup

cd /u02/rman/scripts

vi db_full_backup.rman

run
{
allocate channel ch1 device type disk format '/u02/rman/backups/PRODDB_DBFULL_BKP_%u';
allocate channel ch2 device type disk format '/u02/rman/backups/PRODDB_DBFULL_BKP_%u';
allocate channel ch3 device type disk format '/u02/rman/backups/PRODDB_DBFULL_BKP_%u';
crosscheck backup;
delete nopromtp obsolete;
backup database;
backup archivelog all delete input;
release channel ch1;
release channel ch2;
release channel ch3;
}

Create shell script to trigger backup

We need to create a shell script file that will call the above db_full_backup.rman file and triggers the database backup in the background

cd /u02/rman/scripts

vi rman_backup.sh

#!/bin/bash
. /home/oracle/.bash_profile
export DATE=$(date +%m%d%y_%H%M%S)
export ORACLE_HOME=/u02/app/oracle/product/11.2.0/dbhome_1
export ORACLE_SID=proddb
$ORACLE_HOME/bin/rman target / catalog rman_rc/[email protected] cmdfile=/u02/rman/scripts/db_full_backup.rman log=/u02/rman/logs/${DATE}_proddb_BACKUP.log

Give execute permissions on the shell script

chmod 775 /u02/rman/scripts/rman_backup.sh

Schedule backup under crontab

Now you can go ahead and schedule the backup under the crontab. For example, we are scheduling backup to trigger at 10 am and 4 pm everyday

crontab -e
00 10,16 * * * /u02/rman/scripts/rman_backup.sh

Crontab tool

Here is a crontab handy tool that I use to acurately define when crontab will execute next.

Was this article helpful?

Related Articles

Comments

  1. Good job on this article! I really like how you presented your facts and how you made it interesting and easy to understand. Thank you.

  2. I simply must tell you that you have written an excellent and unique article that I really enjoyed reading. I’m fascinated by how well you laid out your material and presented your views. Thank you.

  3. I am often to blogging and i also truly appreciate your site content. The content has really peaks my interest. I am about to bookmark your blog and maintain checking for new details.

  4. Your article has proven useful to me. It’s very informative and you are obviously very knowledgeable in this area. You have opened my eyes to varying views on this topic with interesting and solid content.

  5. its very helpfull to me thanks for sharing scripts with us.

Leave a Comment