Wednesday, February 13, 2019

How to take backup listener log, SCAN listener log

 This script is to backup the alert log and listener log to a backup location.  A weekly or monthly cron job can be scheduled to run this script.



#!/bin/ksh
.  ~oracle/.env
export timestamp=`date +%y%m%d`
export machine=`hostname`
typeset -u machine
export MACHINE=`echo $machine |awk -F. '{print $1}'`
export LIS_NAME1=NOLISTENER1
export LIS_NAME2=NOLISTENER2
export LIS_NAME3=NOLISTENER3
case ${MACHINE} in
        NODE101)
        export LIS_NAME1=listener_scan1
        export LIS_NAME2=listener_scan2
        export LIS_NAME3=listener_scan3
        export LIS_NAME=listener
        export LOGBACKDIR=~oracle/prod/backup/logbackup
        ;;
        *)
        echo "\n\n Error: Environment \"${Market}\" not defined for this job"
        exit 8
esac

#mkdir $LOGBACKDIR

#
# copy the log files to the backup directory and create an empty *.log file
#

cp ${ORACLE_BASE}/diag/tnslsnr/${HOSTNAME}/${LIS_NAME}/trace/${LIS_NAME}.log $LOGBACKDIR/${LIS_NAME}.$timestamp
if [ $? == 0 ]
then
> ${ORACLE_BASE}/diag/tnslsnr/${HOSTNAME}/${LIS_NAME}/trace/${LIS_NAME}.log
fi

if [ "$LIS_NAME1" != "NOLISTENER1" ]; then
cp /u01/app/11.2.0/grid_2/log/diag/tnslsnr/${HOSTNAME}/${LIS_NAME1}/trace/${LIS_NAME1}.log $LOGBACKDIR/${LIS_NAME1}.$timestamp
if [ $? == 0 ]
then
> /u01/app/11.2.0/grid_2/log/diag/tnslsnr/${HOSTNAME}/${LIS_NAME1}/trace/${LIS_NAME1}.log
fi
gzip ${LOGBACKDIR}/${LIS_NAME1}.$timestamp
fi


if [ "$LIS_NAME2" != "NOLISTENER2" ]; then
cp /u01/app/11.2.0/grid_2/log/diag/tnslsnr/${HOSTNAME}/${LIS_NAME2}/trace/${LIS_NAME2}.log $LOGBACKDIR/${LIS_NAME2}.$timestamp
if [ $? == 0 ]
then
> /u01/app/11.2.0/grid_2/log/diag/tnslsnr/${HOSTNAME}/${LIS_NAME2}/trace/${LIS_NAME2}.log
fi
gzip ${LOGBACKDIR}/${LIS_NAME2}.$timestamp
fi

if [ "$LIS_NAME3" != "NOLISTENER3" ]; then
cp /u01/app/11.2.0/grid_2/log/diag/tnslsnr/${HOSTNAME}/${LIS_NAME3}/trace/${LIS_NAME3}.log $LOGBACKDIR/${LIS_NAME3}.$timestamp
if [ $? == 0 ]
then
> /u01/app/11.2.0/grid_2/log/diag/tnslsnr/${HOSTNAME}/${LIS_NAME3}/trace/${LIS_NAME3}.log
fi
gzip ${LOGBACKDIR}/${LIS_NAME3}.$timestamp
fi
#
# zip up the old logs files in the background
#
cd $LOGBACKDIR
gzip ${LIS_NAME}.$timestamp
ls -lrt *.$timestamp.*

find $LOGBACKDIR -name '*' -mtime +365 -exec rm {} \;

exit

No comments:

Post a Comment