Archive Traces

######################################################################
#!/bin/bash
# Author : Rodrigo Mufalani (rodrigo@mufalani.com.br)
# Date : November 19th, 2009
# From : Mufalani
# To :
# Purpose : Archive *.trc data monthly
######################################################################
# Obs : Remember to set your env variables accordingly
######################################################################

set -a
ORACLE_BASE=/u01/app
ORACLE_HOME=$ORACLE_BASE/oracle/product/10.2.0
PATH=/usr/bin:/usr/ccs/bin:/usr/ucb:/usr/sbin:/usr/local/bin:/etc:$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:.
NLS_LANG=’american_america.WE8ISO8859P1′
DBA=’suporte@mufalani.com.br’
HOST=`hostname`
DATA=`date +%d%m%y_%H%M`
DUMPDIR=/tmp
OUTF=${DUMPDIR}/log_traces_${HOST}_${DATA}.out
ERRF=${DUMPDIR}/log_traces_${HOST}_${DATA}.err
set +a

function archive_trace1 (){
tar -cf traces_$HOST_$DATA.tar *.trc *.log *.aud
rm -rf *.trc *.log *.aud
gzip traces_$HOST_$DATA.tar
}

function archive_trace2 (){
for i in `ls $ORACLE_BASE/admin/$ORACLE_SID`;
do
cd $ORACLE_BASE/admin/$ORACLE_SID/$i;
echo “Archive traces at … $ORACLE_BASE/admin/$ORACLE_SID/$i”;
archive_trace1;
echo ” “;
done
}

exec 9>&2
exec 2>>$ERRF
{
set -x
DATE=`date “+%d/%m/%Y %H:%M”`
echo “”
echo “==================================================================================== ”
echo “————- Beginning archive traces 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 ” ”

for i in `ps -ef | grep smon | grep -v grep | awk -F”_” ‘{print $3}’` ; do
ORACLE_SID=$i
archive_trace2;
done;
RETURN_STATUS=$?

echo
DATE=`date “+%d/%m/%Y %H:%M”`
echo “==================================================================================== ”
echo “————- Archive traces of ${ORACLE_SID} finished ————— $DATE”
echo “==================================================================================== ”
echo
echo “exit $RETURN_STATUS”
} >> $OUTF

exec 2>&9

if [ $RETURN_STATUS -eq 0 ]; then
mailx -s “Archive traces – Success!!!” $DBA < $OUTF;
else
mailx -s “Archive traces – Failed!!!” $DBA < $ERRF;
fi

exit $RETURN_STATUS

 

Deixe uma resposta

O seu endereço de email não será publicado. Campos obrigatórios são marcados com *