ITPub博客

首页 > Linux操作系统 > Linux操作系统 > oracle日志分割-purge_logs

oracle日志分割-purge_logs

原创 Linux操作系统 作者:wwd_wang 时间:2010-11-05 09:51:48 0 删除 编辑
[xszntsnoradb@oracle:/u01/app/oracle/admin/VPETEST/bdump] cat /home/oracle/scripts/purge_logs
#!/usr/bin/env ksh

###########################################################################
#
# script  : purge_logs
# auteur  : philippe CATHERINE
# objet   : purge des fichiers de logs oracle 'superflus'
#
# version : v1.2
# sortie  : ($?) 0 => OK   1 => KO
#
# A noter que ce la retention peut etre adaptée selon les besoins
# (variables RETENTION_TRACES & RETENTION_ALERTLOG)
#
###########################################################################
#set -x  #set -e

# Check if oratab exists
if [[ -r "/var/opt/oracle/oratab" ]]; then
        RATAB=/var/opt/oracle/oratab
elif [[ -r "/etc/oratab" ]]; then
        RATAB=/etc/oratab
else
        echo ""; echo " !! File ${ORATAB} missing...."; echo ""
        return 1
fi

RETENTION_TRACES='2'
RETENTION_ALERTLOG='5'
DATE=`date +'%d%m%y'`

cat ${ORATAB}|grep -v "#"|grep ":Y" |awk -F: '{print $1" "$2}'| while read ORACLE_SID ORACLE_HOME; do
        ## Suppression des traces du listener
        cp /var/opt/oracle/lsnrdump/LSN_${ORACLE_SID}.log /var/opt/oracle/lsnrdump/LSN_${ORACLE_SID}.${DATE}.log
        cat /dev/null > /var/opt/oracle/lsnrdump/LSN_${ORACLE_SID}.log
        find /var/opt/oracle/lsnrdump -name "LSN_*.log" -mtime +${RETENTION_TRACES} -print -exec rm -f {} \;
        ## Suppression des fichiers aud
        find /u01/app/oracle/admin/${ORACLE_SID}/adump -name "*.aud" -mtime +${RETENTION_TRACES} -print -exec rm -f {} \;
        find ${ORACLE_HOME}/rdbms/audit -name "*.aud" -mtime +${RETENTION_TRACES} -print -exec rm -f {} \;
        ## Suppression des fichiers trace (9i)
        find ${ORACLE_HOME}/rdbms/log -name "*.trc" -mtime +${RETENTION_TRACES} -print -exec rm -f {} \;
        ## Suppression des fichiers trace
        find /u01/app/oracle/admin/${ORACLE_SID}/bdump -name "*.trc" -mtime +${RETENTION_TRACES} -print -exec rm -f {} \;
        ## Suppression des fichiers alertlog        
        cp /u01/app/oracle/admin/${ORACLE_SID}/bdump/alert_${ORACLE_SID}.log /u01/app/oracle/admin/${ORACLE_SID}/bdump/alert_${ORACLE_SID}.${DATE}.log
        cat /dev/null > /u01/app/oracle/admin/${ORACLE_SID}/bdump/alert_${ORACLE_SID}.log
        find /u01/app/oracle/admin/${ORACLE_SID}/bdump  -name "alert_*.log" -mtime +${RETENTION_ALERTLOG} -print -exec rm -f {} \;
done

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/12137615/viewspace-677544/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2008-05-08

  • 博文量
    236
  • 访问量
    195082