Posted on

Emergency cleanup of files on Exadata compute node

This is an aggressive script to clear space in an Exadata compute node. Use with caution as it wipes out a lot of logs quickly.

## Cleanup of filesystems by the root user
# First, cleanup system files
journalctl --vacuum-time=1s

# Remove un-needed system files
rm -rf /tmp/OraInstall*
rm -f /var/log/*.1
rm -f /var/log/*gz
# Clear the ones we do need to keep
:> /var/spool/mail/root
:> /var/log/rdbmsaudit.log
:> /var/log/asmaudit.log

## Oracle file cleanup
. /u01/app/oracle/bin/ora_funcs.sh
# Migrate schemas before we run purgelogs
oe PRD
ADR_HOME=`ls -d /u01/app/oracle/diag/rdbms/ftsprd*/$ORACLE_SID|cut -c17-`
#echo $ADR_HOME
export ORACLE_HOME=/u01/app/oracle/product/18.0.0.0/DbHome_1;/u01/app/oracle/product/18.0.0.0/DbHome_1/bin/adrci exec="set homepath $ADR_HOME; migrate schema"
# Fix permissions - If these pv dirs are owned by root, you can't login locally
chown -R oracle /u01/app/oracle/diag/rdbms/*/*/metadata_pv
/u01/app/oracle/bin/purgeLogs -orcl 1 -osw 1 -oda 1 -extra /tmp:1,/var/log:1

DIAGDIR=/u01/app/oracle/diag/rdbms
cd $DIAGDIR

# remove core dumps
rm -rf ${DIAGDIR}/*/*/trace/cdmp*
find /u01/app -name "cdmp*" -type d -delete

# remove incident files
rm -rf ${DIAGDIR}/*/*/incident/incdir*

DIAGDIR=/u01/app

# remove audit files
find /u01/app -mount -name "*.aud" -type f -delete

# remove zero length files older than 6 hours
find $DIAGDIR -mount -name "*.trc" -type f -size 0 -mmin +360 -delete
find $DIAGDIR -mount -name "*.trm" -type f -size 0 -mmin +360 -delete

# clear older trace files
#find $DIAGDIR -mount -name "*.trc" -type f -size +0 -mmin +10 -execdir cp /dev/null {} \;
#find $DIAGDIR -mount -name "*.trm" -type f -size +0 -mmin +10 -execdir cp /dev/null {} \;

# Clear of all large trace files
find $DIAGDIR -mount -name "*.trc" -type f -size +0 -execdir cp /dev/null {} \;
find $DIAGDIR -mount -name "*.trm" -type f -size +0 -execdir cp /dev/null {} \;

# Check ownership of directories
ls -ld /u01/app/oracle/diag/rdbms/*/*/metadata_pv