############################################################################################
#!/bin/ksh
# Author : Rodrigo Mufalani – rodrigo@mufalani.com.br
# Date : July 11th, 2009
# From :
# To :
# Purpose : Backup of production database with Recovery Manager to store on /some/hotbackup
############################################################################################
# Obs.: This script was build on 9i R2 database but still can be use on new releases
############################################################################################set -a
DBA=”suporte@mufalani.com.br”
SCR=`basename $0 | awk -F”.” ‘{print $1}’`
ORACLE_SID=`echo ${SCR} | awk -F”_” ‘{ print $2 }’`
ORACLE_USER=oracle
ORACLE_BASE=/u01/app/oracle
ORACLE_HOME=${ORACLE_BASE}/product/9.2.0
NLS_LANG=AMERICAN_AMERICA.WE8ISO8859P1
DUMPDIR=/some/path
DATA=`date “+%d_%m”`
OUTF=${DUMPDIR}/rman_${ORACLE_SID}_${DATA}.out
ERRF=${DUMPDIR}/rman_${ORACLE_SID}_${DATA}.err
LOGFILE=${DUMPDIR}/rman_${ORACLE_SID}_${DATA}.log
PATH=$ORACLE_HOME/bin:$PATH:.
HOST=`uname -n`
set +a
exec 9>&2
exec 2>>$ERRF
{ # output block
#set +x
echo “$DATE”
DATE=`date “+%d/%m/%Y %H:%M”`
echo “”
echo “==================================================================================== ”
echo “—————- Beginning RMAN Full of ${ORACLE_SID} —————– $DATE”
echo “==================================================================================== ”
echo “Script name: $0”
echo
echo “ORACLE_SID: $ORACLE_SID”
echo “ORACLE_USER: $ORACLE_USER”
echo “ORACLE_HOME: $ORACLE_HOME”
echo “LOGFILE: ${OUTF}”
echo “DESC: Cold backup of production database (RMAN)”
$ORACLE_HOME/bin/rman target / log=${LOGFILE} <<EOF
run
{
shutdown immediate;
startup mount;
backup database format ‘${DUMPDIR}/bkp_full_%d_%T_%U.bkp’ TAG=FULL_SEMANAL;
backup current controlfile format ‘${DUMPDIR}/bkp_ctfile_%d_%T_%U.bkp’ TAG=CTFILE_SEMANAL;
backup spfile format ‘${DUMPDIR}/bkp_spfile_%d_%T_%U.bkp’ TAG=SPFILE_SEMANAL;
crosscheck backup;
delete noprompt expired backup;
delete noprompt obsolete;
alter database open;
}
exit;
EOF
RETURN_STATUS=$?
echo
DATE=`date “+%d/%m/%Y %H:%M”`
echo “==================================================================================== ”
echo “—————— RMAN Full of ${ORACLE_SID} finished ————— $DATE”
echo “==================================================================================== ”
echo
echo “exit $RETURN_STATUS”
} >> $OUTF
exec 2>&9
if [ $RETURN_STATUS -eq 0 ]; then
echo “0” > /tmp/.export_${ORACLE_SID}_${DATA}
mailx -s “Cold Backup of $ORACLE_SID with success …” $DBA <${OUTF}
else
echo “1” > /tmp/.export_${ORACLE_SID}_${DATA}
mailx -s “Cold Backup of $ORACLE_SID failed …” $DBA <${ERRF}
fi
exit $RETURN_STATUS