Linux Shell Script for RMAN Archivelog Backup

If you want to perform hot backup then your database must be in archivelog mode. Using below shell script you can automate archivelog backup into the Linux crontab. 

Archivelog Backup Script

Before performing the hot archivelog backup please put the database into archivelog mode.

Shell Script to Backup Archivelog on Disk

[oracle@orahow Scripts]$ more archive_backup.sh
#!/bin/bash
export ORACLE_BASE=/ora/app/oracle
export ORACLE_HOME=/ora/app/oracle/product/11.2.0.4/dbhome_1
export ORACLE_SID=orahowdb
export PATH=$ORACLE_HOME/bin:$PATH
export LOG_DIR=/orabackup/Backup/orahowdb/Physical/Hot/Backupfiles/arch/
export DATE=`date +%Y%m%d_%H%M`
export LOG_FILE=$LOG_DIR/${DATE}_${ORACLE_SID}.log
echo "Begin backup"
rman cmdfile=/orabackup/Backup/orahowdb/Physical/Hot/Scripts/archivelog_backup.rcv log=$LOG_FILE
date
echo "End backup"
[oracle@orahow Scripts]$
[oracle@orahow Scripts]$ more archivelog_backup.rcv
connect target /

CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/u01/SAN_Backups/PROD/Backups/Physical/Hot/Backupfiles/arch/%F';

run {
ALLOCATE CHANNEL disk1 DEVICE TYPE DISK FORMAT  '/orabackup/Backup/orahowdb/Physical/Hot/Backupfiles/arch/%T_@_%s_%p_%t';
ALLOCATE CHANNEL disk2 DEVICE TYPE DISK FORMAT  '/orabackup/Backup/orahowdb/Physical/Hot/Backupfiles/arch/%T_@_%s_%p_%t';
ALLOCATE CHANNEL disk3 DEVICE TYPE DISK FORMAT  '/orabackup/Backup/orahowdb/Physical/Hot/Backupfiles/arch/%T_@_%s_%p_%t';
ALLOCATE CHANNEL disk4 DEVICE TYPE DISK FORMAT  '/orabackup/Backup/orahowdb/Physical/Hot/Backupfiles/arch/%T_@_%s_%p_%t';
crosscheck archivelog all;
backup as compressed backupset archivelog all not backed up 1 times filesperset 10 format '/orabackup/Backup/orahowdb/Physical/Hot/Backupfiles/arch/%T_@_%s_%p_%t'delete
input;
release channel disk1 ;
release channel disk2 ;
release channel disk3 ;
release channel disk4 ;
}

run
{
        delete noprompt backup of archivelog all completed before 'sysdate-2';
}

exit;
[oracle@orahow Scripts]$

The above archivelo backup contains two scripts:

  •  archive_backup.sh -> Contains oracle database environmental variables and calling RMAN archivelog_backup.rcv cmdfile.
  • archivelog_backup.rcv -> Contains RMAN configurations and archivelog backup commands.

Please allocate channels and set the archivelog deletion policy based on your requirement.