add hanamgr option to copy schemas

This commit is contained in:
2026-04-16 15:38:47 +02:00
parent 84e3928668
commit 20a632eca7
2 changed files with 75 additions and 8 deletions
+74 -7
View File
@@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
# Version: 1.3.1 # Version: 1.4.0
# Author: Tomi Eckert # Author: Tomi Eckert
# ============================================================================== # ==============================================================================
# HANA Database Manager Menu (hanamgr.sh) # HANA Database Manager Menu (hanamgr.sh)
@@ -286,6 +286,69 @@ do_drop() {
fi fi
} }
do_copy() {
echo -e "\n\033[1m=== Copy Schema ===\033[0m"
select_schema "$GLOBAL_USER_KEY"
local source_schema="$SELECTED_SCHEMA"
if [[ -z "$source_schema" ]]; then
echo -e "\033[31m[❌] Error: Source Schema is required.\033[0m"
return
fi
read -p "Enter Target Schema Name: " target_schema
read -p "Enter Temporary Export Directory Path: " export_path
local max_threads=$(nproc --all 2>/dev/null || echo 1)
local half_threads=$((max_threads / 2))
[[ $half_threads -lt 1 ]] && half_threads=1
read -p "Number of threads (default: $half_threads, max: $max_threads): " threads
threads=${threads:-$half_threads}
read -p "Replace existing objects in target schema? (y/N): " replace_opt
if [[ -z "$GLOBAL_USER_KEY" || -z "$target_schema" || -z "$export_path" ]]; then
echo -e "\033[31m[❌] Error: Key, Target Schema, and Path are required.\033[0m"
return
fi
# 1. Export
echo -e "\n[⬇️] Step 1/2: Exporting source schema '${source_schema}' to '${export_path}'..."
mkdir -p "$export_path"
local temp_export_dir=$(mktemp -d "${export_path}/copy_export_${source_schema}_XXXXXXXX")
echo "[️] Using temporary export directory: ${temp_export_dir}"
local export_query="EXPORT \"${source_schema}\".\"*\" AS BINARY INTO '${temp_export_dir}' WITH REPLACE THREADS ${threads} NO DEPENDENCIES;"
if ! execute_sql "$GLOBAL_USER_KEY" "$export_query"; then
echo -e "\033[31m[❌] Error: Export phase failed. Aborting copy.\033[0m"
rm -rf "$temp_export_dir"
return
fi
echo -e "\033[32m[✅] Export phase completed successfully.\033[0m"
# 2. Import-Rename
echo -e "\n[⬆️] Step 2/2: Importing and renaming to '${target_schema}'..."
local import_options="IGNORE EXISTING"
if [[ "$replace_opt" =~ ^[Yy]$ ]]; then
import_options="REPLACE"
fi
import_options="${import_options} RENAME SCHEMA \"${source_schema}\" TO \"${target_schema}\""
local import_query="IMPORT \"${source_schema}\".\"*\" AS BINARY FROM '${temp_export_dir}' WITH ${import_options} THREADS ${threads};"
if execute_sql "$GLOBAL_USER_KEY" "$import_query"; then
echo -e "\033[32m[✅] Successfully copied schema '${source_schema}' to '${target_schema}'.\033[0m"
else
echo -e "\033[31m[❌] Error: Import phase failed.\033[0m"
fi
# Cleanup
echo "[🧹] Cleaning up temporary files..."
rm -rf "$temp_export_dir"
}
do_rename_db() { do_rename_db() {
echo -e "\n\033[1m=== Rename Database (Company Name) ===\033[0m" echo -e "\n\033[1m=== Rename Database (Company Name) ===\033[0m"
select_schema "$GLOBAL_USER_KEY" select_schema "$GLOBAL_USER_KEY"
@@ -334,11 +397,12 @@ while true; do
echo "1) Export Schema" echo "1) Export Schema"
echo "2) Import Schema" echo "2) Import Schema"
echo "3) Import-Rename Schema" echo "3) Import-Rename Schema"
echo "4) Drop Schema" echo "4) Copy Schema"
echo "5) Rename Database (Update Company Name)" echo "5) Drop Schema"
echo "6) Quit" echo "6) Rename Database (Update Company Name)"
echo "7) Quit"
echo echo
read -p "Please select an option (1-6): " choice read -p "Please select an option (1-7): " choice
case $choice in case $choice in
1) 1)
@@ -351,12 +415,15 @@ while true; do
do_import "true" do_import "true"
;; ;;
4) 4)
do_drop do_copy
;; ;;
5) 5)
do_rename_db do_drop
;; ;;
6) 6)
do_rename_db
;;
7)
echo "[👋] Exiting." echo "[👋] Exiting."
exit 0 exit 0
;; ;;
+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.3.1|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.4.0|An interactive command-line menu for managing SAP HANA schemas and databases.|https://git.technopunk.space/tomi/Scripts/raw/branch/main/hanamgr.sh"