add config file to hanamgr, cleaned up hanamgr prompts

This commit is contained in:
2026-06-24 12:15:31 +02:00
parent bcc6427eea
commit a171fdd1e2
2 changed files with 61 additions and 9 deletions
+60 -8
View File
@@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
# Version: 1.6.0 # Version: 1.7.0
# Author: Tomi Eckert # Author: Tomi Eckert
# ============================================================================== # ==============================================================================
# HANA Database Manager Menu (hanamgr.sh) # HANA Database Manager Menu (hanamgr.sh)
@@ -111,8 +111,12 @@ do_export() {
echo -e "\n\033[1m=== Export Schema ===\033[0m" echo -e "\n\033[1m=== Export Schema ===\033[0m"
select_schema "$GLOBAL_USER_KEY" select_schema "$GLOBAL_USER_KEY"
local schema_name="$SELECTED_SCHEMA" local schema_name="$SELECTED_SCHEMA"
read -p "Enter Target Directory or File Path (.tar.gz): " target_path local default_export_path="/hana/shared/backup/schema"
echo " Without compression: provide a parent directory — the script will create a new subdirectory inside it."
echo " With compression: provide a parent directory (script auto-names the .tar.gz), or a full path ending in .tar.gz (script creates that file)."
read -p "Target path [${default_export_path}]: " target_path
target_path="${target_path:-${default_export_path}}"
local max_threads=$(nproc --all 2>/dev/null || echo 1) local max_threads=$(nproc --all 2>/dev/null || echo 1)
local half_threads=$((max_threads / 2)) local half_threads=$((max_threads / 2))
[[ $half_threads -lt 1 ]] && half_threads=1 [[ $half_threads -lt 1 ]] && half_threads=1
@@ -297,7 +301,10 @@ do_copy() {
fi fi
read -p "Enter Target Schema Name: " target_schema read -p "Enter Target Schema Name: " target_schema
read -p "Enter Temporary Export Directory Path: " export_path local default_copy_path="/hana/shared/backup/schema"
echo " Provide a parent directory — the script will create a temporary subdirectory inside it for the intermediate export, then delete it when done."
read -p "Temporary export directory [${default_copy_path}]: " export_path
export_path="${export_path:-${default_copy_path}}"
local max_threads=$(nproc --all 2>/dev/null || echo 1) local max_threads=$(nproc --all 2>/dev/null || echo 1)
local half_threads=$((max_threads / 2)) local half_threads=$((max_threads / 2))
@@ -448,14 +455,59 @@ do_rename_db() {
check_hdbsql check_hdbsql
# --- Config ---
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CONFIG_FILE="${SCRIPT_DIR}/.hanamgr.conf"
load_config() {
if [[ -f "$CONFIG_FILE" ]]; then
local saved_key
saved_key=$(grep -m1 '^HDBUSERSTORE_KEY=' "$CONFIG_FILE" | cut -d'=' -f2-)
if [[ -n "$saved_key" ]]; then
echo "$saved_key"
fi
fi
}
save_config() {
local key="$1"
if [[ -f "$CONFIG_FILE" ]]; then
# Update existing key entry
sed -i "s|^HDBUSERSTORE_KEY=.*|HDBUSERSTORE_KEY=${key}|" "$CONFIG_FILE"
if ! grep -q '^HDBUSERSTORE_KEY=' "$CONFIG_FILE"; then
echo "HDBUSERSTORE_KEY=${key}" >> "$CONFIG_FILE"
fi
else
echo "HDBUSERSTORE_KEY=${key}" > "$CONFIG_FILE"
fi
}
echo echo
echo "========================================================" echo "========================================================"
echo " HANA Database Manager Init " echo " HANA Database Manager Init "
echo "========================================================" echo "========================================================"
read -p "Enter HDBUSERSTORE Key: " GLOBAL_USER_KEY
if [[ -z "$GLOBAL_USER_KEY" ]]; then SAVED_KEY="$(load_config)"
echo -e "\033[31m[ERROR] Key is required.\033[0m" if [[ -n "$SAVED_KEY" ]]; then
exit 1 read -p "Use saved HDBUSERSTORE key '${SAVED_KEY}'? [Y/n]: " use_saved
use_saved="${use_saved:-Y}"
if [[ "$use_saved" =~ ^[Yy]$ ]]; then
GLOBAL_USER_KEY="$SAVED_KEY"
else
read -p "Enter HDBUSERSTORE Key: " GLOBAL_USER_KEY
if [[ -z "$GLOBAL_USER_KEY" ]]; then
echo -e "\033[31m[ERROR] Key is required.\033[0m"
exit 1
fi
save_config "$GLOBAL_USER_KEY"
fi
else
read -p "Enter HDBUSERSTORE Key: " GLOBAL_USER_KEY
if [[ -z "$GLOBAL_USER_KEY" ]]; then
echo -e "\033[31m[ERROR] Key is required.\033[0m"
exit 1
fi
save_config "$GLOBAL_USER_KEY"
fi fi
while true; do while true; do
+1 -1
View File
@@ -16,4 +16,4 @@ SCRIPT_PACKAGES["monitor"]="Monitor Suite|1.3.1|Scripts for monitoring system he
SCRIPT_PACKAGES["keymanager"]="Key Manager|1.2.3|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.3|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.6.0|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.6.0|A command-line tool for various SAP HANA administration tasks.|https://git.technopunk.space/tomi/Scripts/raw/branch/main/hanatool.sh"
SCRIPT_PACKAGES["hanamgr"]="HANA Manager UI|1.6.0|An interactive command-line menu for managing SAP HANA schemas and databases.|https://git.technopunk.space/tomi/Scripts/raw/branch/main/hanamgr.sh" SCRIPT_PACKAGES["hanamgr"]="HANA Manager UI|1.7.0|An interactive command-line menu for managing SAP HANA schemas and databases.|https://git.technopunk.space/tomi/Scripts/raw/branch/main/hanamgr.sh"