Saturday, March 15, 2008

Script to Archive Automation

#!/usr/bin/ksh
# Functions
#A function to format the date

function formatDate {
date +%Y%m%d"."%H%M%S
}

#A function to generate a time stamp
function getTimestamp {
echo `formatDate` -- "${*}"
}

#A function to exit after an error condition
function exitError {
getTimestamp ${exitCodeArr[${1}]}

exit ${1}
}

#Function to set the environmental varriable from oratab.

function ToSetEnvVariables ()
{
if [ -f /etc/oratab ]; then
OraTab=/etc/oratab
elif [ -f /var/opt/oracle/oratab ]; then
OraTab=/var/opt/oracle/oratab
fi
unset ORACLE_HOME
OH=`cat /etc/oratab |grep -v "#"|grep -v "*."|grep "$1"|cut -d ":" -f2`
ORACLE_SID=$1;export ORACLE_SID
ORACLE_HOME=$OH;export ORACLE_HOME
PATH=$ORACLE_HOME/bin:$PATH:.;export PATH
}
#Function to backup the archive log file aftre reaching to threshold of archive log file system

function cleararchivelog ()
{
ToSetEnvVariables $1
$ORACLE_HOME/bin/rman target / cmdfile /u01/Scripts/backup_arch_rman.cmd msglog /u01/Scripts/backup_arch_rman.log
}
sqlplus -s "/as sysdba" < /dev/null
set feed off echo off head off trimspool on timing off set pagesize 1000 verify off
spool CheckarchDest.lst
select round(PERCENT_SPACE_USED) from v\$FLASH_RECOVERY_AREA_USAGE where FILE_TYPE='ARCHIVED LOG';
spool off
set feed on
eof
cat CheckarchDest.lst|grep -v "rows selected"|grep -v "SQL" |grep -v ^$ > check_percent_arch_full
while read line
do
Percent=`echo $line |awk '{print $1}'`
if [ ${Percent} -gt $2 ]; then
cleararchivelog $1
else
echo "Looks Okay"
fi
done < check_percent_arch_full

No comments: