Shell Script: RMAN_BACKUP.sh


#-----------------------------------------------------------------------------
# Script Name  : RMAN_BACKUP.sh
# Author       : Adithya
# Support      : adithya_dba@yahoo.com
# Languages    : Bash
# Version      : V7
# Description  : Oracle Database RMAN Online Backup, Backup Format will be <DATABASE_NAME_%U.BKP>
#
# Usage        : RMAN_BACKUP.sh -I <INSTANCE_NAME> -D <BACKUP_DIRECTORY> [-L <INCRIMENTAL_LEVEL>] [ -C <CLEAR_PREVIOUS_BACKUP>]
#
#                Where:
#                  -I : Instance Name should be followed.
#                  -D : Present RMAN Backup Directory. Backup will be taken in this Directory.
#   -L : IncrementalLevel of the Backup FULL: Full Backup, 0:Incremental Level 0, 1:Incremental Level 1.
#               FULL: Full Backup(Database Plus Archive Logs)."
# 0   : Incremental Level 0."
# 1   : Incremental Level 1."
# DB  : Database Backup (No Archive Logs)."
#   -C : Clears the Expired Backup from Catalog YES/NO/DY/DN (Default: YES)"
# YES : Clears the Expired Backup from Catalog."
# NO  : Will Not Clear the Expired Backup From Catalog."
# DY  : Delets the All Previous Backups and Clears the expired Backup from Catalog."
# DN  : Delets the All Previous Backups."
#               Note:::::: This Script Uses Target Database Control file as RMAN Catalog"
# RMAN_BACKUP.sh -I apvat1 -D /rmanbackup/RMAN_BACKUP -C DY > /rmanbackup/RMAN_BACKUP/LOGS/RMAN_VATMSTR_`date +"%a_%b_%d_%Y-%H_%M_%S"`.log &
# Revision History: At end of script.
#-----------------------------------------------------------------------------
# Default minimum PATH
PATH=/usr/bin:/bin
export PATH
if [ -r /var/opt/oracle/oratab ]            #Checking oratab file
then
ORATAB=/var/opt/oracle/oratab
elif [ -r /etc/oratab ]
then
ORATAB=/etc/oratab
else
echo "Oracle Not Installed or Not Configured, ORATAB file not found!"
exit 0
fi
#-----------------------------------------------------------------------------
# Function   : BkpCmdFull
# Description: Print usage syntax.
#-----------------------------------------------------------------------------
BkpCmdFull()
{
if [ -w "$BkpDir" ]
then
BF1=`echo "$BkpDir/BACKUP_L1/$Dn""_%U_%D.BKP" | sed -e 's/\/\//\//g'`
BF2=`echo "$BkpDir/BACKUP_L2/$Dn""_%U_%D.BKP" | sed -e 's/\/\//\//g'`
BF3=`echo "$BkpDir/BACKUP_L3/$Dn""_%U_%D.BKP" | sed -e 's/\/\//\//g'`
if [ ! -d "$BkpDir/BACKUP_L1" ]
then
mkdir -p "$BkpDir/BACKUP_L1"
fi
if [ ! -d "$BkpDir/BACKUP_L2" ]
then
mkdir -p "$BkpDir/BACKUP_L2"
fi
if [ ! -d "$BkpDir/BACKUP_L3" ]
then
mkdir -p "$BkpDir/BACKUP_L3"
fi
echo "run" >> Bkp_Script.cmd
echo "{" >> Bkp_Script.cmd
echo "sql 'alter system archive log current';" >> Bkp_Script.cmd
echo "CONFIGURE DEVICE TYPE DISK PARALLELISM 3;" >> Bkp_Script.cmd
echo "allocate channel c1 device type disk format '$BF1';" >> Bkp_Script.cmd
echo "allocate channel c2 device type disk format '$BF2';" >> Bkp_Script.cmd
echo "allocate channel c3 device type disk format '$BF3';" >> Bkp_Script.cmd
echo "BACKUP DATABASE filesperset 5 PLUS ARCHIVELOG;" >> Bkp_Script.cmd
echo "BACKUP CURRENT CONTROLFILE;" >> Bkp_Script.cmd
echo "release channel c1;" >> Bkp_Script.cmd
echo "release channel c2;" >> Bkp_Script.cmd
echo "release channel c3;" >> Bkp_Script.cmd
echo "}"  >> Bkp_Script.cmd
echo "" >> Bkp_Script.cmd
else
echo "*************************************************************************"
echo "Error:::Backup Directory : $BkpDir is Write Proected : Can Not Take RMAN Backup"
echo "*************************************************************************"
exit 0
fi
        return
} # End of BkpCmdFull
#-----------------------------------------------------------------------------

#-----------------------------------------------------------------------------
# Function   : BkpCmdDb
# Description: Print usage syntax.
#-----------------------------------------------------------------------------
BkpCmdDb()
{
if [ -w "$BkpDir" ]
then
BF1=`echo "$BkpDir/BACKUP_L1/$Dn""_%U_%D.BKP" | sed -e 's/\/\//\//g'`
BF2=`echo "$BkpDir/BACKUP_L2/$Dn""_%U_%D.BKP" | sed -e 's/\/\//\//g'`
BF3=`echo "$BkpDir/BACKUP_L3/$Dn""_%U_%D.BKP" | sed -e 's/\/\//\//g'`
if [ ! -d "$BkpDir/BACKUP_L1" ]
then
mkdir -p "$BkpDir/BACKUP_L1"
fi
if [ ! -d "$BkpDir/BACKUP_L2" ]
then
mkdir -p "$BkpDir/BACKUP_L2"
fi
if [ ! -d "$BkpDir/BACKUP_L3" ]
then
mkdir -p "$BkpDir/BACKUP_L3"
fi
echo "run" >> Bkp_Script.cmd
echo "{" >> Bkp_Script.cmd
echo "sql 'alter system archive log current';" >> Bkp_Script.cmd
echo "CONFIGURE DEVICE TYPE DISK PARALLELISM 3;" >> Bkp_Script.cmd
echo "allocate channel c1 device type disk format '$BF1';" >> Bkp_Script.cmd
echo "allocate channel c2 device type disk format '$BF2';" >> Bkp_Script.cmd
echo "allocate channel c3 device type disk format '$BF3';" >> Bkp_Script.cmd
echo "BACKUP DATABASE filesperset 5;" >> Bkp_Script.cmd
echo "BACKUP CURRENT CONTROLFILE;" >> Bkp_Script.cmd
echo "release channel c1;" >> Bkp_Script.cmd
echo "release channel c2;" >> Bkp_Script.cmd
echo "release channel c3;" >> Bkp_Script.cmd
echo "}"  >> Bkp_Script.cmd
echo "" >> Bkp_Script.cmd
else
echo "*************************************************************************"
echo "Error:::Backup Directory : $BkpDir is Write Proected : Can Not Take RMAN Backup"
echo "*************************************************************************"
exit 0
fi
        return
} # End of BkpCmdDb
#-----------------------------------------------------------------------------

#-----------------------------------------------------------------------------
# Function   : BkpCmdIncLZero
# Description: Print usage syntax.
#-----------------------------------------------------------------------------
BkpCmdIncLZero()
{
if [ -w "$BkpDir" ]
then
BF1=`echo "$BkpDir/BACKUP_L1/$Dn""_%U_%D.BKP" | sed -e 's/\/\//\//g'`
BF2=`echo "$BkpDir/BACKUP_L2/$Dn""_%U_%D.BKP" | sed -e 's/\/\//\//g'`
BF3=`echo "$BkpDir/BACKUP_L3/$Dn""_%U_%D.BKP" | sed -e 's/\/\//\//g'`
if [ ! -d "$BkpDir/BACKUP_L1" ]
then
mkdir -p "$BkpDir/BACKUP_L1"
fi
if [ ! -d "$BkpDir/BACKUP_L2" ]
then
mkdir -p "$BkpDir/BACKUP_L2"
fi
if [ ! -d "$BkpDir/BACKUP_L3" ]
then
mkdir -p "$BkpDir/BACKUP_L3"
fi
echo "run" >> Bkp_Script.cmd
echo "{" >> Bkp_Script.cmd
echo "sql 'alter system archive log current';" >> Bkp_Script.cmd
echo "CONFIGURE DEVICE TYPE DISK PARALLELISM 3;" >> Bkp_Script.cmd
echo "allocate channel c1 device type disk format '$BF1';" >> Bkp_Script.cmd
echo "allocate channel c2 device type disk format '$BF2';" >> Bkp_Script.cmd
echo "allocate channel c3 device type disk format '$BF3';" >> Bkp_Script.cmd
echo "BACKUP INCREMENTAL LEVEL 0 DATABASE filesperset 5 PLUS ARCHIVELOG;" >> Bkp_Script.cmd
echo "BACKUP CURRENT CONTROLFILE;" >> Bkp_Script.cmd
echo "release channel c1;" >> Bkp_Script.cmd
echo "release channel c2;" >> Bkp_Script.cmd
echo "release channel c3;" >> Bkp_Script.cmd
echo "}"  >> Bkp_Script.cmd
echo "" >> Bkp_Script.cmd
else
echo "*************************************************************************"
echo "Error:::Backup Directory : $BkpDir is Write Proected : Can Not Take RMAN Backup"
echo "*************************************************************************"
exit 0
fi
        return
} # End of BkpCmdIncLZero
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Function   : BkpCmdIncLOne
# Description: Print usage syntax.
#-----------------------------------------------------------------------------
BkpCmdIncLOne()
{
if [ -w "$BkpDir" ]
then
BF1=`echo "$BkpDir/BACKUP_L1/$Dn""_%U_%D.BKP" | sed -e 's/\/\//\//g'`
BF2=`echo "$BkpDir/BACKUP_L2/$Dn""_%U_%D.BKP" | sed -e 's/\/\//\//g'`
BF3=`echo "$BkpDir/BACKUP_L3/$Dn""_%U_%D.BKP" | sed -e 's/\/\//\//g'`
if [ ! -d "$BkpDir/BACKUP_L1" ]
then
mkdir -p "$BkpDir/BACKUP_L1"
fi
if [ ! -d "$BkpDir/BACKUP_L2" ]
then
mkdir -p "$BkpDir/BACKUP_L2"
fi
if [ ! -d "$BkpDir/BACKUP_L3" ]
then
mkdir -p "$BkpDir/BACKUP_L3"
fi
echo "run" >> Bkp_Script.cmd
echo "{" >> Bkp_Script.cmd
echo "sql 'alter system archive log current';" >> Bkp_Script.cmd
echo "CONFIGURE DEVICE TYPE DISK PARALLELISM 3;" >> Bkp_Script.cmd
echo "allocate channel c1 device type disk format '$BF1';" >> Bkp_Script.cmd
echo "allocate channel c2 device type disk format '$BF2';" >> Bkp_Script.cmd
echo "allocate channel c3 device type disk format '$BF3';" >> Bkp_Script.cmd
echo "BACKUP INCREMENTAL LEVEL 1 CUMULATIVE DATABASE filesperset 5 PLUS ARCHIVELOG;" >> Bkp_Script.cmd
echo "BACKUP CURRENT CONTROLFILE;" >> Bkp_Script.cmd
echo "release channel c1;" >> Bkp_Script.cmd
echo "release channel c2;" >> Bkp_Script.cmd
echo "release channel c3;" >> Bkp_Script.cmd
echo "}"  >> Bkp_Script.cmd
echo "" >> Bkp_Script.cmd
else
echo "*************************************************************************"
echo "Error:::Backup Directory : $BkpDir is Write Proected : Can Not Take RMAN Backup"
echo "*************************************************************************"
exit 0
fi
        return
} # End of BkpCmdIncLOne
#-----------------------------------------------------------------------------

#-----------------------------------------------------------------------------
# Function   : DelExpCmd
# Description: Print usage syntax.
#-----------------------------------------------------------------------------
DelExpCmd()
{
echo "run" > Bkp_Script.cmd
echo "{"  >> Bkp_Script.cmd
echo "crosscheck backup;" >> Bkp_Script.cmd
echo "delete noprompt expired backup;"  >> Bkp_Script.cmd
echo "}"  >> Bkp_Script.cmd
echo ""  >> Bkp_Script.cmd
        return
} # End of DelExpCmd
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Function   : DelPrBkp
# Description: Print usage syntax.
#-----------------------------------------------------------------------------
DelPrBkp()
{
echo "list backup;" >> Del_Bkp_Script.cmd
PrBkpList=`rman target / @Del_Bkp_Script.cmd |grep Piece | sed -e 's/ //g' |  sed -e 's/PieceName//g' | sed -e 's/://g'`
for Val in ${PrBkpList}
do
if [ -w $Val ]
then
echo "Deleting Backup Piece::: $Val"                                          #Changed to inside if condition in Version2
echo "Deleting Previous Backup Piece::: $Val">&2      #Added in Version5
rm "$Val"
else                                                                                  #Added in Version2
echo "Backup Piece is write Protected, Unable Delete Backup Piece::: $Val"    #Added in Version2
fi
done
rm Del_Bkp_Script.cmd
sleep 60
        return
} # End of DelPrBkp
#-----------------------------------------------------------------------------


#-----------------------------------------------------------------------------
# Function   : ShowUsage
# Description: Print usage syntax.
#-----------------------------------------------------------------------------
ShowUsage()
{
echo "USAGE: RMAN_BACKUP.sh -I <INSTANCE_NAME> -D <BACKUP_DIRECTORY> [-L <INCRIMENTAL_LEVEL>] [-C <CLEAR_PREVIOUS_BACKUP>]"
        echo "Where:"
        echo "   -I : Instance Name should be followed"
        echo "   -D : Present RMAN Backup Directory. Backup will be taken in this Directory."
        echo "   -L : IncrementalLevel of the Backup  (Default: FULL)"
echo " FULL: Full Backup(Database Plus Archive Logs)."
echo " 0   : Incremental Level 0."
echo " 1   : Incremental Level 1."
echo " DB  : Database Backup (No Archive Logs)."
        echo "   -C : Clears the Expired Backup from Catalog YES/NO/DY/DN (Default: YES)"
echo " YES : Clears the Expired Backup from Catalog."
echo " NO  : Will Not Clear the Expired Backup From Catalog."
echo " DY  : Delets the All Previous Backups and Clears the expired Backup from Catalog."
echo " DN  : Delets the All Previous Backups."
echo "Note:::::: This Script Uses Target Database Control file as RMAN Catalog"
echo "************************************************************************"
        return


} # End of ShowUsage
#-----------------------------------------------------------------------------

#-----------------------------------------------------------------------------
# Function   : GenScriptFile
# Description: Creates the Backup Command
#-----------------------------------------------------------------------------
GenScriptFile()
{
if [ $BkpClr = "YES" ]
then
DelExpCmd
elif [ $BkpClr = "NO" ]
then
echo "---"
elif [ $BkpClr = "DY" ]
then
if [ $BkpLevel = "0" -o  $BkpLevel = "1" ]
then
echo "*************************************************************************"
echo "Error:::Backup Deletion is not Possible with Incremental Backups Can Not Take RMAN Backup"
echo "*************************************************************************"
ShowUsage
exit 0
elif [ $BkpLevel = "FULL" -o  $BkpLevel = "DB" ]
then
DelPrBkp
DelExpCmd
fi
elif [ $BkpClr = "DN" ]
then
if [ $BkpLevel = "0" -o  $BkpLevel = "1" ]
then
echo "*************************************************************************"
echo "Error:::Backup Deletion is not Possible with Incremental Backups Can Not Take RMAN Backup"
echo "*************************************************************************"
ShowUsage
exit 0
elif [ $BkpLevel = "FULL" -o  $BkpLevel = "DB" ]
then
DelPrBkp
DelExpCmd
fi
else
echo "*************************************************************************"
echo "Error:::Invalid Backup Level Argument: -C $BkpClr in the Command Line: Can Not Take RMAN Backup"
echo "*************************************************************************"
ShowUsage
exit 0
fi

if [ $BkpLevel = "FULL" ]
then
BkpCmdFull
elif [ $BkpLevel = "0" ]
then
BkpCmdIncLZero
elif [ $BkpLevel = "1" ]
then
BkpCmdIncLOne
elif [ $BkpLevel = "DB" ]
then
BkpCmdDb
else
echo "*************************************************************************"
echo "Error:::Invalid Backup Level Argument: -L $BkpLevel in the Command Line: Can Not Take RMAN Backup"
echo "*************************************************************************"
ShowUsage
exit 0
fi

        return

} # End of GenScriptFile
#-----------------------------------------------------------------------------

CountI=0
CountD=0
CountL=0
CountC=0
if [ ${#} -eq 8 ]
then
case $1 in
'-I' )
OptionI=$1
CountI=`expr ${CountI} + 1`
InstanceName=$2
;;
'-D' )
OptionD=$1
CountD=`expr ${CountD} + 1`
BkpDir=$2
;;
'-L' )  
OptionL=$1
CountL=`expr ${CountL} + 1`
BkpLevel=$2
;;
'-C' )
OptionC=$1
CountC=`expr ${CountIC} + 1`
BkpClr=$2
;;
* )
echo "*************************************************************************"
echo "Error:::Invalid Options $1 in the Command Line: Can Not Take RMAN Backup"
echo "*************************************************************************"
ShowUsage
exit 0
;;
esac
case $3 in
'-I' )
OptionI=$3
CountI=`expr ${CountI} + 1`
InstanceName=$4
;;
'-D' )
OptionD=$3
CountD=`expr ${CountD} + 1`
BkpDir=$4
;;
'-L' )
OptionL=$3
CountL=`expr ${CountL} + 1`
BkpLevel=$4
;;
'-C' )
OptionC=$3
CountC=`expr ${CountC} + 1`
BkpClr=$4
;;
* )
echo "*************************************************************************"
echo "Error:::Invalid Options $3 in the Command Line: Can Not Take RMAN Backup"
echo "*************************************************************************"
ShowUsage
exit 0
;;
esac
case $5 in
'-I' )
OptionI=$5
CountI=`expr ${CountI} + 1`
InstanceName=$6
;;
'-D' )
OptionD=$5
CountD=`expr ${CountD} + 1`
BkpDir=$6
;;
'-L' )
OptionL=$5
CountL=`expr ${CountL} + 1`
BkpLevel=$6
;;
'-C' )
OptionC=$5
CountC=`expr ${CountC} + 1`
BkpClr=$6
;;
* )
echo "*************************************************************************"
echo "Error:::Invalid Options $5 in the Command Line: Can Not Take RMAN Backup"
echo "*************************************************************************"
ShowUsage
exit 0
;;
esac
case $7 in
'-I' )
OptionI=$7
CountI=`expr ${CountI} + 1`
InstanceName=$8
;;
'-D' )
OptionD=$7
CountD=`expr ${CountD} + 1`
BkpDir=$8
;;
'-L' )  
OptionL=$7
CountL=`expr ${CountL} + 1`
BkpLevel=$8
;;
'-C' )
OptionC=$7
CountC=`expr ${CountC} + 1`
BkpClr=$8
;;
* )
echo "*************************************************************************"
echo "Error:::Invalid Options $7 in the Command Line: Can Not Take RMAN Backup"
echo "*************************************************************************"
ShowUsage
exit 0
;;
esac
elif [ ${#} -eq 6 ]
then
case $1 in
'-I' )
OptionI=$1
CountI=`expr ${CountI} + 1`
InstanceName=$2
;;
'-D' )
OptionD=$1
CountD=`expr ${CountD} + 1`
BkpDir=$2
;;
'-L' )  
OptionL=$1
CountL=`expr ${CountL} + 1`
BkpLevel=$2
;;
'-C' )
OptionC=$1
CountC=`expr ${CountC} + 1`
BkpClr=$2
;;
* )
echo "*************************************************************************"
echo "Error:::Invalid Options $1 in the Command Line: Can Not Take RMAN Backup"
echo "*************************************************************************"
ShowUsage
exit 0
;;
esac
case $3 in
'-I' )
OptionI=$3
CountI=`expr ${CountI} + 1`
InstanceName=$4
;;
'-D' )
OptionD=$3
CountD=`expr ${CountD} + 1`
BkpDir=$4
;;
'-L' )
OptionL=$3
CountL=`expr ${CountL} + 1`
BkpLevel=$4
;;
'-C' )
OptionC=$3
CountC=`expr ${CountC} + 1`
BkpClr=$4
;;
* )
echo "*************************************************************************"
echo "Error:::Invalid Options $3 in the Command Line: Can Not Take RMAN Backup"
echo "*************************************************************************"
ShowUsage
exit 0
;;
esac
case $5 in
'-I' )
OptionI=$5
CountI=`expr ${CountI} + 1`
InstanceName=$6
;;
'-D' )
OptionD=$5
CountD=`expr ${CountD} + 1`
BkpDir=$6
;;
'-L' )
OptionL=$5
CountL=`expr ${CountL} + 1`
BkpLevel=$6
;;
'-C' )
OptionC=$5
CountC=`expr ${CountC} + 1`
BkpClr=$6
;;
* ) echo "*************************************************************************"
echo "Error:::Invalid Options $5 in the Command Line: Can Not Take RMAN Backup"
echo "*************************************************************************"
ShowUsage
exit 0
;;
esac
elif [ ${#} -eq 4 ]
then
case $1 in
'-I' )
OptionI=$1
CountI=`expr ${CountI} + 1`
InstanceName=$2
;;
'-D' )
OptionD=$1
CountD=`expr ${CountD} + 1`
BkpDir=$2
;;
* )
echo "*************************************************************************"
echo "Error:::Mandatory Options -I or -D Not Found in the Command Line: Can Not Take RMAN Backup"
echo "*************************************************************************"
ShowUsage
exit 0
;;
esac
case $3 in
'-I' )
OptionI=$3
CountI=`expr ${CountI} + 1`
InstanceName=$4
;;
'-D' )
OptionD=$3
CountD=`expr ${CountD} + 1`
BkpDir=$4
;;
* )
echo "*************************************************************************"
echo "Error:::Mandatory Options -I or -D Not Found in the Command Line: Can Not Take RMAN Backup"
echo "*************************************************************************"
ShowUsage
exit 0
;;
esac
else
echo "**************************************************************************"
echo ":::::::::::::::::::::::::::: H  E  L  P ::::::::::::::::::::::::::::::::::"
echo "**************************************************************************"
ShowUsage
exit 0
fi


if [ $CountI -eq 0 -o $CountD -eq 0 ]
then
echo "*************************************************************************"
echo "Error:::Mandatory Options -I or -D Not Found in the Command Line: Can Not Take RMAN Backup"
echo "*************************************************************************"
ShowUsage
exit 0
elif [ $CountI -gt 1 -o $CountD -gt 1 ]
then
echo "*************************************************************************"
echo "Error:::Duplicate Options -I or -D Found in the Command Line: Can Not Take RMAN Backup"
echo "*************************************************************************"
ShowUsage
exit 0

else
if [ $CountL -eq 0 ]
then
BkpLevel="FULL"
fi
if [ $CountC -eq 0 ]
then
BkpClr="YES"
fi
if [ $CountL -gt 1 ]
then
echo "*************************************************************************"
echo "Error:::Dupicate Options -L Found in the Command Line: Can Not Take RMAN Backup"
echo "*************************************************************************"
ShowUsage
exit 0
fi
if [ $CountC -gt 1 ]
then
echo "*************************************************************************"
echo "Error:::Dupicate Options -C Found in the Command Line: Can Not Take RMAN Backup"
echo "*************************************************************************"
ShowUsage
exit 0
fi
fi
ID="/usr/xpg4/bin/id -nu"
ValueList=`grep -i "^[a-z,0-9]" "$ORATAB" | sed -e 's/ //g'`               #Reading the ORATAB entries
InstanceCnt=0
RunFlg=0
for Value in ${ValueList}
do
InstanceCnt=`expr ${InstanceCnt} + 1`                              #Reading the ORATAB entries
        IName="`echo ${Value} | cut -d: -f1`"
        IHome="`echo ${Value} | cut -d: -f2`"
        IAuto="`echo ${Value} | cut -d: -f3 | tr '[:lower:]' '[:upper:]'`"
        IOwner=`ls -lLd ${IHome}/bin 2>/dev/null | awk '{print $3}'`
ROwner=`${ID}`
if [ $RunFlg -eq 1  ]
then
exit 0
elif [ $RunFlg -eq 0  ]                                            #Checking the Run Flag
then
if [ "$IName" = "$InstanceName" ]
        then
                if [ $ROwner = $IOwner ]
                then
                        ORACLE_SID="$InstanceName"
                      export ORACLE_SID
OraSid="${IName}"
                       ORACLE_HOME="$IHome"
                       export ORACLE_HOME
                       PATH="$IHome"/bin:$PATH
                        export PATH
ProcCount=0
               Procs=`ps -fe 2>/dev/null | cut -c1-132 | sed -e 's/ *$//' | grep -v grep | \
               egrep "ora_pmo._${OraSid}\$|ora_dbw._${OraSid}\$|ora_lgw._${OraSid}\$|ora_smo._${OraSid}"'$'`
for Proc in pmo dbw lgw smo
              do
                        Result=`echo ${Procs} | grep "ora_${Proc}._${OraSid}" 2>&1`
                       if [ -n "${Result}" ]
                      then
                        ProcCount=`expr ${ProcCount} + 1`
                        fi
               done
if [ ${ProcCount} -ge 4 ]
               then
Status=`echo 'set heading off
set timing off
                        set time off
                        select status from v$instance;
                        exit' | sqlplus -s / as sysdba`
               DbType=`echo 'set heading off
set timing off
                      set time off
                        select database_role from v$database;
                      exit' | sqlplus -s / as sysdba`
LogMode=`echo 'set heading off
set timing off
                       set time off
                        select log_mode from v$database;
       exit' | sqlplus -s / as sysdba`
DbName=`echo 'set heading off
set timing off
                       set time off
                        select name from v$database;
       exit' | sqlplus -s / as sysdba`
Dt="`echo ${DbType} | cut -d: -f1`"
St="`echo ${Status} | cut -d: -f1`"
lm="`echo ${LogMode} | cut -d: -f1`"
Dn="`echo ${DbName} | cut -d: -f1`"
               else
              DbType="Unknown"
                               Status="Down"
LogMode="Unknown"
              Dt="Unknown"
                               St="Down"
lm="Unknown"
                fi
if [ $St = "OPEN" ]
then
if [ "$Dt" = "PRIMARY" ]
then
if [ $lm = "ARCHIVELOG" ]
then
if [ -w `pwd` ]
then
echo "*************************************************************************">&2    #Added in Version5
echo ":::::::::::::::::::::::::::RMAN Backup Started:::::::::::::::::::::::::::">&2    #Added in Version5
echo "*************************************************************************">&2    #Added in Version5
GenScriptFile
rman target / @Bkp_Script.cmd
Resl=$?
if [ $Resl -eq 0 ]
then
echo "*************************************************************************"
echo ":::::::::::::::::::::::RMAN Backup Successfull:::::::::::::::::::::::::::"
echo "*************************************************************************"
echo "*************************************************************************">&2
echo ":::::::::::::::::::::::RMAN Backup Successfull:::::::::::::::::::::::::::">&2
echo "*************************************************************************">&2
else
echo "*************************************************************************"
echo "::::::::::::::::::::::::::RMAN Backup Failed:::::::::::::::::::::::::::::"
echo "*************************************************************************"
echo "*************************************************************************">&2
echo "::::::::::::::::::::::::::RMAN Backup Failed:::::::::::::::::::::::::::::">&2
echo "*************************************************************************">&2
rm Bkp_Script.cmd                                             #Added in Version2, After Faild backup Script file not deleting
exit 0
fi
                        RunFlg=`expr ${RunFlg} + 1`
rm Bkp_Script.cmd
else
echo "*************************************************************************"
echo "Error::::Can not Create File Bkp_Script.cmd in `pwd`, Access Dedained, Change the Present Working Directory"
echo "*************************************************************************"
exit 0
fi
else
echo "*************************************************************************"
echo "Error:::::::::::Database $InstanceName not in ArchiveLog Mode::::::::::::"
echo "*************************************************************************"
exit 0
fi
else
echo "*************************************************************************"
echo "Error::::::::::::$InstanceName Not a Primary Database::::::::::::::::::::"
echo "*************************************************************************"
exit 0
fi
else
echo "*************************************************************************"
echo "Error::::::::::::::::Database $InstanceName is $St State:::::::::::::::::"
echo "*************************************************************************"
exit 0
fi

               else
echo "*************************************************************************"
echo "Error:::Not Othorized to execute as $ROwner. Please Log on to $IOwner::::"
echo "*************************************************************************"
exit 0
fi              #End Of If Condition user logged in Database owner or not
        fi                      #End Of If Condition $InstanceName Matching wiht ORATAB Entries
fi                              #End Of If Condition $RunFlg checking 0 or 1
done
if [ "$InstanceCnt" -gt 0 -a "$RunFlg" -eq 0 ]
then
echo "*************************************************************************"
echo "Error::::No Instance Configured with $InstanceName,Invalid Instance Name at Command Line"
echo "*************************************************************************"
exit 0
fi



#-----------------------------------------------------------------------------
# Revision History
#-----------------------------------------------------------------------------
# Revision History 1:
# Author       : Adithya Sirimalla
# Version 1    : 5th October 2010
# Support      : adithya_dba@yahoo.com
# Testing      : On Solaris 9,10
# Script Status: Initial Script (Version 1)
# Changes      : No Changes
#----------------------------------------------------------------------------
# Revision History 2:
# Author       : Adithya Sirimalla
# Version 2    : 20th October 2010
# Support      : adithya_dba@yahoo.com
# Testing      : On Solaris 9,10
# Script Status: Version 2 : Bugs related to DelPrBkp,  After Faild backup Script file not deleting are fixed
# Changes      : Change in Function : DelPrBkp
#----------------------------------------------------------------------------
# Revision History 3:
# Author       : Adithya Sirimalla
# Version 2    : 13th May 2011
# Support      : adithya_dba@yahoo.com
# Testing      : On Solaris 9,10
# Script Status: Version 3 :
# Changes      : Changes in Backup Level added new Level DB
#----------------------------------------------------------------------------
# Revision History 4:
# Author       : Adithya Sirimalla
# Version 2    : 11th July 2011
# Support      : adithya_dba@yahoo.com
# Testing      : On Solaris 9,10
# Script Status: Version 4 : Wrong File Name HELP Dispaly  Bug is Fixed
# Changes      : ShowUsage Functaion
#----------------------------------------------------------------------------
# Revision History 5:
# Author       : Adithya Sirimalla
# Version 2    : 20th July 2011
# Support      : adithya_dba@yahoo.com
# Testing      : On Solaris 9,10
# Script Status: Version 5 :
# Changes      : Added Verbose output for some of the messages
#----------------------------------------------------------------------------
# Revision History 6:
# Author       : Adithya Sirimalla
# Version 2    : 12th October 2011
# Support      : adithya_dba@yahoo.com
# Testing      : On Solaris 9,10
# Script Status: Version 6 : Included PARALLELISM in rman commands
# Changes      : Changes in BkpCmdFull,BkpCmdDb
#----------------------------------------------------------------------------
# Revision History 7:
# Author       : Adithya Sirimalla
# Version 2    : 13th October 2011
# Support      : adithya_dba@yahoo.com
# Testing      : On Solaris 9,10
# Script Status: Version 7 : Fixed Directory Creation Bugs realted to PARALLELISM in rman commands
# Changes      : changes in functions BkpCmdFull,BkpCmdDb,BkpCmdIncLZeor,BkpCmdIncLOne
#----------------------------------------------------------------------------

No comments:

Post a Comment