From 05bd96e8b2232197b020635d84b8f24a98b4427c Mon Sep 17 00:00:00 2001 From: Tomi Eckert Date: Wed, 24 Sep 2025 21:10:15 +0200 Subject: [PATCH] update hana with replace flag --- hanatool.sh | 26 ++++++++++++++++++++------ packages.conf | 2 +- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/hanatool.sh b/hanatool.sh index d7b0d87..e420fe4 100644 --- a/hanatool.sh +++ b/hanatool.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Version: 1.4.6 +# Version: 1.5.0 # ============================================================================== # SAP HANA Schema and Tenant Management Tool (hanatool.sh) # @@ -12,6 +12,7 @@ COMPRESS=false THREADS=0 # 0 means auto-calculate later DRY_RUN=false NTFY_TOKEN="" +IMPORT_REPLACE=false # --- Help/Usage Function --- usage() { @@ -38,6 +39,7 @@ usage() { echo " -c, --compress Enable tar.gz compression for exports and backups." echo " -n, --dry-run Show what commands would be executed without running them." echo " --ntfy Send a notification via ntfy.sh upon completion/failure." + echo " --replace Use the 'REPLACE' option for imports instead of 'IGNORE EXISTING'." echo " --hdbsql Specify a custom path for the hdbsql executable." echo " -h, --help Show this help message." echo "" @@ -48,8 +50,8 @@ usage() { echo " # Import MYSCHEMA from a compressed archive" echo " $0 MY_SCHEMA_KEY import MYSCHEMA /hana/backups/MYSCHEMA_20240101.tar.gz -c" echo "" - echo " # Import MYSCHEMA as MYSCHEMA_TEST using a custom hdbsql path" - echo " $0 MY_SCHEMA_KEY import-rename MYSCHEMA MYSCHEMA_TEST /hana/backups/temp_export --hdbsql /sap/custom/hdbsql" + echo " # Import MYSCHEMA as MYSCHEMA_TEST, replacing any existing objects" + echo " $0 MY_SCHEMA_KEY import-rename MYSCHEMA MYSCHEMA_TEST /hana/backups/temp_export --replace" } # --- Notification Function --- @@ -83,6 +85,10 @@ while [[ $# -gt 0 ]]; do NTFY_TOKEN="$2" shift 2 ;; + --replace) + IMPORT_REPLACE=true + shift + ;; --hdbsql) HDBSQL_PATH="$2" shift 2 @@ -350,12 +356,20 @@ case "$ACTION" in exit 1 fi - QUERY_RENAME_PART="" + local import_options + if [[ "$IMPORT_REPLACE" == "true" ]]; then + import_options="REPLACE" + echo " - Mode: REPLACE" + else + import_options="IGNORE EXISTING" + echo " - Mode: IGNORE EXISTING (default)" + fi + if [[ "$ACTION" == "import-rename" ]]; then - QUERY_RENAME_PART="RENAME SCHEMA \"${SCHEMA_NAME}\" TO \"${NEW_SCHEMA_NAME}\"" + import_options="${import_options} RENAME SCHEMA \"${SCHEMA_NAME}\" TO \"${NEW_SCHEMA_NAME}\"" fi - QUERY="IMPORT \"${SCHEMA_NAME}\".\"*\" AS BINARY FROM '${IMPORT_DIR}' WITH IGNORE EXISTING THREADS ${THREADS} ${QUERY_RENAME_PART};" + QUERY="IMPORT \"${SCHEMA_NAME}\".\"*\" AS BINARY FROM '${IMPORT_DIR}' WITH ${import_options} THREADS ${THREADS};" EXIT_CODE=0 if [[ "$DRY_RUN" == "true" ]]; then diff --git a/packages.conf b/packages.conf index d8448e1..c3349b2 100644 --- a/packages.conf +++ b/packages.conf @@ -12,6 +12,6 @@ SCRIPT_PACKAGES["Backup Suite"]="1.0.5|https://git.technopunk.space/tomi/Scripts SCRIPT_PACKAGES["Monitor Suite"]="1.0.5|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["Key Manager"]="1.2.1|https://git.technopunk.space/tomi/Scripts/raw/branch/main/hdb_keymanager.sh" SCRIPT_PACKAGES["File Cleaner"]="1.1.0|https://git.technopunk.space/tomi/Scripts/raw/branch/main/clean.sh" -SCRIPT_PACKAGES["HANA Tool"]="1.4.6|https://git.technopunk.space/tomi/Scripts/raw/branch/main/hanatool.sh" +SCRIPT_PACKAGES["HANA Tool"]="1.5.0|https://git.technopunk.space/tomi/Scripts/raw/branch/main/hanatool.sh" # Example: Add a new script with its version. # SCRIPT_PACKAGES["My Other Script"]="1.0.0|https://path/to/my-other-script.sh"