• Arun Kumar

Automate RMAN Backup using Shell Script

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 directory. If you want to have a different directory structure, its complete up to your environment requirements

mkdir -p /u01/rman

Create RMAN backup script file

Let us create the RMAN backup script file to trigger DB FULL backup

vi /u01/rman/full_backup.sh

. /home/oracle/.bash_profile

export ORACLE_SID=proddb
export ORACLE_HOME=/u01/app/oracle/product/

export DATE=$(date +%y-%m-%d_%H%M%S)

rman target / log=/u01/rman/proddb_${DATE}.log << EOF
allocate channel ch1 device type disk format '/u01/rman/proddb_full_bkp_%u';
allocate channel ch2 device type disk format '/u01/rman/proddb_full_bkp_%u';
allocate channel ch3 device type disk format '/u01/rman/proddb_full_bkp_%u';
crosscheck backup;
delete noprompt obsolete;
backup database;
backup archivelog all delete input;
release channel ch1;
release channel ch2;
release channel ch3;

Schedule Backup Under Crontab

Give execute permissions on the shell script

chmod 775 /u01/rman/full_backup.sh

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 * * * /u01/rman/full_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

Oracle RMAN Cold Backup

It’s easy to fire RMAN backups when database is running in archive log mode. RMAN will take your database backup along with archive logs. You can even use RMAN to take backup of a database running in