update backup, add systemdb backup
This commit is contained in:
@@ -11,6 +11,9 @@ HDBSQL_PATH="/usr/sap/hdbclient/hdbsql"
|
|||||||
# This key should be configured to connect to the target tenant database.
|
# This key should be configured to connect to the target tenant database.
|
||||||
USER_KEY="CRONKEY"
|
USER_KEY="CRONKEY"
|
||||||
|
|
||||||
|
# hdbuserstore key for the SYSTEMDB user
|
||||||
|
SYSTEMDB_USER_KEY="SYSTEMDB_KEY"
|
||||||
|
|
||||||
# --- Backup Settings ---
|
# --- Backup Settings ---
|
||||||
|
|
||||||
# The base directory where all backup files and directories will be stored.
|
# The base directory where all backup files and directories will be stored.
|
||||||
@@ -25,6 +28,9 @@ BACKUP_BASE_DIR="/hana/backups/automated"
|
|||||||
# 'all' - Performs both the schema export and the tenant backup.
|
# 'all' - Performs both the schema export and the tenant backup.
|
||||||
BACKUP_TYPE="all"
|
BACKUP_TYPE="all"
|
||||||
|
|
||||||
|
# Set to 'true' to also perform a backup of the SYSTEMDB
|
||||||
|
BACKUP_SYSTEMDB=true
|
||||||
|
|
||||||
# Schema can be compressed after exporting, decreasing it's size.
|
# Schema can be compressed after exporting, decreasing it's size.
|
||||||
COMPRESS_SCHEMA=true
|
COMPRESS_SCHEMA=true
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Version: 1.0.0
|
# Version: 1.0.5
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
# SAP HANA Backup Script
|
# SAP HANA Backup Script
|
||||||
#
|
#
|
||||||
@@ -52,7 +52,7 @@ perform_schema_export() {
|
|||||||
timestamp=$(date +%Y%m%d_%H%M%S)
|
timestamp=$(date +%Y%m%d_%H%M%S)
|
||||||
local export_base_dir="${BACKUP_BASE_DIR}/schema"
|
local export_base_dir="${BACKUP_BASE_DIR}/schema"
|
||||||
local export_path="${export_base_dir}/${schema_name}_${timestamp}"
|
local export_path="${export_base_dir}/${schema_name}_${timestamp}"
|
||||||
local query_export_path="$export_path" # Default path for the EXPORT query
|
local query_export_path="$export_path"
|
||||||
|
|
||||||
if [[ "$COMPRESS_SCHEMA" == "true" ]]; then
|
if [[ "$COMPRESS_SCHEMA" == "true" ]]; then
|
||||||
export_path="${export_base_dir}/tmp/${schema_name}_${timestamp}"
|
export_path="${export_base_dir}/tmp/${schema_name}_${timestamp}"
|
||||||
@@ -94,7 +94,7 @@ perform_schema_export() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# NEW: Loops through the schemas in the config file and runs an export for each.
|
# Loops through the schemas in the config file and runs an export for each.
|
||||||
run_all_schema_exports() {
|
run_all_schema_exports() {
|
||||||
if [[ -z "$SCHEMA_NAMES" ]]; then
|
if [[ -z "$SCHEMA_NAMES" ]]; then
|
||||||
echo " ⚠️ Warning: SCHEMA_NAMES variable is not set in config. Skipping schema export."
|
echo " ⚠️ Warning: SCHEMA_NAMES variable is not set in config. Skipping schema export."
|
||||||
@@ -108,17 +108,22 @@ run_all_schema_exports() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
# Performs a full backup of the tenant database.
|
# REFACTORED: Generic function to back up any database (Tenant or SYSTEMDB).
|
||||||
perform_tenant_backup() {
|
# Arguments: 1:Backup Name (for logging), 2:User Key, 3:Base Directory, 4:Compression Flag
|
||||||
echo "⬇️ Starting tenant backup..."
|
perform_database_backup() {
|
||||||
|
local backup_name="$1"
|
||||||
|
local user_key="$2"
|
||||||
|
local backup_base_dir="$3"
|
||||||
|
local compress_enabled="$4"
|
||||||
|
|
||||||
|
echo "⬇️ Starting ${backup_name} backup..."
|
||||||
|
|
||||||
local timestamp
|
local timestamp
|
||||||
timestamp=$(date +%Y%m%d_%H%M%S)
|
timestamp=$(date +%Y%m%d_%H%M%S)
|
||||||
local backup_base_dir="${BACKUP_BASE_DIR}/tenant"
|
|
||||||
local backup_path_prefix
|
local backup_path_prefix
|
||||||
local backup_target_dir
|
local backup_target_dir
|
||||||
|
|
||||||
if [[ "$COMPRESS_TENANT" == "true" ]]; then
|
if [[ "$compress_enabled" == "true" ]]; then
|
||||||
backup_target_dir="${backup_base_dir}/tmp"
|
backup_target_dir="${backup_base_dir}/tmp"
|
||||||
backup_path_prefix="${backup_target_dir}/backup_${timestamp}"
|
backup_path_prefix="${backup_target_dir}/backup_${timestamp}"
|
||||||
echo " ℹ️ Compression enabled. Using temporary backup path: ${backup_path_prefix}"
|
echo " ℹ️ Compression enabled. Using temporary backup path: ${backup_path_prefix}"
|
||||||
@@ -131,13 +136,13 @@ perform_tenant_backup() {
|
|||||||
|
|
||||||
local query="BACKUP DATA USING FILE ('${backup_path_prefix}')"
|
local query="BACKUP DATA USING FILE ('${backup_path_prefix}')"
|
||||||
|
|
||||||
"$HDBSQL_PATH" -U "$USER_KEY" "$query" > /dev/null 2>&1
|
"$HDBSQL_PATH" -U "$user_key" "$query" > /dev/null 2>&1
|
||||||
local exit_code=$?
|
local exit_code=$?
|
||||||
|
|
||||||
if [[ "$exit_code" -eq 0 ]]; then
|
if [[ "$exit_code" -eq 0 ]]; then
|
||||||
echo " ✅ Successfully initiated tenant backup with prefix '${backup_path_prefix}'."
|
echo " ✅ Successfully initiated ${backup_name} backup with prefix '${backup_path_prefix}'."
|
||||||
|
|
||||||
if [[ "$COMPRESS_TENANT" == "true" ]]; then
|
if [[ "$compress_enabled" == "true" ]]; then
|
||||||
local archive_file="${backup_base_dir}/backup_${timestamp}.tar.gz"
|
local archive_file="${backup_base_dir}/backup_${timestamp}.tar.gz"
|
||||||
echo " 🗜️ Compressing backup files..."
|
echo " 🗜️ Compressing backup files..."
|
||||||
tar -czf "$archive_file" -C "$backup_target_dir" .
|
tar -czf "$archive_file" -C "$backup_target_dir" .
|
||||||
@@ -153,7 +158,7 @@ perform_tenant_backup() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo " ❌ Error: Failed to initiate tenant backup (hdbsql exit code: ${exit_code})."
|
echo " ❌ Error: Failed to initiate ${backup_name} backup (hdbsql exit code: ${exit_code})."
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,16 +173,28 @@ case "$BACKUP_TYPE" in
|
|||||||
run_all_schema_exports
|
run_all_schema_exports
|
||||||
;;
|
;;
|
||||||
tenant)
|
tenant)
|
||||||
perform_tenant_backup
|
perform_database_backup "Tenant" "$USER_KEY" "${BACKUP_BASE_DIR}/tenant" "$COMPRESS_TENANT"
|
||||||
;;
|
;;
|
||||||
all)
|
all)
|
||||||
run_all_schema_exports
|
run_all_schema_exports
|
||||||
perform_tenant_backup
|
perform_database_backup "Tenant" "$USER_KEY" "${BACKUP_BASE_DIR}/tenant" "$COMPRESS_TENANT"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo " ❌ Error: Invalid BACKUP_TYPE '${BACKUP_TYPE}' in config. Use 'schema', 'tenant', or 'all'."
|
echo " ❌ Error: Invalid BACKUP_TYPE '${BACKUP_TYPE}' in config. Use 'schema', 'tenant', or 'all'."
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
# NEW: Check if SYSTEMDB backup is enabled, regardless of BACKUP_TYPE (as long as it's not 'schema' only)
|
||||||
|
if [[ "$BACKUP_TYPE" == "tenant" || "$BACKUP_TYPE" == "all" ]]; then
|
||||||
|
if [[ "$BACKUP_SYSTEMDB" == "true" ]]; then
|
||||||
|
echo "--------------------------------------------------"
|
||||||
|
if [[ -z "$SYSTEMDB_USER_KEY" ]]; then
|
||||||
|
echo " ❌ Error: BACKUP_SYSTEMDB is true, but SYSTEMDB_USER_KEY is not set in config."
|
||||||
|
else
|
||||||
|
perform_database_backup "SYSTEMDB" "$SYSTEMDB_USER_KEY" "${BACKUP_BASE_DIR}/systemdb" "$COMPRESS_TENANT"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
echo "📦 Backup process complete."
|
echo "📦 Backup process complete."
|
||||||
echo "👋 Exiting."
|
echo "👋 Exiting."
|
||||||
@@ -8,7 +8,7 @@ declare -A SCRIPT_PACKAGES
|
|||||||
|
|
||||||
# The version should match the "# Version: x.x.x" line in the main script file.
|
# The version should match the "# Version: x.x.x" line in the main script file.
|
||||||
SCRIPT_PACKAGES["Aurora Suite"]="1.1.0|https://git.technopunk.space/tomi/Scripts/raw/branch/main/aurora/aurora.sh https://git.technopunk.space/tomi/Scripts/raw/branch/main/aurora/aurora.conf"
|
SCRIPT_PACKAGES["Aurora Suite"]="1.1.0|https://git.technopunk.space/tomi/Scripts/raw/branch/main/aurora/aurora.sh https://git.technopunk.space/tomi/Scripts/raw/branch/main/aurora/aurora.conf"
|
||||||
SCRIPT_PACKAGES["Backup Suite"]="1.0.0|https://git.technopunk.space/tomi/Scripts/raw/branch/main/backup/backup.sh https://git.technopunk.space/tomi/Scripts/raw/branch/main/backup/backup.conf"
|
SCRIPT_PACKAGES["Backup Suite"]="1.0.5|https://git.technopunk.space/tomi/Scripts/raw/branch/main/backup/backup.sh https://git.technopunk.space/tomi/Scripts/raw/branch/main/backup/backup.conf"
|
||||||
SCRIPT_PACKAGES["Key Manager"]="1.2.1|https://git.technopunk.space/tomi/Scripts/raw/branch/main/hdb_keymanager.sh"
|
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["File Cleaner"]="1.1.0|https://git.technopunk.space/tomi/Scripts/raw/branch/main/clean.sh"
|
||||||
SCRIPT_PACKAGES["HANA Tool"]="1.0.4|https://git.technopunk.space/tomi/Scripts/raw/branch/main/hanatool.sh"
|
SCRIPT_PACKAGES["HANA Tool"]="1.0.4|https://git.technopunk.space/tomi/Scripts/raw/branch/main/hanatool.sh"
|
||||||
|
|||||||
Reference in New Issue
Block a user