File Maintenance (OS Files, Purging)
Overview
Should you find that Oracle database's ability to self maintain peripheral logs and files is inadequate this might help. If nothing else you can use this as a fail-safe so your OS volumes do not become full.
Manual script below. For an ADR script example (adr.purge.sh) go here.
One directory that can be overlooked is where old patches are stored. $ORACLE_HOME/.patch_storage
- Get existing dirs:
ls -l $ORACLE_HOME/.patch_storage > /tmp/dir0.txt - Get lsinventory found dirs:
$ORACLE_HOME/OPatch/opatch lsinventory | grep -E "(^Patch.*applied)|(^Sub-patch)" - Remove directories of patches not found in the lsinventory.
• Directory names would be prefaced with the patchid for example: 13343438_<timestamp>.
• Do not remove the Sub-patch folders.
See: How To Avoid Disk Full Issues Because OPatch Backups Take Big Amount Of Disk Space. (Doc ID 550522.1)
Cron Example (via root)
OUT=/u01/app/scripts/out AUD_DIR_GRID=/u01/app/12.1.0/grid/rdbms/audit AUD_DIR_RDBMS=/u01/app/oracle/product/12.1.0.2/db_1/rdbms/audit # Daily 00 05 * * * find $AUD_DIR_GRID -type f -name '*.aud' -mtime +15 -delete > $OUT/AUD_DIR_GRID.out 15 05 * * * find $AUD_DIR_RDBMS -type f -name '*.aud' -mtime +15 -delete > $OUT/AUD_DIR_RDBMS.out
Adjust as needed for your environment.
Script Example (Manual)
#!/bin/bash # 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. ORACLE_SID="oradb"; ORACLE_BASE="/u01/app/oracle"; ORACLE_HOME="/u01/app/oracle/product/12.1.0.2/dbhome_1"; GRID_HOME="/u01/app/12.1.0.2/grid"; # 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 # Audit find $ORACLE_BASE/admin/$ORACLE_SID/adump -type f -name '*.aud' -mtime +$usrAudRet -delete find $ORACLE_HOME/rdbms/audit -type f -name '*.aud' -mtime +$usrAudRet -delete find $GRID_HOME/rdbms/audit -type f -name '*.aud' -mtime +$usrAudRet -delete # alert find $ORACLE_BASE/diag/rdbms/$ORACLE_SID/$ORACLE_SID1/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/$ORACLE_SID/$ORACLE_SID1/trace -type f -name '*.tr?' -mtime +$usrStdRet -delete ##find $ORACLE_BASE/diag/tnslsnr/$HOSTNAME/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 $ORACLE_BASE/diag/tnslsnr/$HOSTNAME/listener -type f -name '*.log.[1-9]' -mtime +$usrStdRet -delete # cvures ##find $ORACLE_BASE/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/$ORACLE_SID -type f -name '*.bkp' -mtime +$usrRmnRet -delete