Remove SAPCONTROL_PATH and HDBSQL_PATH variables from configuration. Update scripts to rely on the system PATH environment variable when executing as the <sid>adm user. Remove redundant existence checks for these commands.
73 lines
2.7 KiB
Bash
73 lines
2.7 KiB
Bash
#!/bin/bash
|
|
# =============================================================================
|
|
# SAP HANA Backup Status Monitoring Script
|
|
# Checks last successful backup age
|
|
# =============================================================================
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
|
|
SCRIPT_NAME="hana_backup"
|
|
|
|
# Load configuration
|
|
source "${SCRIPT_DIR}/hana.conf"
|
|
source "${SCRIPT_DIR}/hana_lib.sh"
|
|
|
|
# Acquire lock
|
|
if ! acquire_lock "$SCRIPT_NAME"; then
|
|
exit 1
|
|
fi
|
|
trap 'release_lock "$SCRIPT_NAME"' EXIT
|
|
|
|
log_message "$SCRIPT_NAME" "Starting backup status check..."
|
|
|
|
# SQL Query for last successful backup
|
|
BACKUP_SQL="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"
|
|
|
|
# Execute SQL query
|
|
backup_result=$(execute_hana_sql "$BACKUP_SQL")
|
|
sql_status=$?
|
|
|
|
if [ $sql_status -ne 0 ]; then
|
|
log_message "$SCRIPT_NAME" "ERROR: Failed to execute backup query. Exit code: ${sql_status}"
|
|
send_alert "$SCRIPT_NAME" "HANA Backup Error" "Failed to execute backup query. Exit code: ${sql_status}"
|
|
exit 1
|
|
fi
|
|
|
|
last_backup_date=$(echo "$backup_result" | tr -d '"' | sed 's/\..*//')
|
|
|
|
if [[ -z "$last_backup_date" || "$last_backup_date" == *"error"* || "$last_backup_date" == *"Error"* ]]; then
|
|
message="No successful complete data backup found for ${COMPANY_NAME} HANA."
|
|
log_message "$SCRIPT_NAME" "CRITICAL: ${message}"
|
|
send_alert "$SCRIPT_NAME" "HANA Backup" "$message"
|
|
exit 1
|
|
fi
|
|
|
|
# Calculate backup age
|
|
last_backup_epoch=$(date -d "$last_backup_date" +%s 2>/dev/null)
|
|
if [ $? -ne 0 ]; then
|
|
log_message "$SCRIPT_NAME" "ERROR: Failed to parse backup date: ${last_backup_date}"
|
|
send_alert "$SCRIPT_NAME" "HANA Backup" "Failed to parse backup date: ${last_backup_date}"
|
|
exit 1
|
|
fi
|
|
|
|
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 -lt 0 ]; then
|
|
log_message "$SCRIPT_NAME" "WARNING: Backup timestamp is in the future. Possible clock skew."
|
|
age_hours=0
|
|
fi
|
|
|
|
if [ $age_seconds -gt $threshold_seconds ]; then
|
|
message="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}."
|
|
log_message "$SCRIPT_NAME" "CRITICAL: ${message}"
|
|
send_alert "$SCRIPT_NAME" "HANA Backup" "$message"
|
|
exit 1
|
|
else
|
|
message="Last successful backup is ${age_hours} hours old (Threshold: ${BACKUP_THRESHOLD_HOURS} hours)."
|
|
log_message "$SCRIPT_NAME" "SUCCESS: ${message}"
|
|
fi
|
|
|
|
log_message "$SCRIPT_NAME" "Backup check complete."
|