Oracle RMAN Database Incremental Backup Script

This is the third post/script in this series, the first script was Oracle RMAN Database Full Hot Backup Script

The second script was Oracle RMAN Database Full Cold Backup Script

The following script will incrementally backup the database while it is open (although it may be used while the database is in the mount mode also).


#*****************************************************************************
# $Header: abc_rman_incr_hot_bkp.sh *
# **************************************************************************************
# * Author: Ahmed Abdel Fattah *
# **************************************************************************************
# * DESCRIPTION: Take rman incremental hot backup(incremental level 1 ) *
# * PLATFORM: Linux/Solaris/HP-UX/AIX *
# **************************************************************************************

#!/bin/bash

# Check the login user to be “oracle”
# ————————————
usr=`id |cut -d”(” -f2 | cut -d “)” -f1`

if [ $usr != “oracle” ]
then
echo “You should login as oracle user”
exit 1
fi

# Check that ORACLE_HOME was set
# ——————————
# oh=$ORACLE_HOME
# if [ -z $oh ]
# then
# echo “You should set the oracle environment”
# exit 1
# fi

if [ $# -lt 1 ] ; then #not given enough parameters to script
cat <<USAGEINFO

******************************************************************
** USAGE: abc_rman_incr_hot_bkp.sh **
** where Is the SID of Database to be backed up. **
** **
** Prerequisits: **
** – Login as oracle user **
** – Ensure that the DB is open **
** – Ensure that the DB is in the archivelog mode **
** – Configure FRA , if not already configured **
******************************************************************

USAGEINFO
exit 1
fi

# Set the Oracle Environment
# —————————
export ORACLE_HOME=/u01/app/oracle/product/12.2.0.1/dbhome_1
export ORACLE_SID=$1
export PATH=$ORACLE_HOME/bin:$PATH:.
oh=$ORACLE_HOME

dt=”_`date ‘+%Y%m%d’`”
sid=$1
lg=”/backup/$sid/log/rman_incr_hot$dt.log”
#lg=”/home/oracle/$sid/log/rman_incr_hot$dt.log”

echo Script $0 >> $lg
echo >> $lg
echo ========== started on `date` ========== >> $lg
echo “ORACLE_SID: $sid” >> $lg
echo “ORACLE_USER: $usr” >> $lg
echo “ORACLE_HOME: $oh” >> $lg
echo “RMAN Log File: $lg” >> $lg
echo ============================================================ >> $lg

rman msglog $lg append << EOF

connect target /

set echo on;

configure controlfile autobackup on;

run { sql “alter session set nls_date_format=”dd-mm-yyyy hh24:mi:ss””;

allocate channel c1 device type disk ;

allocate channel c2 device type disk ;

allocate channel c3 device type disk ;

allocate channel c4 device type disk ;

backup as compressed backupset incremental level 1 database tag ‘daily_db_incr_hot_backup’ plus archivelog tag ‘daily_archive_hot_backup’;

release channel c1 ;

release channel c2 ;

release channel c3 ;

release channel c4 ; }

exit

EOF

echo ========== Completed at `date` ========== >> $lg

Donate to support our blogging work

$1.00

Thanks
Ahmed

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s