Being an Oracle Database Administrator, managing filesystem can be
challenging task, especially when it comes to keeping the storage clean
and efficient. One common challenge is dealing with the accumulation of
diagnostic logs, particularly XML files, in the Oracle Automatic
Diagnostic Repository (ADR). Over time, these files can consume a
significant amount of disk space.
Today, I'm sharing a nifty script to automate the purging of these XML files which can be scheduled in crontab where it can clear the files older than 30 days. This script will help you keep your ADR clean and your database performing optimally. Let's dive in!
The Script
Today, I'm sharing a nifty script to automate the purging of these XML files which can be scheduled in crontab where it can clear the files older than 30 days. This script will help you keep your ADR clean and your database performing optimally. Let's dive in!
The Script
Here's the magic script that will handle the purging process:
#!/bin/bash # Environment setup export GRID_HOME=/u01/app/grid export PATH=$GRID_HOME/bin:/bin:$PATH # Log file for the script SCRIPT_LOG=/home/grid/bin/purge_adr.log # Age in minutes for purging files older than 30 days (30 days * 24 hours * 60 minutes) SCRIPT_AGE=$((30 * 24 * 60)) # Current date date >> $SCRIPT_LOG # ADR home directories HOMES=( "diag/tnslsnr/d1racnode/listener_scan1" "diag/tnslsnr/d1racnode/listener" "diag/tnslsnr/d1racnode/mgmtlsnr" "diag/tnslsnr/d1racnode/asmnet1lsnr_asm" "diag/tnslsnr/d1racnode/listener_test" ) # Loop through each ADR home and purge old XML files for h in "${HOMES[@]}" do adrci_home=$h echo "Purging from: $adrci_home" >> $SCRIPT_LOG adrci exec="set homepath ${adrci_home}; purge -age ${SCRIPT_AGE}" -type ALERT >> $SCRIPT_LOG done exit 0
How it works :
- Environment Setup: We start by defining the GRID_HOME and updating the PATH to ensure our script can locate the necessary binaries.
- Logging: All actions taken by the script are logged to /home/grid/bin/purge_adr.log for auditing and troubleshooting purposes
- Purge Age: The script calculates the age threshold for purging files,set to 30 days. This is converted into minutes for the ADRCI purge command.
- ADR Home Directories : These are the locations where Oracle stores its diagnostic logs.
- Purging Process: The script loops through each ADR home directory and executes the ADRCI command to purge files older than 30 days. Each purging action is logged
Final Thoughts
Automating routine maintenance tasks like purging old XML files can save you a lot of time and help maintain the performance of your Oracle database. This script is a simple yet effective tool to add to your database management arsenal. Happy scripting, and may your databases always run smoothly!
No comments:
Post a Comment