oracledba.help
Scripts

DBA Script

<- Scripts

#!/bin/bash
# Purpose:      Keep an Oracle system clean of unneeded files.
# Version:      2018.10.01
# Dependencies: inc_system.sh

######################################
# Preamble: 2018.10.01               #
######################################
set -a; DIR_SCRIPTS="/u01/app/scripts"; source $DIR_SCRIPTS/inc_system.sh
sFullName=$(basename "$0"); me=${sFullName%.*}
sSLog="$DIR_LOGS/$me.sess.log"; sHLog="$DIR_LOGS/$me.hist.log"; > $sSLog
if [[ $MAINT_WINDOW -eq 1 ]]; then printf "Maintenance Window Detected - Exiting\n"; exit; fi

# User Vars
usrStdRet=35; # Days to retain files, i.e. standard retention.
usrAudRet=7;  # Days to retain Audit files.
usrRmnRet=14; # Days to retain RMAN files.
GRID_HOME="/u01/app/12.1.0.2/grid";

######################################
# Init Script Actions\Functions\Vars #
######################################
# NA


######################################
# Start                              #
######################################
clear; log "$sSLog" "$sFullName Started"; linesep
SysVars_show

# Scripts
find /u01/app/scripts/logs                     -type f -name '*.log' -mtime +$usrStdRet -delete
find /u01/app/scripts/tmp                      -type f -name '*.tmp' -mtime +$usrStdRet -delete

# oracle
find $ORACLE_BASE/admin/dnat/adump             -type f -name '*.aud' -mtime +$usrAudRet -delete
find $ORACLE_HOME/rdbms/audit                  -type f -name '*.aud' -mtime +$usrAudRet -delete
#find /u01/app/12.1.0.2/grid/rdbms/audit        -type f -name '*.aud' -mtime +$usrAudRet -delete

# alert
find $ORACLE_BASE/diag/rdbms/dnat/dnat1/alert  -type f -name '*.xml' -mtime +$usrStdRet -delete

# trace
find $ORACLE_HOME/network/trace                -type f -name '*.tr?' -mtime +$usrStdRet -delete
find $ORACLE_BASE/diag/rdbms/dnat/dnat1/trace  -type f -name '*.tr?' -mtime +$usrStdRet -delete
#find /u01/app/oracle/diag/tnslsnr/mlbltdnasolov01/listener/trace -type f -name '*.tr?' -mtime +$usrStdRet -delete

# lsinv
find $ORACLE_HOME/cfgtoollogs/opatch/lsinv -type f -name 'lsinventory*.txt' -mtime +$usrStdRet -delete
find $GRID_HOME/cfgtoollogs/opatch/lsinv   -type f -name 'lsinventory*.txt' -mtime +$usrStdRet -delete


# Listener
#find /u01/app/oracle/diag/tnslsnr/mlbltdnasolov01/listener -type f -name '*.log.[1-9]' -mtime +$usrStdRet -delete

# cvures
#find /u01/app/oracle/crsdata/@global/cvu/baseline/cvures -type f -name '*.zip' -mtime +$usrStdRet -delete

# gpnp Logs (GRID Environments)
#find /u01/app/grid/12.1.0.2/log/mlblpdnaorav01/client -type f -name '*.log' -mtime +$usrStdRet -delete

# RMAN
find /u03/rman/dnat -type f -name '*.bkp' -mtime +$usrRmnRet -delete



######################################
# End                                #
######################################
log "$sSLog" "$sFullName Ended [Elapse Time: $(elapse)]";
echo $(linesep "=") >> $sHLog; cat $sSLog >> $sHLog;
tail -32768 $sHLog > $sHLog.tmp; mv $sHLog.tmp $sHLog