update hanamgr
This commit is contained in:
+67
-4
@@ -1,5 +1,5 @@
|
||||
#!/bin/bash
|
||||
# Version: 1.0.0
|
||||
# Version: 1.1.0
|
||||
# Author: Tomi Eckert
|
||||
# ==============================================================================
|
||||
# HANA Database Manager Menu (hanamgr.sh)
|
||||
@@ -45,12 +45,73 @@ execute_sql() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to interactively select a schema from the database
|
||||
# Sets the global variable SELECTED_SCHEMA
|
||||
select_schema() {
|
||||
local user_key="$1"
|
||||
SELECTED_SCHEMA=""
|
||||
|
||||
echo "[🔎] Fetching available schemas..."
|
||||
local query="SELECT SCHEMA_NAME FROM SCHEMAS WHERE SCHEMA_OWNER = 'SYSTEM' AND SCHEMA_NAME NOT IN ('_SYS_SECURITY', 'IFSERV', 'B1if', 'SYSTEM', 'RSP');"
|
||||
|
||||
local raw_output
|
||||
raw_output=$("$HDBSQL_CMD" -U "$user_key" "$query" 2>/dev/null)
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo -e "\033[31m[❌] Error: Failed to fetch schemas. Check your HDBUSERSTORE key.\033[0m"
|
||||
# Fallback to manual entry
|
||||
read -p "Enter Schema Name manually: " SELECTED_SCHEMA
|
||||
return 1
|
||||
fi
|
||||
|
||||
local schemas=()
|
||||
while IFS= read -r line; do
|
||||
if [[ -z "$line" || "$line" == SCHEMA_NAME* || "$line" == *"rows selected"* || "$line" == *"row selected"* || "$line" == *"overall time"* || "$line" == -* ]]; then
|
||||
continue
|
||||
fi
|
||||
local clean_name
|
||||
clean_name=$(echo "$line" | tr -d '"' | xargs)
|
||||
if [[ -n "$clean_name" ]]; then
|
||||
schemas+=("$clean_name")
|
||||
fi
|
||||
done <<< "$raw_output"
|
||||
|
||||
if [ ${#schemas[@]} -eq 0 ]; then
|
||||
echo -e "\033[33m[⚠️] No eligible schemas found in the database.\033[0m"
|
||||
# Fallback to manual
|
||||
read -p "Enter Schema Name manually: " SELECTED_SCHEMA
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo -e "\n\033[1mAvailable Schemas:\033[0m"
|
||||
for i in "${!schemas[@]}"; do
|
||||
echo "$((i+1))) ${schemas[$i]}"
|
||||
fi
|
||||
echo "0) Enter manually"
|
||||
echo
|
||||
|
||||
local choice
|
||||
while true; do
|
||||
read -p "Select a schema (0-${#schemas[@]}): " choice
|
||||
if [[ "$choice" == "0" ]]; then
|
||||
read -p "Enter Schema Name manually: " SELECTED_SCHEMA
|
||||
break
|
||||
elif [[ "$choice" =~ ^[0-9]+$ ]] && [ "$choice" -ge 1 ] && [ "$choice" -le "${#schemas[@]}" ]; then
|
||||
SELECTED_SCHEMA="${schemas[$((choice-1))]}"
|
||||
break
|
||||
else
|
||||
echo -e "\033[31m[❌] Invalid selection. Please try again.\033[0m"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# --- Operation Functions ---
|
||||
|
||||
do_export() {
|
||||
echo -e "\n\033[1m=== Export Schema ===\033[0m"
|
||||
read -p "Enter HDBUSERSTORE Key: " user_key
|
||||
read -p "Enter Schema Name to export: " schema_name
|
||||
select_schema "$user_key"
|
||||
local schema_name="$SELECTED_SCHEMA"
|
||||
read -p "Enter Target Directory Path: " target_path
|
||||
read -p "Number of threads (default: 1): " threads
|
||||
threads=${threads:-1}
|
||||
@@ -182,7 +243,8 @@ do_import() {
|
||||
do_drop() {
|
||||
echo -e "\n\033[1m=== Drop Schema ===\033[0m"
|
||||
read -p "Enter HDBUSERSTORE Key: " user_key
|
||||
read -p "Enter Schema Name to DROP: " schema_name
|
||||
select_schema "$user_key"
|
||||
local schema_name="$SELECTED_SCHEMA"
|
||||
|
||||
if [[ -z "$user_key" || -z "$schema_name" ]]; then
|
||||
echo -e "\033[31m[❌] Error: Key and Schema Name are required.\033[0m"
|
||||
@@ -208,7 +270,8 @@ do_drop() {
|
||||
do_rename_db() {
|
||||
echo -e "\n\033[1m=== Rename Database (Company Name) ===\033[0m"
|
||||
read -p "Enter HDBUSERSTORE Key: " user_key
|
||||
read -p "Enter Schema Name to update: " schema_name
|
||||
select_schema "$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
|
||||
|
||||
Reference in New Issue
Block a user