feat(hanatool): Include HANA tenant name in backup file names
This commit is contained in:
35
hanatool.sh
35
hanatool.sh
@@ -1,5 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Version: 1.5.2
|
# Version: 1.5.3
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
# SAP HANA Schema and Tenant Management Tool (hanatool.sh)
|
# SAP HANA Schema and Tenant Management Tool (hanatool.sh)
|
||||||
#
|
#
|
||||||
@@ -65,6 +65,28 @@ send_notification() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# --- Function to get HANA tenant name ---
|
||||||
|
get_hana_tenant_name() {
|
||||||
|
local user_key="$1"
|
||||||
|
local hdbsql_path="$2"
|
||||||
|
local dry_run="$3"
|
||||||
|
|
||||||
|
local query="SELECT DATABASE_NAME FROM SYS.M_DATABASES;"
|
||||||
|
local tenant_name=""
|
||||||
|
|
||||||
|
if [[ "$dry_run" == "true" ]]; then
|
||||||
|
echo "[DRY RUN] Would execute hdbsql to get tenant name: \"$hdbsql_path\" -U \"$user_key\" \"$query\""
|
||||||
|
tenant_name="DRYRUN_TENANT"
|
||||||
|
else
|
||||||
|
tenant_name=$("$hdbsql_path" -U "$user_key" "$query" | tail -n +2 | head -n 1 | tr -d '[:space:]' | tr -d '"')
|
||||||
|
if [[ -z "$tenant_name" ]]; then
|
||||||
|
echo "❌ Error: Could not retrieve HANA tenant name using user key '${user_key}'."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
echo "$tenant_name"
|
||||||
|
}
|
||||||
|
|
||||||
# --- Argument Parsing ---
|
# --- Argument Parsing ---
|
||||||
POSITIONAL_ARGS=()
|
POSITIONAL_ARGS=()
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
@@ -148,15 +170,18 @@ case "$ACTION" in
|
|||||||
echo " - Path: ${TARGET_PATH}"
|
echo " - Path: ${TARGET_PATH}"
|
||||||
echo " - Compress: ${COMPRESS}"
|
echo " - Compress: ${COMPRESS}"
|
||||||
|
|
||||||
|
TENANT_NAME=$(get_hana_tenant_name "$USER_KEY" "$HDBSQL_PATH" "$DRY_RUN")
|
||||||
|
echo " - Tenant Name: ${TENANT_NAME}"
|
||||||
|
|
||||||
timestamp=$(date +%Y%m%d_%H%M%S)
|
timestamp=$(date +%Y%m%d_%H%M%S)
|
||||||
backup_target_dir="$TARGET_PATH" # Initialize with TARGET_PATH
|
backup_target_dir="$TARGET_PATH" # Initialize with TARGET_PATH
|
||||||
backup_path_prefix=""
|
backup_path_prefix=""
|
||||||
|
|
||||||
if [[ "$COMPRESS" == "true" ]]; then
|
if [[ "$COMPRESS" == "true" ]]; then
|
||||||
if [[ "$DRY_RUN" == "true" ]]; then
|
if [[ "$DRY_RUN" == "true" ]]; then
|
||||||
backup_target_dir="${TARGET_PATH}/tenant_backup_DRYRUN_TEMP" # Use TARGET_PATH
|
backup_target_dir="${TARGET_PATH}/${TENANT_NAME}_backup_DRYRUN_TEMP" # Use TARGET_PATH
|
||||||
else
|
else
|
||||||
backup_target_dir=$(mktemp -d "${TARGET_PATH}/tenant_backup_${timestamp}_XXXXXXXX") # Use TARGET_PATH
|
backup_target_dir=$(mktemp -d "${TARGET_PATH}/${TENANT_NAME}_backup_${timestamp}_XXXXXXXX") # Use TARGET_PATH
|
||||||
fi
|
fi
|
||||||
echo "ℹ️ Using temporary backup directory: ${backup_target_dir}"
|
echo "ℹ️ Using temporary backup directory: ${backup_target_dir}"
|
||||||
fi
|
fi
|
||||||
@@ -167,7 +192,7 @@ case "$ACTION" in
|
|||||||
mkdir -p "$backup_target_dir"
|
mkdir -p "$backup_target_dir"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
backup_path_prefix="${backup_target_dir}/backup_${timestamp}"
|
backup_path_prefix="${backup_target_dir}/backup_${TENANT_NAME}_${timestamp}"
|
||||||
|
|
||||||
QUERY="BACKUP DATA USING FILE ('${backup_path_prefix}')"
|
QUERY="BACKUP DATA USING FILE ('${backup_path_prefix}')"
|
||||||
|
|
||||||
@@ -182,7 +207,7 @@ case "$ACTION" in
|
|||||||
if [[ "$EXIT_CODE" -eq 0 ]]; then
|
if [[ "$EXIT_CODE" -eq 0 ]]; then
|
||||||
echo "✅ Successfully initiated tenant backup with prefix '${backup_path_prefix}'."
|
echo "✅ Successfully initiated tenant backup with prefix '${backup_path_prefix}'."
|
||||||
if [[ "$COMPRESS" == "true" ]]; then
|
if [[ "$COMPRESS" == "true" ]]; then
|
||||||
ARCHIVE_FILE="${TARGET_PATH}/tenant_backup_${timestamp}.tar.gz"
|
ARCHIVE_FILE="${TARGET_PATH}/${TENANT_NAME}_backup_${timestamp}.tar.gz"
|
||||||
echo "🗜️ Compressing backup files to '${ARCHIVE_FILE}'..."
|
echo "🗜️ Compressing backup files to '${ARCHIVE_FILE}'..."
|
||||||
|
|
||||||
TAR_EXIT_CODE=0
|
TAR_EXIT_CODE=0
|
||||||
|
|||||||
@@ -14,4 +14,4 @@ SCRIPT_PACKAGES["backup"]="Backup Suite|1.0.5|A comprehensive script for backing
|
|||||||
SCRIPT_PACKAGES["monitor"]="Monitor Suite|1.3.1|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|https://git.technopunk.space/tomi/Scripts/raw/branch/main/monitor/monitor.hook.sh"
|
SCRIPT_PACKAGES["monitor"]="Monitor Suite|1.3.1|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|https://git.technopunk.space/tomi/Scripts/raw/branch/main/monitor/monitor.hook.sh"
|
||||||
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["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["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.2|A command-line tool for various SAP HANA administration tasks.|https://git.technopunk.space/tomi/Scripts/raw/branch/main/hanatool.sh"
|
SCRIPT_PACKAGES["hanatool"]="HANA Tool|1.5.3|A command-line tool for various SAP HANA administration tasks.|https://git.technopunk.space/tomi/Scripts/raw/branch/main/hanatool.sh"
|
||||||
|
|||||||
Reference in New Issue
Block a user