update hana with replace flag
This commit is contained in:
28
hanatool.sh
28
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 <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 " -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=""
|
||||
if [[ "$ACTION" == "import-rename" ]]; then
|
||||
QUERY_RENAME_PART="RENAME SCHEMA \"${SCHEMA_NAME}\" TO \"${NEW_SCHEMA_NAME}\""
|
||||
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
|
||||
|
||||
QUERY="IMPORT \"${SCHEMA_NAME}\".\"*\" AS BINARY FROM '${IMPORT_DIR}' WITH IGNORE EXISTING THREADS ${THREADS} ${QUERY_RENAME_PART};"
|
||||
if [[ "$ACTION" == "import-rename" ]]; then
|
||||
import_options="${import_options} RENAME SCHEMA \"${SCHEMA_NAME}\" TO \"${NEW_SCHEMA_NAME}\""
|
||||
fi
|
||||
|
||||
QUERY="IMPORT \"${SCHEMA_NAME}\".\"*\" AS BINARY FROM '${IMPORT_DIR}' WITH ${import_options} THREADS ${THREADS};"
|
||||
|
||||
EXIT_CODE=0
|
||||
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["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"
|
||||
|
||||
Reference in New Issue
Block a user