← Backup & Recovery
Oracle · Backup & Recovery

How to purge Oracle archivelogs older than one day with RMAN

Delete Oracle archivelogs already backed up and older than one day using RMAN DELETE ARCHIVELOG, wrapped in a shell script for cron.

Tested on11g12c18c19c21c23ai26ai

Wrap RMAN in a here-doc so it can run from cron. Deletes archivelogs that RMAN considers completed before SYSDATE-1. Safer than a raw find + rm because RMAN tracks which archivelogs are already backed up and refuses to delete ones that are still needed.

Deletes archivelogs. Make sure your RMAN retention and archivelog backup schedule are correct first — otherwise you can lose recoverability. Test with LIST ARCHIVELOG ALL COMPLETED BEFORE ''SYSDATE-1'' before switching to DELETE.

#!/bin/bash
# Purge archivelogs older than 1 day that RMAN considers already backed up.
# Meant for cron; source the Oracle profile so ORACLE_HOME / ORACLE_SID are set.

. /oracle/dba/.profile

rman target / <<'__EOF__'
  DELETE NOPROMPT FORCE ARCHIVELOG ALL COMPLETED BEFORE 'SYSDATE-1';
  EXIT
__EOF__

# ---------------------------------------------
# Dry-run alternative (run this from RMAN first):
# ---------------------------------------------
# LIST ARCHIVELOG ALL COMPLETED BEFORE 'SYSDATE-1';
# CROSSCHECK ARCHIVELOG ALL;
# DELETE NOPROMPT EXPIRED ARCHIVELOG ALL;
rmanarchiveloghousekeepingshell