• Arun Kumar

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/rman_rc@rcat 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.

Recent Posts

See All

MySQL Installation on Linux

This article demonstrates MySQL installation on Oracle Enterprise Linux 6.5 version. Installation of MySQL Make sure you are able to connect internet via virtual machine. Try to ping google.com and pr

Add ISO image storage repository on XenServer

If you have used VMware ESXI, its very easy to upload ISO files to the data store and create VMs. With XenServer, you must create your own ISO repository to upload ISO files. Create ISO directory Acce

Perform Manual Switchover on Physical Standby

Connect to proddb database via client: Take a new putty session and connect to proddb database via client machine. Keep querying below sqlplus sys/sys@proddb as sysdba SQL> select name, open_mode, db

  • Facebook
  • Twitter
  • YouTube
  • Instagram

© 2020 by DBA Genesis

Feedback