Every running Oracle installation has several directories and files that need to be rotated and/or purged. Surprisingly, or not, Oracle has not included this basic maintenance in their software. I have come across the oraclean utility in the past, but the script does not do everything I need.
To achieve what I required, I recently hacked together a single script that does the following things:
- Cleans audit_dump_dest.
- Cleans background_dump_dest.
- Cleans core_dump_dest.
- Cleans user_dump_dest.
- Cleans Oracle Clusterware log files.
- Rotates and purges alert log files.
- Rotates and purges listener log files.
The script has been tested on Solaris 9 and 10 with Oracle database versions 9i and 10g. It has also been tested with Oracle Clusterware and ASM 11g. The script can be scheduled on each server having one or more Oracle homes installed, and it will clean all of them up using the retention policy specified. The limitation is that log file retention is specified per server, not per instance. However, I find that placing a single crontab entry on each database server is easier than setting up separate log purge processes for each one.
The script finds all unique Oracle Homes listed in the oratab file and retrieves the list of running Oracle instances and listeners. Once the script knows that information, it rotates and cleans the trace, dump, and log files.
Usage: [bash]cleanhouse.sh -d DAYS [-a DAYS] [-b DAYS] [-c DAYS] [-n DAYS] [-r DAYS] [-u DAYS] [-t] [-h]
-d = Mandatory default number of days to keep log files that are not explicitly passed as parameters.
-a = Optional number of days to keep audit logs.
-b = Optional number of days to keep background dumps.
-c = Optional number of days to keep core dumps.
-n = Optional number of days to keep network log files.
-r = Optional number of days to keep clusterware log files.
-u = Optional number of days to keep user dumps.
-h = Optional help mode.
-t = Optional test mode. Does not delete any files.[/bash]