remove emoji bullshit from hanamgr
This commit is contained in:
+52
-52
@@ -23,7 +23,7 @@ print_separator() {
|
||||
# Function to check if hdbsql is available
|
||||
check_hdbsql() {
|
||||
if ! command -v "$HDBSQL_CMD" &> /dev/null; then
|
||||
echo -e "\033[31m[❌] Error: '$HDBSQL_CMD' command not found. Ensure it is in your PATH.\033[0m"
|
||||
echo -e "\033[31m[ERROR] '$HDBSQL_CMD' command not found. Ensure it is in your PATH.\033[0m"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
@@ -58,7 +58,7 @@ select_schema() {
|
||||
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"
|
||||
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
|
||||
@@ -77,7 +77,7 @@ select_schema() {
|
||||
done <<< "$raw_output"
|
||||
|
||||
if [ ${#schemas[@]} -eq 0 ]; then
|
||||
echo -e "\033[33m[⚠️] No eligible schemas found in the database.\033[0m"
|
||||
echo -e "\033[33m[WARN] No eligible schemas found in the database.\033[0m"
|
||||
# Fallback to manual
|
||||
read -p "Enter Schema Name manually: " SELECTED_SCHEMA
|
||||
return 0
|
||||
@@ -100,7 +100,7 @@ select_schema() {
|
||||
SELECTED_SCHEMA="${schemas[$((choice-1))]}"
|
||||
break
|
||||
else
|
||||
echo -e "\033[31m[❌] Invalid selection. Please try again.\033[0m"
|
||||
echo -e "\033[31m[ERROR] Invalid selection. Please try again.\033[0m"
|
||||
fi
|
||||
done
|
||||
}
|
||||
@@ -123,11 +123,11 @@ do_export() {
|
||||
read -p "Compress output as tar.gz? (y/N): " compress
|
||||
|
||||
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"
|
||||
echo -e "\033[31m[ERROR] Key, Schema, and Path are required.\033[0m"
|
||||
return
|
||||
fi
|
||||
|
||||
echo -e "\n[⬇️] Starting export of schema '${schema_name}'..."
|
||||
echo -e "\n- Starting export of schema '${schema_name}'..."
|
||||
local export_dir="$target_path"
|
||||
local archive_file=""
|
||||
|
||||
@@ -143,7 +143,7 @@ do_export() {
|
||||
mkdir -p "$target_path"
|
||||
export_dir=$(mktemp -d "${target_path}/export_${schema_name}_XXXXXXXX")
|
||||
fi
|
||||
echo "[ℹ️] Using temporary export directory: ${export_dir}"
|
||||
echo "- Using temporary export directory: ${export_dir}"
|
||||
else
|
||||
mkdir -p "$export_dir"
|
||||
fi
|
||||
@@ -151,10 +151,10 @@ do_export() {
|
||||
local query="EXPORT \"${schema_name}\".\"*\" AS BINARY INTO '${export_dir}' WITH REPLACE THREADS ${threads} NO DEPENDENCIES;"
|
||||
|
||||
if execute_sql "$GLOBAL_USER_KEY" "$query"; then
|
||||
echo -e "\033[32m[✅] Successfully exported schema '${schema_name}'.\033[0m"
|
||||
echo -e "\033[32m[DONE] Successfully exported schema '${schema_name}'.\033[0m"
|
||||
|
||||
if [[ "$compress" =~ ^[Yy]$ ]]; then
|
||||
echo "[📦] Compressing export to ${archive_file}..."
|
||||
echo "- Compressing export to ${archive_file}..."
|
||||
|
||||
if command -v pigz &> /dev/null; then
|
||||
tar -I "pigz -p $threads" -cf "$archive_file" -C "$(dirname "$export_dir")" "$(basename "$export_dir")"
|
||||
@@ -163,14 +163,14 @@ do_export() {
|
||||
fi
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo -e "\033[32m[✅] Compression successful.\033[0m"
|
||||
echo -e "\033[32m[DONE] Compression successful.\033[0m"
|
||||
rm -rf "$export_dir"
|
||||
else
|
||||
echo -e "\033[31m[❌] Error: Compression failed.\033[0m"
|
||||
echo -e "\033[31m[ERROR] Compression failed.\033[0m"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
echo -e "\033[31m[❌] Error: Export failed.\033[0m"
|
||||
echo -e "\033[31m[ERROR] Export failed.\033[0m"
|
||||
if [[ "$compress" =~ ^[Yy]$ ]]; then rm -rf "$export_dir"; fi
|
||||
fi
|
||||
}
|
||||
@@ -190,7 +190,7 @@ do_import() {
|
||||
if [[ "$rename_mode" == "true" ]]; then
|
||||
read -p "Enter NEW Target Schema Name: " new_schema_name
|
||||
if [[ -z "$new_schema_name" ]]; then
|
||||
echo -e "\033[31m[❌] Error: New Schema Name is required for renaming.\033[0m"
|
||||
echo -e "\033[31m[ERROR] New Schema Name is required for renaming.\033[0m"
|
||||
return
|
||||
fi
|
||||
fi
|
||||
@@ -207,11 +207,11 @@ do_import() {
|
||||
read -p "Replace existing objects? (y/N): " replace_opt
|
||||
|
||||
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"
|
||||
echo -e "\033[31m[ERROR] Key, Schema, and Path are required.\033[0m"
|
||||
return
|
||||
fi
|
||||
|
||||
echo -e "\n[⬆️] Starting schema import..."
|
||||
echo -e "\n- Starting schema import..."
|
||||
local import_dir="$source_path"
|
||||
local cleanup_temp=false
|
||||
|
||||
@@ -219,7 +219,7 @@ do_import() {
|
||||
if [[ -f "$source_path" && "$source_path" == *.tar.gz ]]; then
|
||||
import_dir=$(mktemp -d "/tmp/import_${schema_name}_XXXXXXXX")
|
||||
cleanup_temp=true
|
||||
echo "[ℹ️] Decompressing archive to ${import_dir}..."
|
||||
echo "- Decompressing archive to ${import_dir}..."
|
||||
|
||||
if command -v pigz &> /dev/null; then
|
||||
tar -I "pigz -p $threads" -xf "$source_path" -C "$import_dir" --strip-components=1
|
||||
@@ -228,12 +228,12 @@ do_import() {
|
||||
fi
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo -e "\033[31m[❌] Error: Failed to decompress archive.\033[0m"
|
||||
echo -e "\033[31m[ERROR] Failed to decompress archive.\033[0m"
|
||||
rm -rf "$import_dir"
|
||||
return
|
||||
fi
|
||||
elif [[ ! -d "$import_dir" ]]; then
|
||||
echo -e "\033[31m[❌] Error: Path is neither a directory nor a valid .tar.gz archive.\033[0m"
|
||||
echo -e "\033[31m[ERROR] Path is neither a directory nor a valid .tar.gz archive.\033[0m"
|
||||
return
|
||||
fi
|
||||
|
||||
@@ -249,13 +249,13 @@ do_import() {
|
||||
local query="IMPORT \"${schema_name}\".\"*\" AS BINARY FROM '${import_dir}' WITH ${import_options} THREADS ${threads};"
|
||||
|
||||
if execute_sql "$GLOBAL_USER_KEY" "$query"; then
|
||||
echo -e "\033[32m[✅] Successfully imported schema.\033[0m"
|
||||
echo -e "\033[32m[DONE] Successfully imported schema.\033[0m"
|
||||
else
|
||||
echo -e "\033[31m[❌] Error: Import failed.\033[0m"
|
||||
echo -e "\033[31m[ERROR] Import failed.\033[0m"
|
||||
fi
|
||||
|
||||
if [[ "$cleanup_temp" == "true" ]]; then
|
||||
echo "[🧹] Cleaning up temporary files..."
|
||||
echo "- Cleaning up temporary files..."
|
||||
rm -rf "$import_dir"
|
||||
fi
|
||||
}
|
||||
@@ -266,23 +266,23 @@ do_drop() {
|
||||
local schema_name="$SELECTED_SCHEMA"
|
||||
|
||||
if [[ -z "$GLOBAL_USER_KEY" || -z "$schema_name" ]]; then
|
||||
echo -e "\033[31m[❌] Error: Key and Schema Name are required.\033[0m"
|
||||
echo -e "\033[31m[ERROR] Key and Schema Name are required.\033[0m"
|
||||
return
|
||||
fi
|
||||
|
||||
echo -e "\033[31m[⚠️] WARNING: You are about to completely drop the schema '${schema_name}'.\033[0m"
|
||||
echo -e "\033[31m[WARN] You are about to completely drop the schema '${schema_name}'.\033[0m"
|
||||
read -p "Are you absolutely sure? Type 'YES' to confirm: " confirm
|
||||
|
||||
if [[ "$confirm" == "YES" ]]; then
|
||||
echo "[🗑️] Dropping schema '${schema_name}'..."
|
||||
echo "- Dropping schema '${schema_name}'..."
|
||||
local query="DROP SCHEMA \"${schema_name}\" CASCADE"
|
||||
if execute_sql "$GLOBAL_USER_KEY" "$query"; then
|
||||
echo -e "\033[32m[✅] Schema successfully dropped.\033[0m"
|
||||
echo -e "\033[32m[DONE] Schema successfully dropped.\033[0m"
|
||||
else
|
||||
echo -e "\033[31m[❌] Error: Failed to drop schema.\033[0m"
|
||||
echo -e "\033[31m[ERROR] Failed to drop schema.\033[0m"
|
||||
fi
|
||||
else
|
||||
echo "[🤷] Operation cancelled."
|
||||
echo "- Operation cancelled."
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -292,7 +292,7 @@ do_copy() {
|
||||
local source_schema="$SELECTED_SCHEMA"
|
||||
|
||||
if [[ -z "$source_schema" ]]; then
|
||||
echo -e "\033[31m[❌] Error: Source Schema is required.\033[0m"
|
||||
echo -e "\033[31m[ERROR] Source Schema is required.\033[0m"
|
||||
return
|
||||
fi
|
||||
|
||||
@@ -309,27 +309,27 @@ do_copy() {
|
||||
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"
|
||||
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}'..."
|
||||
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}"
|
||||
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"
|
||||
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"
|
||||
echo -e "\033[32m[DONE] Export phase completed successfully.\033[0m"
|
||||
|
||||
# 2. Import-Rename
|
||||
echo -e "\n[⬆️] Step 2/2: Importing and renaming to '${target_schema}'..."
|
||||
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"
|
||||
@@ -339,13 +339,13 @@ do_copy() {
|
||||
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"
|
||||
echo -e "\033[32m[DONE] Successfully copied schema '${source_schema}' to '${target_schema}'.\033[0m"
|
||||
else
|
||||
echo -e "\033[31m[❌] Error: Import phase failed.\033[0m"
|
||||
echo -e "\033[31m[ERROR] Import phase failed.\033[0m"
|
||||
fi
|
||||
|
||||
# Cleanup
|
||||
echo "[🧹] Cleaning up temporary files..."
|
||||
echo "- Cleaning up temporary files..."
|
||||
rm -rf "$temp_export_dir"
|
||||
}
|
||||
|
||||
@@ -363,7 +363,7 @@ do_backup() {
|
||||
read -p "Compress output as tar.gz? (y/N): " compress
|
||||
|
||||
if [[ -z "$GLOBAL_USER_KEY" || -z "$target_path" ]]; then
|
||||
echo -e "\033[31m[❌] Error: Key and Path are required.\033[0m"
|
||||
echo -e "\033[31m[ERROR] Key and Path are required.\033[0m"
|
||||
return
|
||||
fi
|
||||
|
||||
@@ -373,7 +373,7 @@ do_backup() {
|
||||
tenant_name=$("$HDBSQL_CMD" -U "$GLOBAL_USER_KEY" "$tenant_query" 2>/dev/null | tail -n +2 | head -n 1 | tr -d '[:space:]' | tr -d '"')
|
||||
|
||||
if [[ -z "$tenant_name" ]]; then
|
||||
echo -e "\033[31m[❌] Error: Could not retrieve HANA tenant name.\033[0m"
|
||||
echo -e "\033[31m[ERROR] Could not retrieve HANA tenant name.\033[0m"
|
||||
return
|
||||
fi
|
||||
|
||||
@@ -384,20 +384,20 @@ do_backup() {
|
||||
if [[ "$compress" =~ ^[Yy]$ ]]; then
|
||||
backup_target_dir=$(mktemp -d "${target_path}/${tenant_name}_backup_${timestamp}_XXXXXXXX")
|
||||
archive_file="${target_path}/${tenant_name}_backup_${timestamp}.tar.gz"
|
||||
echo "[ℹ️] Using temporary backup directory: ${backup_target_dir}"
|
||||
echo "- Using temporary backup directory: ${backup_target_dir}"
|
||||
fi
|
||||
|
||||
mkdir -p "$backup_target_dir"
|
||||
local backup_path_prefix="${backup_target_dir}/backup_${tenant_name}_${timestamp}"
|
||||
|
||||
echo -e "\n[💾] Starting backup of tenant '${tenant_name}'..."
|
||||
echo -e "\n- Starting backup of tenant '${tenant_name}'..."
|
||||
local query="BACKUP DATA USING FILE ('${backup_path_prefix}')"
|
||||
|
||||
if execute_sql "$GLOBAL_USER_KEY" "$query"; then
|
||||
echo -e "\033[32m[✅] Successfully initiated tenant backup.\033[0m"
|
||||
echo -e "\033[32m[DONE] Successfully initiated tenant backup.\033[0m"
|
||||
|
||||
if [[ "$compress" =~ ^[Yy]$ ]]; then
|
||||
echo "[📦] Compressing backup to ${archive_file}..."
|
||||
echo "- Compressing backup to ${archive_file}..."
|
||||
|
||||
if command -v pigz &> /dev/null; then
|
||||
tar -I "pigz -p $threads" -cf "$archive_file" -C "$backup_target_dir" .
|
||||
@@ -406,14 +406,14 @@ do_backup() {
|
||||
fi
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo -e "\033[32m[✅] Compression successful.\033[0m"
|
||||
echo -e "\033[32m[DONE] Compression successful.\033[0m"
|
||||
rm -rf "$backup_target_dir"
|
||||
else
|
||||
echo -e "\033[31m[❌] Error: Compression failed.\033[0m"
|
||||
echo -e "\033[31m[ERROR] Compression failed.\033[0m"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
echo -e "\033[31m[❌] Error: Backup failed.\033[0m"
|
||||
echo -e "\033[31m[ERROR] Backup failed.\033[0m"
|
||||
if [[ "$compress" =~ ^[Yy]$ ]]; then rm -rf "$backup_target_dir"; fi
|
||||
fi
|
||||
}
|
||||
@@ -425,11 +425,11 @@ do_rename_db() {
|
||||
read -p "Enter NEW Company Name: " new_compny_name
|
||||
|
||||
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"
|
||||
echo -e "\033[31m[ERROR] Key, Schema Name, and New Company Name are required.\033[0m"
|
||||
return
|
||||
fi
|
||||
|
||||
echo -e "\n[✍️] Updating company name for '${schema_name}' to '${new_compny_name}'..."
|
||||
echo -e "\n- Updating company name for '${schema_name}' to '${new_compny_name}'..."
|
||||
|
||||
# Update CINF
|
||||
echo " -> Updating CINF table..."
|
||||
@@ -441,7 +441,7 @@ do_rename_db() {
|
||||
local q_oadm="UPDATE \"${schema_name}\".OADM SET \"CompnyName\" = '${new_compny_name}', \"PrintHeadr\" = '${new_compny_name}';"
|
||||
execute_sql "$GLOBAL_USER_KEY" "$q_oadm" > /dev/null
|
||||
|
||||
echo -e "\033[32m[✅] Database renamed successfully.\033[0m"
|
||||
echo -e "\033[32m[DONE] Database renamed successfully.\033[0m"
|
||||
}
|
||||
|
||||
# --- Main Menu Loop ---
|
||||
@@ -454,7 +454,7 @@ 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"
|
||||
echo -e "\033[31m[ERROR] Key is required.\033[0m"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -497,11 +497,11 @@ while true; do
|
||||
do_backup
|
||||
;;
|
||||
8)
|
||||
echo "[👋] Exiting."
|
||||
echo "Exiting."
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo -e "\033[31m[⚠️] Invalid option. Please try again.\033[0m"
|
||||
echo -e "\033[31m[WARN] Invalid option. Please try again.\033[0m"
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
Reference in New Issue
Block a user