feat(hanatool): Add --replace flag for schema imports
Introduces a new '--replace' option to 'hanatool.sh' to allow replacing existing objects during schema import operations. Updates script version to 1.5.0.
This commit is contained in:
26
hanatool.sh
26
hanatool.sh
@@ -1,5 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Version: 1.4.6
|
# Version: 1.5.0
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
# SAP HANA Schema and Tenant Management Tool (hanatool.sh)
|
# SAP HANA Schema and Tenant Management Tool (hanatool.sh)
|
||||||
#
|
#
|
||||||
@@ -12,6 +12,7 @@ COMPRESS=false
|
|||||||
THREADS=0 # 0 means auto-calculate later
|
THREADS=0 # 0 means auto-calculate later
|
||||||
DRY_RUN=false
|
DRY_RUN=false
|
||||||
NTFY_TOKEN=""
|
NTFY_TOKEN=""
|
||||||
|
IMPORT_REPLACE=false
|
||||||
|
|
||||||
# --- Help/Usage Function ---
|
# --- Help/Usage Function ---
|
||||||
usage() {
|
usage() {
|
||||||
@@ -38,6 +39,7 @@ usage() {
|
|||||||
echo " -c, --compress Enable tar.gz compression for exports and backups."
|
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 " -n, --dry-run Show what commands would be executed without running them."
|
||||||
echo " --ntfy <token> Send a notification via ntfy.sh upon completion/failure."
|
echo " --ntfy <token> Send a notification via ntfy.sh upon completion/failure."
|
||||||
|
echo " --replace Use the 'REPLACE' option for imports instead of 'IGNORE EXISTING'."
|
||||||
echo " --hdbsql <path> Specify a custom path for the hdbsql executable."
|
echo " --hdbsql <path> Specify a custom path for the hdbsql executable."
|
||||||
echo " -h, --help Show this help message."
|
echo " -h, --help Show this help message."
|
||||||
echo ""
|
echo ""
|
||||||
@@ -48,8 +50,8 @@ usage() {
|
|||||||
echo " # Import MYSCHEMA from a compressed archive"
|
echo " # Import MYSCHEMA from a compressed archive"
|
||||||
echo " $0 MY_SCHEMA_KEY import MYSCHEMA /hana/backups/MYSCHEMA_20240101.tar.gz -c"
|
echo " $0 MY_SCHEMA_KEY import MYSCHEMA /hana/backups/MYSCHEMA_20240101.tar.gz -c"
|
||||||
echo ""
|
echo ""
|
||||||
echo " # Import MYSCHEMA as MYSCHEMA_TEST using a custom hdbsql path"
|
echo " # Import MYSCHEMA as MYSCHEMA_TEST, replacing any existing objects"
|
||||||
echo " $0 MY_SCHEMA_KEY import-rename MYSCHEMA MYSCHEMA_TEST /hana/backups/temp_export --hdbsql /sap/custom/hdbsql"
|
echo " $0 MY_SCHEMA_KEY import-rename MYSCHEMA MYSCHEMA_TEST /hana/backups/temp_export --replace"
|
||||||
}
|
}
|
||||||
|
|
||||||
# --- Notification Function ---
|
# --- Notification Function ---
|
||||||
@@ -83,6 +85,10 @@ while [[ $# -gt 0 ]]; do
|
|||||||
NTFY_TOKEN="$2"
|
NTFY_TOKEN="$2"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
|
--replace)
|
||||||
|
IMPORT_REPLACE=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
--hdbsql)
|
--hdbsql)
|
||||||
HDBSQL_PATH="$2"
|
HDBSQL_PATH="$2"
|
||||||
shift 2
|
shift 2
|
||||||
@@ -350,12 +356,20 @@ case "$ACTION" in
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
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
|
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
|
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
|
EXIT_CODE=0
|
||||||
if [[ "$DRY_RUN" == "true" ]]; then
|
if [[ "$DRY_RUN" == "true" ]]; then
|
||||||
|
|||||||
@@ -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["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["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["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.
|
# Example: Add a new script with its version.
|
||||||
# SCRIPT_PACKAGES["My Other Script"]="1.0.0|https://path/to/my-other-script.sh"
|
# SCRIPT_PACKAGES["My Other Script"]="1.0.0|https://path/to/my-other-script.sh"
|
||||||
|
|||||||
Reference in New Issue
Block a user