RMAN BACKUP SCRIPT

How to automate Oracle RMAN Backup with shell script

In a real environment, you obviously won’t manually trigger all of the Oracle database backups. An automated mechanism is required to enable RMAN backups. In this article, we’ll look at automating RMAN backup using a shell script.

Create Backup Location

On your database server, create a listing structure to maintain RMAN backups and all associated files. All the RMAN backup logs and backup scripts are saved in a single directory. If you need to have a specific directory structure, it’s completely up to your surrounding’s requirements.

$mkdir -p /u01/rman_backup

Create Backup Script

Create a rman full backup shell script using the below code with the help of vi editor. “My shell script name is rman_full_backup.sh

$vi /u01/rman_backup/rman_full_backup.sh

Backup Script:

export Backup_Location=/u01/rman_backup/`date +%d-%m-%y`
export ORACLE_SID=digital
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/12.2.0/dbhome_1/
export PATH=/usr/sbin:$PATH
export PATH=$ORACLE_HOME/bin:$PATH

date
mkdir -p /u01/rman_backup/`date +%d-%m-%y`
rman target / nocatalog log=$Backup_Location/LogRMAN.log << EOF
run {
allocate channel cha1 type disk;
crosscheck backup;
crosscheck archivelog all;
DELETE NOPROMPT EXPIRED ARCHIVELOG ALL;
delete noprompt expired backup;
delete noprompt obsolete;
backup database format '$Backup_Location/digital_`date +%F`_%U_DB.bkp';
sql 'alter system archive log current';
backup archivelog all format '$Backup_Location/digital_`date +%F`_%U_ArchiveLog.bkp';
backup current controlfile format '$Backup_Location/digital_`date +%F`_ControlFile.bkp';
release channel cha1;
}
EOF

Change Backup Script Permissions

We need to change script permissions, It must be 775.

chmod 775 /u01/rman_backup/rman_full_backup.sh

Schedule Database Backup in Crontab

This is the final step for RMAN Backup to be scheduled in the corn job. In my case, I’m going to schedule backup will run at 08:20 PM every day. Just add the below entry in crontab.

$crontab -e 20 18 * * * /u01/rman_backup/rman_full_backup.sh

Related posts

Recover a Table from Drop/Truncate/Delete done on Primary using Flashback on a Standby

Steps to Clone Oracle Database from Windows to Oracle Linux

Restoring an Oracle Database on a New Server