housekeep arch logs (tested on AIX)

oo0yuki0oo發表於2012-05-13

#!/usr/bin/ksh
#----------------------------------------------------------------#
# File Name : housekeeparch.ksh #
# Description : This Program will take a snaphot of #
# Archive Log files and remove only those #
# once the backup is completed #
# Version : 1.0 #
# Usage : housekeeparch.ksh #
# sid - ORACLE_SID #
# Type - PRE or POST #
# PRE - take snapshot of archive log #
# files #
# POST - Remove the files from the #
# snapshot take in PRE #
# History #
# ======= #
# 17/01/2010 Ramesh Initial Version #
#----------------------------------------------------------------#

ORACLE_BASE=/optware/oracle
MON=`date '+%m%Y'`
Conf=$ORACLE_BASE/dbaconf
OsName=`uname`
case $OsName in
HP-UX) BDF="bdf";;
SunOS) BDF="df -k";;
OSF1) BDF="df -k";;
AIX) BDF="df -k";;
esac
aclfile=$ORACLE_BASE/tmp/housekeeparch.acl

ErrDisp ()
{
echo
echo `date "+%Y-%m-%d %H:%M:%S"` : "${ErrMsg}"
echo `date "+%Y-%m-%d %H:%M:%S"`" : ${Type} Job Terminated"
echo `date "+%Y-%m-%d %H:%M:%S"`" : Exit Status = -1"
echo "#------------------------------- New Adhoc Archive Backup Job End -------------------------------#"
if [ ${LogFile:-0} != 0 ]
then
echo >> ${LogFile}
echo `date "+%Y-%m-%d %H:%M:%S"` : "${ErrMsg}" >> ${LogFile}
echo `date "+%Y-%m-%d %H:%M:%S"`" : ${Type} Job Terminated" >> ${LogFile}
echo `date "+%Y-%m-%d %H:%M:%S"`" : Exit Status = -1" >> ${LogFile}
echo "#------------------------------- New Adhoc Archive Backup Job End -------------------------------#" >> ${LogFile}
echo >> ${LogFile}
fi
exit -1
}

#-------------------------------------
# Main Program Starts Here
#-------------------------------------

OraSid=$1
Type=$2
echo "#------------------------------- New Adhoc Archive Backup Job Begin -----------------------------#"
if [ $# -ne 2 ]
then
ErrMsg="Error. Usage : housekeeparch.ksh

"
ErrDisp
fi

if [ "$Type" != "PRE" -a "$Type" != "POST" ]
then
ErrMsg="Error. Usage : housekeeparch.ksh

"
ErrDisp
fi

LogFile=${ORACLE_BASE}/admin/${OraSid}/create/arch_files_${OraSid}_${MON}.log
echo `date "+%Y-%m-%d %H:%M:%S"`" : ${Type} Job Started"
echo
echo "Log File : $LogFile"
echo "ORACLE_SID : $OraSid"
echo "Type : $Type"
echo "Config File : $Conf"

echo "#------------------------------- New Adhoc Archive Backup Job Begin -----------------------------#" >> ${LogFile}
echo `date "+%Y-%m-%d %H:%M:%S"`" : ${Type} Job Started" >> ${LogFile}
echo >> ${LogFile}
echo "Log File : $LogFile" >> ${LogFile}
echo "ORACLE_SID : $OraSid" >> ${LogFile}
echo "Type : $Type" >> ${LogFile}
echo "Config File : $Conf" >> ${LogFile}

if [ ! -f ${Conf} ]
then
ErrMsg="Error : Config File Does not Exist."
ErrDisp
fi

ArchDir=`grep ARCHDST ${Conf}|grep ${OraSid}|cut -d: -f3`
echo "Archive Log Directory : $ArchDir"
echo "Archive Log Directory : $ArchDir" >> ${LogFile}

if [ ! -d ${ArchDir} ]
then
ErrMsg="Error. Archive Log Directory Not exist"
ErrDisp
fi

#if [ ! -e $ArchDir/*${OraSid}*arc* ]
#then
# ErrMsg="Error. Archive Log Directory empty"
# ErrDisp
#fi

ArchLogFile=${ArchDir}/arch_files_${OraSid}.log
echo "Archive Files List : $ArchLogFile"
echo "Archive Files List : $ArchLogFile" >> ${LogFile}

if [ " $Type " = " PRE " ]
then
if [ -f "${ArchLogFile}" ]
then
ErrMsg="Archive Log Backup is Running already"
ErrDisp
fi
echo >> ${LogFile}
echo "File System Usage" >> ${LogFile}
echo "-----------------" >> ${LogFile}
$BDF ${ArchDir} >> ${LogFile}
echo >> ${LogFile}
echo "List of Files" >> ${LogFile}
echo "-------------" >> ${LogFile}
ls -lt ${ArchDir}/*.arc* >> ${LogFile}
ls -ltr ${ArchDir}/*.arc*|awk '{print $9}' > ${ArchLogFile}
if [ $? -ne 0 ]
then
ErrMsg="Error in Creating Archive Log List File"
ErrDisp
fi
aclget ${ArchLogFile}|tail -9 > $aclfile
echo " enabled" >>$aclfile
echo "permit r-x u:oracle">>$aclfile
aclput -i $aclfile $ArchLogFile
chmod u-rwx,g-rwx,o-rwx ${ArchLogFile}
fi

if [ " $Type " = " POST " ]
then
if [ ! -f ${ArchLogFile} ]
then
ErrMsg="Error. Pre Image is not available"
ErrDisp
fi
chmod 400 ${ArchLogFile}
echo >> ${LogFile}
echo "List of Files" >> ${LogFile}
echo "-------------" >> ${LogFile}
cat ${ArchLogFile} >> ${LogFile}
echo >> ${LogFile}
for fname in `cat ${ArchLogFile}`
do
rm -f ${fname}*
echo "Removed File ... ${fname}" >> ${LogFile}
done
rm -f ${ArchLogFile}
if [ $? -ne 0 ]
then
echo "Error in Removing Archive Log List File ...exiting"
exit -1
fi
echo
echo >> ${LogFile}
echo "File System Usage" >> ${LogFile}
echo "-----------------" >> ${LogFile}
$BDF ${ArchDir} >> ${LogFile}
fi
echo
echo `date "+%Y-%m-%d %H:%M:%S"`" : ${Type} Job Completed"
echo `date "+%Y-%m-%d %H:%M:%S"`" : Exit Status = 0"
echo "#------------------------------- New Adhoc Archive Backup Job End -------------------------------#"
echo >> ${LogFile}
echo `date "+%Y-%m-%d %H:%M:%S"`" : ${Type} Job Completed" >> ${LogFile}
echo `date "+%Y-%m-%d %H:%M:%S"`" : Exit Status = 0" >> ${LogFile}
echo "#------------------------------- New Adhoc Archive Backup Job End -------------------------------#" >> ${LogFile}
echo >> ${LogFile}
##############################################################3

PWPBASE:/opt/pwp/3.0
ADMPAGE:35
TRFLAGE:15
LGFLAGE:30
ALOGAGE:180
ARCHLMT:75
ORAHLMT:85
CRSHLMT:85
ASMHLMT:85
ASMDLM1:15
ASMDLM2:5
ASMALM1:25
ASMALM2:15
TBLSLMT:15
EXTNMON:1
GRPMAIL:dba@citi.com
ARCHDST:cnccgu:/uccgreg2/uoradata/cnccgu_arch

[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/8337095/viewspace-1058199/,如需轉載,請註明出處,否則將追究法律責任。

相關文章