Oracle archive log cleanup script

Here’s a quick bash script to clean up archive logs older than a week. It reads the Oracle SIDs from /etc/oratab and invokes rman for each SID. One could put this in cron to be run once a day to keep disk space usage in check.

#!/bin/bash
#
# clean up old archive logs
#

# save the original PATH
OLDPATH=$PATH

# function which calls RMAN and deletes old logs
doit ()
{
rman target / <<HERE
delete noprompt archivelog until time ‘sysdate-7’;
HERE
}

# doit for each SID in /etc/oratab
for l in `grep -v ‘^#’ /etc/oratab`; do
export ORACLE_SID=`echo $l | cut -d: -f1`
export ORACLE_HOME=`echo $l | cut -d: -f2`
export PATH=$ORACLE_HOME/bin:$OLDPATH
doit
done

Posted in Uncategorized

Leave a Reply

Your email address will not be published. Required fields are marked *

*