Showing posts with label adrci. Show all posts
Showing posts with label adrci. Show all posts

Friday, July 26, 2024

Purge ADR Contents

# Purge ADR contents (adr_purge.sh)
# 00 05 * * 0 adr_purge.sh
# Add the above line with `crontab -e` to the oracle user's cron
 
ALERT_RET="129600" # 90 Days
INCIDENT_RET="43200" # 30 Days
TRACE_RET="43200" # 30 Days
CDUMP_RET="43200" # 30 Days
HM_RET="43200" # 30 Days
 
echo "INFO: adrci purge started at `date`"
adrci exec="show homes"|grep -v : | while read file_line
do
echo "INFO: adrci purging diagnostic destination " $file_line
echo "INFO: purging ALERT older than 90 days"
adrci exec="set homepath $file_line;purge -age $ALERT_RET -type ALERT"
echo "INFO: purging INCIDENT older than 30 days"
adrci exec="set homepath $file_line;purge -age $INCIDENT_RET -type INCIDENT"
echo "INFO: purging TRACE older than 30 days"
adrci exec="set homepath $file_line;purge -age $TRACE_RET -type TRACE"
echo "INFO: purging CDUMP older than 30 days"
adrci exec="set homepath $file_line;purge -age $CDUMP_RET -type CDUMP"
echo "INFO: purging HM older than 30 days"
adrci exec="set homepath $file_line;purge -age $HM_RET -type HM"
echo ""
echo ""
done
echo
echo "INFO: adrci purge finished at `date`"

Thursday, July 25, 2024

ADRCI - Purge Database Logs/traces

 #!/bin/bash
# Script By Mohamed Fowjil
# Function to purge logs and traces older than 30 days using ADRCI for a specific ADR home
purge_adrci() {
    local home_path="$1"
    echo "Purging logs and traces older than 30 days for ADR home: $home_path"
    adrci exec="set homepath $home_path; purge -age 43200"  # 43200 minutes = 30 days
}
# Function to rotate alert logs
rotate_alert_log() {
    local alert_log="$1"
    if [ -f "$alert_log" ]; then
        echo "Rotating alert log: $alert_log"
        mv "$alert_log" "${alert_log}.$(date +%Y%m%d%H%M%S).bak"
        touch "$alert_log"
    else
        echo "Alert log not found: $alert_log"
    fi
}
# Function to rotate listener logs
rotate_listener_log() {
    local listener_log="$1"
    if [ -f "$listener_log" ]; then
        echo "Rotating listener log: $listener_log"
        mv "$listener_log" "${listener_log}.$(date +%Y%m%d%H%M%S).bak"
        touch "$listener_log"
    else
        echo "Listener log not found: $listener_log"
    fi
}
# Function to purge audit files older than 30 days
purge_audit_files() {
    local audit_directory="$1"
    if [ -d "$audit_directory" ]; then
        echo "Purging audit files older than 30 days in: $audit_directory"
        find "$audit_directory" -type f -name "*.aud" -mtime +30 -exec rm -f {} \;
    else
        echo "Audit directory not found: $audit_directory"
    fi
}
# Main script execution
echo "Starting Oracle Database log management..."
# Fetch the list of ADR homes
adr_homes=$(adrci exec="show homes" | grep -v "ADR Homes:" | grep -v "^$")
# Check if there are any ADR homes to process
if [ -z "$adr_homes" ]; then
    echo "No ADR homes found."
    exit 1
fi
# Purge logs for Oracle Database homes
for home in $adr_homes; do
    if [[ "$home" == *"rdbms"* ]]; then
        purge_adrci "$home"
    fi
done
# Rotate alert logs for database  instances
alert_logs=("/u01/app/oracle/diag/rdbms/*/*/trace/alert*.log")
for log in "${alert_logs[@]}"; do
    for log_file in $log; do
        rotate_alert_log "$log_file"
    done
done
# Rotate listener logs
##listener_logs=("/u01/app/oracle/diag/tnslsnr/*/listener*/alert/log.xml" )
for log in "${listener_logs[@]}"; do
    for log_file in $log; do
        rotate_listener_log "$log_file"
    done
done


# Purge audit files in common directories
audit_directories=("/u01/app/oracle/admin/*/adump")
for dir in "${audit_directories[@]}"; do
    for audit_dir in $dir; do
        purge_audit_files "$audit_dir"
    done
done
echo "Oracle Database log management completed."