{"id":4273,"date":"2025-06-16T23:45:39","date_gmt":"2025-06-16T23:45:39","guid":{"rendered":"https:\/\/w3buddy.com\/?post_type=cposts&#038;p=4273"},"modified":"2025-06-16T23:54:22","modified_gmt":"2025-06-16T23:54:22","slug":"automate-deletion-of-old-archive-logs-using-rman","status":"publish","type":"cposts","link":"https:\/\/w3buddy.com\/blog\/notes\/shell-scripts\/automate-deletion-of-old-archive-logs-using-rman\/","title":{"rendered":"Automate Deletion of Old Archive Logs Using RMAN"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">This shell script is part of the <strong>Shell Script Automations<\/strong> toolkit for Oracle DBAs. It helps automatically delete archive logs that are older than a day using RMAN. It also performs cleanup of expired and obsolete entries from the RMAN catalog. Ideal for environments <strong>where archive logs are not backed up<\/strong> and need to be purged regularly to free up space.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udcdc Shell Script: <code>rman_arch_del.sh<\/code><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code><code>################################################################################\n# Title   : Automated Deletion of Old Archive Logs Using RMAN\n# Script  : rman_arch_del.sh\n# Purpose : Deletes archive logs older than 1 day and cleans up RMAN metadata.\n#\n# Features:\n#   - Deletes archive logs older than SYSDATE - 1\n#   - Crosschecks archive logs and backups\n#   - Deletes expired and obsolete metadata\n#   - Cron-friendly and lightweight\n#\n# Author  : W3Buddy\n# Version : 1.2\n################################################################################\n\n#!\/bin\/bash\n\n# Set Oracle Environment - Update as per your environment\nexport ORACLE_HOME=\/oracle\/app\/oracle\/product\/12.1.0.2.0\nexport ORACLE_SID=PARIS12C\nexport PATH=$ORACLE_HOME\/bin:$PATH\n\n# Run RMAN commands and log output\nrman log=\/home\/oracle\/arch_del.log &lt;&lt;EOF\nCONNECT TARGET \/\n\n-- Delete archive logs older than 1 day\nDELETE NOPROMPT ARCHIVELOG ALL COMPLETED BEFORE 'SYSDATE-1';\n\n-- Validate catalog entries\nCROSSCHECK ARCHIVELOG ALL;\nCROSSCHECK BACKUP;\n\n-- Remove expired entries\nDELETE EXPIRED ARCHIVELOG ALL;\nDELETE EXPIRED BACKUP;\n\n-- Remove obsolete backups using policy\nDELETE NOPROMPT OBSOLETE;\n\nEXIT\nEOF<\/code><\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\u2705 <strong>NOTE:<\/strong> This script avoids the use of <code>DELETE FORCE OBSOLETE<\/code> to prevent accidental deletion of useful backups. Add it only if you\u2019re certain it\u2019s required.<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\">\u2699\ufe0f Setup Instructions<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code><code># ----------------------------------------------\n# 1. Create the script file\n# ----------------------------------------------\ncd \/u01\/app\/oracle\nvi rman_arch_del.sh\n\n# (Paste the full script above into the file and save)\n\n# ----------------------------------------------\n# 2. Make the script executable\n# ----------------------------------------------\nchmod +x rman_arch_del.sh\n\n# ----------------------------------------------\n# 3. Test the script manually\n# ----------------------------------------------\n.\/rman_arch_del.sh\n\n# Check the log file for details:\ncat \/home\/oracle\/arch_del.log\n\n# ----------------------------------------------\n# 4. Schedule with cron (every night at 10:00 PM)\n# ----------------------------------------------\ncrontab -e\n\n# Add this line:\n00 22 * * * \/u01\/app\/oracle\/rman_arch_del.sh >> \/tmp\/rmanarch.log 2>&amp;1\n\n# ----------------------------------------------\n# 5. Confirm the cron entry\n# ----------------------------------------------\ncrontab -l<\/code><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This shell script is part of the Shell Script Automations toolkit for Oracle DBAs. It helps automatically delete archive logs that are older than a day using RMAN. It also performs cleanup of expired and obsolete entries from the RMAN catalog. Ideal for environments where archive logs are not backed up and need to be [&hellip;]<\/p>\n","protected":false},"template":"","meta":{"googlesitekit_rrm_CAowu461DA:productID":""},"categories":[952,990],"class_list":["post-4273","cposts","type-cposts","status-publish","hentry","category-notes","category-shell-scripts"],"_links":{"self":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/cposts\/4273","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/cposts"}],"about":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/types\/cposts"}],"wp:attachment":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/media?parent=4273"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/categories?post=4273"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}