最佳實踐(保持、清理ORACLE alert日誌)

hurp_oracle發表於2015-06-23
Please modify the script variables below to your specifics.


LOGFILE_DIR
RETENTION_DAYS
RETENTION_SIZE

RUEI has a script called clean.sh

--------------------------------
#!/bin/bash
#
# Automatically clean the Automatic Diagnostics Repository (ADR) directories.
#
source /etc/ruei.conf &>/dev/null

RETENTION_DAYS=7
RETENTION_SIZE=10M

export PATH=$PATH:/usr/local/bin # oraenv needs to find dbhome
export ORACLE_SID=$RUEI_DB_INST # oraenv looks for this name in /etc/oratab

ORAENV_ASK=NO . oraenv &>/dev/null 0>&-

[ -z "${ORACLE_BASE}" ] && exit 1
[ -z "${ORACLE_HOME}" ] && exit 1

for dir in $ORACLE_BASE/diag \
  $ORACLE_HOME/log
do
  #
  # Too big files are moved to .bak (and .bak files will be removed when
  # they become too old).
  #
  find ${dir} -type f -size +$RETENTION_SIZE '!' -name '*.bak' \
  -exec mv '{}' '{}.bak' ';'

  #
  # Too old files are removed.
  #
  find ${dir} -type f -mtime +$RETENTION_DAYS -exec rm -f '{}' ';'

done &>/dev/null

exit 0
--------------------------------

you can modify the script as follows, just replace the right directory for LOGFILE_DIR:

--------------------------------
#!/bin/bash
#


LOGFILE_DIR= /usr/lib/oracle/11.2/client64/lib/log/diag/clients/user_moniforce....
RETENTION_DAYS=7
RETENTION_SIZE=10M

export PATH=$PATH:/usr/local/bin # oraenv needs to find dbhome



for dir in $LOGFILE_DIR
do
  #
  # Too big files are moved to .bak (and .bak files will be removed when
  # they become too old).
  #
  find ${dir} -type f -size +$RETENTION_SIZE '!' -name '*.bak' \
  -exec mv '{}' '{}.bak' ';'

  #
  # Too old files are removed.
  #
  find ${dir} -type f -mtime +$RETENTION_DAYS -exec rm -f '{}' ';'

done &>/dev/null

exit 0
--------------------------------



Please put it in the cron,
type 'man crontab', then '5' for details details on the syntax for the schedule frequency,
(the syntax requires higher maths, so luckily examples are included) 

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

相關文章