From 6c4ae7356695db3e99f7de16b0e5a11adb97d23e Mon Sep 17 00:00:00 2001 From: Tomi Eckert Date: Thu, 25 Sep 2025 17:31:31 +0200 Subject: [PATCH] ddd HANA backup monitoring --- monitor/monitor.conf | 2 ++ monitor/monitor.sh | 32 +++++++++++++++++++++++++++++++- packages.conf | 2 +- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/monitor/monitor.conf b/monitor/monitor.conf index 7973382..70d161d 100644 --- a/monitor/monitor.conf +++ b/monitor/monitor.conf @@ -27,6 +27,8 @@ DISK_USAGE_THRESHOLD=80 TRUNCATED_PERCENTAGE_THRESHOLD=50 # Percentage of 'Free' log segments below which an alert is triggered FREE_PERCENTAGE_THRESHOLD=25 +# Maximum age of the last successful full data backup in hours. +BACKUP_THRESHOLD_HOURS=25 # --- Monitored Directories --- # List of directories to check for disk usage (space-separated) diff --git a/monitor/monitor.sh b/monitor/monitor.sh index 6d947e5..bdf72cb 100644 --- a/monitor/monitor.sh +++ b/monitor/monitor.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Version: 1.0.5 +# Version: 1.1.0 # ============================================================================= # SAP HANA Monitoring Script # @@ -123,5 +123,35 @@ if (( $(echo "$free_percentage < $FREE_PERCENTAGE_THRESHOLD" | bc -l) )); then send_notification "HANA Log Segment Alert" "🚨 Alert: Only ${free_percentage}% of HANA log segments are in 'Free' state." fi +echo "â„šī¸ Checking last successful data backup status..." + +# Query to get the start time of the most recent successful complete data backup +last_backup_date=$(hdbsql -U "$HANA_USERKEY" -j -a -x \ + "SELECT TOP 1 SYS_START_TIME FROM M_BACKUP_CATALOG WHERE ENTRY_TYPE_NAME = 'complete data backup' AND STATE_NAME = 'successful' ORDER BY SYS_START_TIME DESC" 2>/dev/null | tr -d "\"" | sed 's/\..*//') # sed removes fractional seconds + +if [[ -z "$last_backup_date" ]]; then + # No successful backup found at all + local message="🚨 Critical: No successful complete data backup found for ${COMPANY_NAME} HANA." + echo "$message" + send_notification "HANA Backup Alert" "$message" + return +fi + +# Convert dates to epoch seconds for comparison +last_backup_epoch=$(date -d "$last_backup_date" +%s) +current_epoch=$(date +%s) +threshold_seconds=$((BACKUP_THRESHOLD_HOURS * 3600)) + +age_seconds=$((current_epoch - last_backup_epoch)) +age_hours=$((age_seconds / 3600)) + +if (( age_seconds > threshold_seconds )); then + local message="🚨 Critical: Last successful HANA backup for ${COMPANY_NAME} is ${age_hours} hours old, which exceeds the threshold of ${BACKUP_THRESHOLD_HOURS} hours. Last backup was on: ${last_backup_date}." + echo "$message" + send_notification "HANA Backup Alert" "$message" +else + echo "✅ Success! Last successful backup is ${age_hours} hours old (Threshold: ${BACKUP_THRESHOLD_HOURS} hours)." +fi + echo "✅ Success! HANA monitoring check complete." diff --git a/packages.conf b/packages.conf index 7ea45de..e97434d 100644 --- a/packages.conf +++ b/packages.conf @@ -10,7 +10,7 @@ declare -A SCRIPT_PACKAGES # Format: short_name="Display Name|Version|Description|URL1 URL2..." SCRIPT_PACKAGES["aurora"]="Aurora Suite|2.1.0|A collection of scripts for managing Aurora database instances.|https://git.technopunk.space/tomi/Scripts/raw/branch/main/aurora/aurora.sh https://git.technopunk.space/tomi/Scripts/raw/branch/main/aurora/aurora.conf" SCRIPT_PACKAGES["backup"]="Backup Suite|1.0.5|A comprehensive script for backing up system files and databases.|https://git.technopunk.space/tomi/Scripts/raw/branch/main/backup/backup.sh https://git.technopunk.space/tomi/Scripts/raw/branch/main/backup/backup.conf" -SCRIPT_PACKAGES["monitor"]="Monitor Suite|1.0.5|Scripts for monitoring system health and performance metrics.|https://git.technopunk.space/tomi/Scripts/raw/branch/main/monitor/monitor.sh https://git.technopunk.space/tomi/Scripts/raw/branch/main/monitor/monitor.conf" +SCRIPT_PACKAGES["monitor"]="Monitor Suite|1.1.0|Scripts for monitoring system health and performance metrics.|https://git.technopunk.space/tomi/Scripts/raw/branch/main/monitor/monitor.sh https://git.technopunk.space/tomi/Scripts/raw/branch/main/monitor/monitor.conf" SCRIPT_PACKAGES["keymanager"]="Key Manager|1.2.1|A utility for managing HDB user keys for SAP HANA.|https://git.technopunk.space/tomi/Scripts/raw/branch/main/keymanager.sh" SCRIPT_PACKAGES["cleaner"]="File Cleaner|1.1.0|A simple script to clean up temporary files and logs.|https://git.technopunk.space/tomi/Scripts/raw/branch/main/cleaner.sh" SCRIPT_PACKAGES["hanatool"]="HANA Tool|1.5.0|A command-line tool for various SAP HANA administration tasks.|https://git.technopunk.space/tomi/Scripts/raw/branch/main/hanatool.sh"