#!/bin/ksh
##########################################################################################
##########################################################################################
set -a

DB_NAME=$1
SITE=$2

###

# NB : Set to local values manually:

BACKUP_DAYS=4                     # Backupset Retention
ARCHLOG_DAYS=4                    # Archivelog retention
LOG=/u01/app/oracle/admin/${DB_NAME}${SITE}/backuplogs/${DB_NAME}_`date +%Y%m%d%H%M%S`.log

###

# Determine ORACLE_HOME and PATH:
#ORAENV_ASK=NO
#ORACLE_SID=$DB_NAME
#. oraenv
#unset ORAENV_ASK

# Determine ORACLE_SID from the instance that is running on this host:
ORACLE_SID=`ps -aef | grep ora_smon_ | grep $DB_NAME | awk -F”_” ‘{print $3}’|awk -F” ” ‘{print $1}’`

# Determine ORACLE_HOME and PATH
ORAENV_ASK=NO
. oraenv
unset ORAENV_ASK

echo “DB_NAME :         $DB_NAME” >> $LOG
echo “ORACLE_SID :              $ORACLE_SID” >> $LOG
echo “ORACLE_HOME :     $ORACLE_HOME” >> $LOG
echo “HOST :                    `hostname`” >> $LOG
echo “SITE :                    $SITE” >> $LOG
echo >> $LOG

NLS_DATE_FORMAT=”YYYY-MON-DD HH24:MI:SS”

$ORACLE_HOME/bin/rman target / <> $LOG 2>&1

 set echo on;

 configure controlfile autobackup on;

 show all;

 recover device type disk copy of database with tag ‘Image_Copy’;

 backup as compressed backupset device type disk incremental level 1 for recover of copy with tag ‘Image_Copy’ tag ‘incr_update’ database;

 backup as compressed backupset device type disk archivelog until time ‘sysdate – ${ARCHLOG_DAYS}’ tag ‘incr_update’ delete all input;

 delete noprompt backup completed before ‘sysdate – ${BACKUP_DAYS}’ tag ‘incr_update’ device type disk;