Pages

Thursday, June 10, 2021

Oracle logs cleanup

===========================================
Keep listener log size under control
===========================================

crontab
1 6 * * * /software/oracle/oracle/scripts/clean_oracle_logs.sh

/software/oracle/oracle/scripts/clean_oracle_logs.sh
#!/bin/bash
. /etc/sh/orash/oracle_login.sh igt
ORA_INST=igt
LIST_SERVER=`hostname`

DAYS_TO_KEEP=14
AUD_DAYS_TO_KEEP=30
DAYS_TO_KEEP_LIST=2

LISTENER_TRACE=/software/oracle/diag/tnslsnr/${LIST_SERVER}/lsnr_igt/trace
LISTENER_TRACE_2=/software/oracle/diag/tnslsnr/${LIST_SERVER}/listener/trace

LISTENER_ALERT=/software/oracle/diag/tnslsnr/${LIST_SERVER}/lsnr_igt/alert
LISTENER_ALERT_2=/software/oracle/diag/tnslsnr/${LIST_SERVER}/listener/alert


LOG_PATH=${ORACLE_HOME}/rdbms/log
AUDIT_PATH=/software/oracle/admin/igt/adump

find /software/oracle/diag/rdbms/${ORA_INST}/${ORA_INST}/alert -type f  -mtime +${DAYS_TO_KEEP} -exec rm {} \;
#find /software/oracle/diag/rdbms/${ORA_INST}/${ORA_INST}/trace -type f -mtime +${DAYS_TO_KEEP} -exec rm {} \;
#find /software/oracle/diag/rdbms/${ORA_INST}/${ORA_INST}/trace -type f -size +1000M -exec rm {} \;

mv -f  ${LISTENER_TRACE}/lsnr_igt.log_6  ${LISTENER_TRACE}/lsnr_igt.log_7
mv -f  ${LISTENER_TRACE}/lsnr_igt.log_5  ${LISTENER_TRACE}/lsnr_igt.log_6
mv -f  ${LISTENER_TRACE}/lsnr_igt.log_4  ${LISTENER_TRACE}/lsnr_igt.log_5
mv -f  ${LISTENER_TRACE}/lsnr_igt.log_3  ${LISTENER_TRACE}/lsnr_igt.log_4
mv -f  ${LISTENER_TRACE}/lsnr_igt.log_2  ${LISTENER_TRACE}/lsnr_igt.log_3
mv -f  ${LISTENER_TRACE}/lsnr_igt.log_1  ${LISTENER_TRACE}/lsnr_igt.log_2
mv -f  ${LISTENER_TRACE}/lsnr_igt.log    ${LISTENER_TRACE}/lsnr_igt.log_1

mv -f  ${LISTENER_TRACE_2}/listener.log_6  ${LISTENER_TRACE_2}/listener.log_7
mv -f  ${LISTENER_TRACE_2}/listener.log_5  ${LISTENER_TRACE_2}/listener.log_6
mv -f  ${LISTENER_TRACE_2}/listener.log_4  ${LISTENER_TRACE_2}/listener.log_5
mv -f  ${LISTENER_TRACE_2}/listener.log_3  ${LISTENER_TRACE_2}/listener.log_4
mv -f  ${LISTENER_TRACE_2}/listener.log_2  ${LISTENER_TRACE_2}/listener.log_3
mv -f  ${LISTENER_TRACE_2}/listener.log_1  ${LISTENER_TRACE_2}/listener.log_2
mv -f  ${LISTENER_TRACE_2}/listener.log    ${LISTENER_TRACE_2}/listener.log_1

#rm -f /software/oracle/diag/tnslsnr/${LIST_SERVER}/lsnr_igt/alert/*.xml


find $LISTENER_ALERT   -type f -mtime +${DAYS_TO_KEEP_LIST} -exec rm {} \;
find $LISTENER_ALERT_2 -type f -mtime +${DAYS_TO_KEEP_LIST} -exec rm {} \;

find ${LOG_PATH} -type f -mtime +${DAYS_TO_KEEP} -exec rm {} \;
find ${AUDIT_PATH} -type f -mtime +${AUD_DAYS_TO_KEEP} -exec rm {} \;

# Delete ogg dmp files
find /software/ogg/*/dirdmp/ -name '*.dmp' -exec \rm -f {} \; 2>/dev/null

===========================================
Delete old backup log files
===========================================
/home/shdaemon/scripts/clean_backup_logs.sh
#!/bin/bash

DAYS_TO_KEEP=30

BACKUP_EXP_LOGS=/backup/ora_exp/for_backup/old_log
BACKUP_RMAN_LOGS=/backup/ora_online/for_backup/log

EXP_LOG_PREFIX=export_igt
METADATA_EXP_LOG_PREFIX=metadata_export_igt
ONLINE_LOG_PREFIX=rman

find  ${BACKUP_EXP_LOGS}/${EXP_LOG_PREFIX}* -type f  -mtime +${DAYS_TO_KEEP} -exec rm -f {} \;
find  ${BACKUP_EXP_LOGS}/${METADATA_EXP_LOG_PREFIX}* -type f  -mtime +${DAYS_TO_KEEP} -exec rm -f {} \;
find  ${BACKUP_RMAN_LOGS}/${ONLINE_LOG_PREFIX}* -type f  -mtime +${DAYS_TO_KEEP} -exec rm -f {} \;

===========================================
Keep /var/log files under control
===========================================
#!/bin/bash

export DAYS_TO_KEEP=14
export LOG_PATH=/var/spool/clientmqueue
find $LOG_PATH -type f -mtime +${DAYS_TO_KEEP} -exec rm {} \;

export DAYS_TO_KEEP=30
export LOG_PATH=/var/log/aide
find $LOG_PATH -type f -mtime +${DAYS_TO_KEEP} -exec rm {} \;


per folder
cd /software/oracle/; 
du -sh *
find /software/oracle/ -type f -printf '%s %p\n'sort -nr | head -10

No comments:

Post a Comment