top of page
DBAGenesis_png.png

How to Automate RMAN Backups

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 on Linux and Windows




Automate RMAN Backups on Linux


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

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

vi /u01/rman/full_backup.sh

#!/bin/bash

. /home/oracle/.bash_profile

export ORACLE_SID=proddb
export ORACLE_HOME=/u01/app/oracle/product/12.2.0.1
export DATE=$(date +%y-%m-%d_%H%M%S)

rman target / log=/u01/rman/${ORACLE_SID}_${DATE}.log << EOF
run
{
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';
crosscheck backup;
delete noprompt obsolete;
backup database;
backup archivelog all delete input;
release channel ch1;
release channel ch2;
}
EOF
You could edit above rman run block to create incremental backup scripts

Give execute permissions to the shell script

chmod 775 /u01/rman/full_backup.sh

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
Here is a crontab handy tool to accurately define the next run schedule


Automate RMAN Backups on Windows


Scheduling RMAN backups on a windows machine is little different than Linux machine. Windows uses bash shell and we will create a backup.cmd file with our RMAN run block for database backup

run{
	crosscheck backup;
	backup database plus archivelog;
};

Create a proddb_rman_backup.bat (.bat is a windows bash shell) file which will call above file

set oracle_sid=proddb
rman target sys@proddb rman_rc@rcat cmdfile='F:\backup.cmd' log='F:\rman_backup_full\backup.log'

Let's schedule the above proddb_rman_backup.bat script under windows scheduler. Launch the Task Scheduler from start menu and Create Task



Enjoy!


Become a top notch dba with DBA Genesis
Become a DBA with DBA Genesis.png
bottom of page