fix hanamgr not able to compress exports

This commit is contained in:
2026-04-16 15:31:45 +02:00
parent 8a8a11ace6
commit 84e3928668
2 changed files with 39 additions and 23 deletions
+37 -21
View File
@@ -1,5 +1,5 @@
#!/bin/bash
# Version: 1.2.0
# Version: 1.3.1
# Author: Tomi Eckert
# ==============================================================================
# HANA Database Manager Menu (hanamgr.sh)
@@ -109,12 +109,11 @@ select_schema() {
do_export() {
echo -e "\n\033[1m=== Export Schema ===\033[0m"
read -p "Enter HDBUSERSTORE Key: " user_key
select_schema "$user_key"
select_schema "$GLOBAL_USER_KEY"
local schema_name="$SELECTED_SCHEMA"
read -p "Enter Target Directory Path: " target_path
read -p "Enter Target Directory or File Path (.tar.gz): " target_path
local max_threads=$(nproc 2>/dev/null || echo 1)
local max_threads=$(nproc --all 2>/dev/null || echo 1)
local half_threads=$((max_threads / 2))
[[ $half_threads -lt 1 ]] && half_threads=1
@@ -123,16 +122,27 @@ do_export() {
read -p "Compress output as tar.gz? (y/N): " compress
if [[ -z "$user_key" || -z "$schema_name" || -z "$target_path" ]]; then
if [[ -z "$GLOBAL_USER_KEY" || -z "$schema_name" || -z "$target_path" ]]; then
echo -e "\033[31m[❌] Error: Key, Schema, and Path are required.\033[0m"
return
fi
echo -e "\n[⬇️] Starting export of schema '${schema_name}'..."
local export_dir="$target_path"
local archive_file=""
if [[ "$compress" =~ ^[Yy]$ ]]; then
# If the target path ends with .tar.gz, treat it as the final filename
if [[ "$target_path" == *.tar.gz ]]; then
archive_file="$target_path"
local target_dir=$(dirname "$target_path")
mkdir -p "$target_dir"
export_dir=$(mktemp -d "${target_dir}/export_${schema_name}_XXXXXXXX")
else
archive_file="${target_path}/${schema_name}_export_$(date +%Y%m%d_%H%M%S).tar.gz"
mkdir -p "$target_path"
export_dir=$(mktemp -d "${target_path}/export_${schema_name}_XXXXXXXX")
fi
echo "[️] Using temporary export directory: ${export_dir}"
else
mkdir -p "$export_dir"
@@ -140,11 +150,10 @@ do_export() {
local query="EXPORT \"${schema_name}\".\"*\" AS BINARY INTO '${export_dir}' WITH REPLACE THREADS ${threads} NO DEPENDENCIES;"
if execute_sql "$user_key" "$query"; then
if execute_sql "$GLOBAL_USER_KEY" "$query"; then
echo -e "\033[32m[✅] Successfully exported schema '${schema_name}'.\033[0m"
if [[ "$compress" =~ ^[Yy]$ ]]; then
local archive_file="${target_path}/${schema_name}_export_$(date +%Y%m%d_%H%M%S).tar.gz"
echo "[📦] Compressing export to ${archive_file}..."
if command -v pigz &> /dev/null; then
@@ -175,7 +184,6 @@ do_import() {
echo -e "\n\033[1m=== Import Schema ===\033[0m"
fi
read -p "Enter HDBUSERSTORE Key: " user_key
read -p "Enter Source Schema Name (as it was exported): " schema_name
local new_schema_name=""
@@ -189,7 +197,7 @@ do_import() {
read -p "Enter Source Path (Directory or .tar.gz): " source_path
local max_threads=$(nproc 2>/dev/null || echo 1)
local max_threads=$(nproc --all 2>/dev/null || echo 1)
local half_threads=$((max_threads / 2))
[[ $half_threads -lt 1 ]] && half_threads=1
@@ -198,7 +206,7 @@ do_import() {
read -p "Replace existing objects? (y/N): " replace_opt
if [[ -z "$user_key" || -z "$schema_name" || -z "$source_path" ]]; then
if [[ -z "$GLOBAL_USER_KEY" || -z "$schema_name" || -z "$source_path" ]]; then
echo -e "\033[31m[❌] Error: Key, Schema, and Path are required.\033[0m"
return
fi
@@ -240,7 +248,7 @@ do_import() {
local query="IMPORT \"${schema_name}\".\"*\" AS BINARY FROM '${import_dir}' WITH ${import_options} THREADS ${threads};"
if execute_sql "$user_key" "$query"; then
if execute_sql "$GLOBAL_USER_KEY" "$query"; then
echo -e "\033[32m[✅] Successfully imported schema.\033[0m"
else
echo -e "\033[31m[❌] Error: Import failed.\033[0m"
@@ -254,11 +262,10 @@ do_import() {
do_drop() {
echo -e "\n\033[1m=== Drop Schema ===\033[0m"
read -p "Enter HDBUSERSTORE Key: " user_key
select_schema "$user_key"
select_schema "$GLOBAL_USER_KEY"
local schema_name="$SELECTED_SCHEMA"
if [[ -z "$user_key" || -z "$schema_name" ]]; then
if [[ -z "$GLOBAL_USER_KEY" || -z "$schema_name" ]]; then
echo -e "\033[31m[❌] Error: Key and Schema Name are required.\033[0m"
return
fi
@@ -269,7 +276,7 @@ do_drop() {
if [[ "$confirm" == "YES" ]]; then
echo "[🗑️] Dropping schema '${schema_name}'..."
local query="DROP SCHEMA \"${schema_name}\" CASCADE"
if execute_sql "$user_key" "$query"; then
if execute_sql "$GLOBAL_USER_KEY" "$query"; then
echo -e "\033[32m[✅] Schema successfully dropped.\033[0m"
else
echo -e "\033[31m[❌] Error: Failed to drop schema.\033[0m"
@@ -281,12 +288,11 @@ do_drop() {
do_rename_db() {
echo -e "\n\033[1m=== Rename Database (Company Name) ===\033[0m"
read -p "Enter HDBUSERSTORE Key: " user_key
select_schema "$user_key"
select_schema "$GLOBAL_USER_KEY"
local schema_name="$SELECTED_SCHEMA"
read -p "Enter NEW Company Name: " new_compny_name
if [[ -z "$user_key" || -z "$schema_name" || -z "$new_compny_name" ]]; then
if [[ -z "$GLOBAL_USER_KEY" || -z "$schema_name" || -z "$new_compny_name" ]]; then
echo -e "\033[31m[❌] Error: Key, Schema Name, and New Company Name are required.\033[0m"
return
fi
@@ -296,12 +302,12 @@ do_rename_db() {
# Update CINF
echo " -> Updating CINF table..."
local q_cinf="UPDATE \"${schema_name}\".CINF SET \"CompnyName\" = '${new_compny_name}';"
execute_sql "$user_key" "$q_cinf" > /dev/null
execute_sql "$GLOBAL_USER_KEY" "$q_cinf" > /dev/null
# Update OADM
echo " -> Updating OADM table..."
local q_oadm="UPDATE \"${schema_name}\".OADM SET \"CompnyName\" = '${new_compny_name}', \"PrintHeadr\" = '${new_compny_name}';"
execute_sql "$user_key" "$q_oadm" > /dev/null
execute_sql "$GLOBAL_USER_KEY" "$q_oadm" > /dev/null
echo -e "\033[32m[✅] Database renamed successfully.\033[0m"
}
@@ -310,6 +316,16 @@ do_rename_db() {
check_hdbsql
echo
echo "========================================================"
echo " HANA Database Manager Init "
echo "========================================================"
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
while true; do
echo
echo "========================================================"
+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["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["hanamgr"]="HANA Manager UI|1.2.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.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"