Clean Up Oracle archive log using cron

Oracle

Cron List

Oracle has capability for creating hot backup using archive log mechanism. This feature act like recovery data system for restoring database content to specified time if the original database has force major which make data corrupted.

But, this mechanism will suck up the free space of hard disk and typically if we donít maintain the following problem maybe occured :

  1. The Space allocated for archive run out which make all transaction will be suspended
  2. Hard disk space will be run out

Usually we can delete completed archive log using RMAN command, but this sometimes takes time.

Below is automation script for deleting completed archive log using cron.

  1. create script (named cleanarchive.sh) !/bin/bash export ORACLE_BASE=/database/oracle/app/oracle
    export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
    export ORACLE_OWNR=oracle
    export ORACLE_SID=orcl
    export PATH=$PATH:$ORACLE_HOME/bin su ñ oracle -c rman target / << EOF
    DELETE NOPROMPT ARCHIVELOG ALL COMPLETED BEFORE ëSYSDATE -7í;
    EXIT
    EOF
  2. create new job on cron sequence (will be executed everyday at 22:55) crontab -e 55 22 * * * /bin/sh /database/oracle/crontab/cleanarchive.sh >/database/oracle/crontab/arch.log 2>&1
  3. Restart cron service

Voila , now the completed archive log will be checked and cleaned up every day, and we just left the archive less then 7 day till the day executed.