Compare commits

..

3 Commits

Author SHA1 Message Date
f9a5cb3ec3 chore: bump versions 2026-01-19 11:28:50 +01:00
2c4c03e604 feat(backup): added thread to config 2026-01-19 11:28:33 +01:00
5579fc852f feat(aurora): uses hanatool 2026-01-19 11:28:10 +01:00
7 changed files with 83 additions and 50 deletions

View File

@@ -31,6 +31,9 @@ HDBSQL="/usr/sap/NDB/HDB00/exe/hdbsql"
# The root directory where post-import SQL scripts are located. # The root directory where post-import SQL scripts are located.
SQL_SCRIPTS_ROOT="/usr/sap/NDB/home/tools/sql" SQL_SCRIPTS_ROOT="/usr/sap/NDB/home/tools/sql"
# Number of threads to use for schema export and import.
THREADS=1
# --- Post-Import Scripts (Optional) --- # --- Post-Import Scripts (Optional) ---
# A space-separated list of SQL script filenames to run after the import is complete. # A space-separated list of SQL script filenames to run after the import is complete.

22
aurora/aurora.hook.sh Normal file
View File

@@ -0,0 +1,22 @@
#!/bin/bash
# Author: Tomi Eckert
# This script helps to configure aurora.conf
# Source the aurora.conf to get current values
source aurora.conf
HDBSQL_PATH_INPUT=$(which hdbsql)
# Default values if not found
HDBSQL_PATH_INPUT=${HDBSQL_PATH_INPUT:-"/usr/sap/hdbclient/hdbsql"}
# Calculate default threads (half of available)
TOTAL_THREADS=$(nproc --all)
THREADS_DEFAULT=$((TOTAL_THREADS / 2))
# Update aurora.conf
sed -i "s#^HDBSQL_PATH=\".*\"#HDBSQL_PATH=\"$HDBSQL_PATH_INPUT\"#" aurora.conf
sed -i "s#^THREADS=.\"*\"#THREADS=\"$THREADS_DEFAULT\"#" aurora.conf
echo "aurora.conf updated successfully!"

View File

@@ -1,50 +1,41 @@
#!/bin/sh #!/bin/bash
# Version: 2.1.0 # Version: 2.5.0
# Author: Tomi Eckert # Author: Tomi Eckert
# ==============================================================================
# Aurora Refresh Script
# #
# Purpose: Performs an automated refresh of a SAP HANA schema. It exports a # Performs an automated refresh of a SAP HANA schema using hanatool.sh.
# production schema and re-imports it under a new name ("Aurora") # It exports a production schema and re-imports it under a new name ("Aurora")
# to create an up-to-date, non-production environment for testing. # to create an up-to-date, non-production environment for testing.
# Designed to be run via cron, typically in the early morning. # ==============================================================================
#
# -----------------------------------------------------------------------------
# --- Basic Setup --- # --- Configuration and Setup ---
# Exit immediately if any command fails or if an unset variable is used.
set -eu
# --- Configuration --- # Find the script's own directory to locate the config file and hanatool.sh
# Load the configuration file located in the same directory as the script. SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)
SCRIPT_DIR=$(dirname "$0")
CONFIG_FILE="${SCRIPT_DIR}/aurora.conf" CONFIG_FILE="${SCRIPT_DIR}/aurora.conf"
HANATOOL_PATH="${SCRIPT_DIR}/../hanatool.sh"
if [ ! -f "$CONFIG_FILE" ]; then # Check for config file and source it
echo "❌ FATAL: Configuration file not found at '${CONFIG_FILE}'" >&2 if [[ -f "$CONFIG_FILE" ]]; then
exit 1 source "$CONFIG_FILE"
fi else
# shellcheck source=aurora.conf echo "❌ Error: Configuration file not found at '${CONFIG_FILE}'"
. "$CONFIG_FILE"
# --- Validate Configuration ---
if [ ! -x "$HDBSQL" ]; then
echo "❌ FATAL: hdbsql is not found or not executable at '${HDBSQL}'" >&2
exit 1 exit 1
fi fi
# --- Derived Variables (Do Not Edit) --- # Check if hanatool.sh executable exists
TIMESTAMP=$(date "+%Y-%m-%d %H:%M:%S") if [[ ! -x "$HANATOOL_PATH" ]]; then
echo "❌ Error: hanatool.sh not found or not executable at '${HANATOOL_PATH}'"
exit 1
fi
# --- Derived Variables ---
AURORA_SCHEMA="${SOURCE_SCHEMA}_AURORA" AURORA_SCHEMA="${SOURCE_SCHEMA}_AURORA"
EXPORT_DIR="${BACKUP_BASE_DIR}/${AURORA_SCHEMA}_TEMP_EXPORT" EXPORT_DIR="${BACKUP_BASE_DIR}/${AURORA_SCHEMA}_TEMP_EXPORT"
COMPANY_NAME_BASE=$(echo "${SOURCE_SCHEMA}" | sed 's/^SBO_//' | sed 's/_PROD$//')
# --- Main Execution --- # --- Main Execution ---
echo echo "🚀 Starting Aurora Refresh for '${SOURCE_SCHEMA}' using hanatool.sh..."
echo "🚀 [$(date "+%T")] Starting Aurora Refresh for '${SOURCE_SCHEMA}'"
echo "--------------------------------------------------------"
echo " Source Schema: ${SOURCE_SCHEMA}"
echo " Target Aurora Schema: ${AURORA_SCHEMA}"
echo " Temp Export Path: ${EXPORT_DIR}"
echo "--------------------------------------------------------"
# 1. Drop the old Aurora schema if it exists. # 1. Drop the old Aurora schema if it exists.
echo "🗑️ Dropping old schema '${AURORA_SCHEMA}' (if it exists)..." echo "🗑️ Dropping old schema '${AURORA_SCHEMA}' (if it exists)..."
@@ -55,21 +46,26 @@ echo "📁 Preparing temporary export directory..."
rm -rf "$EXPORT_DIR" rm -rf "$EXPORT_DIR"
mkdir -p "$EXPORT_DIR" mkdir -p "$EXPORT_DIR"
# 3. Export the source schema. # 3. Export the source schema using hanatool.sh
echo "⬇️ Exporting source schema '${SOURCE_SCHEMA}' to binary files..." echo "⬇️ Exporting source schema '${SOURCE_SCHEMA}'..."
"$HDBSQL" -U "$DB_ADMIN_KEY" "EXPORT \"${SOURCE_SCHEMA}\".\"*\" AS BINARY INTO '${EXPORT_DIR}' WITH REPLACE;" >/dev/null "$HANATOOL_PATH" "$DB_ADMIN_KEY" export "$SOURCE_SCHEMA" "$EXPORT_DIR" -t "$THREADS"
echo " -> Export complete." if [[ $? -ne 0 ]]; then
echo "❌ Error: Export failed."
exit 1
fi
# 4. Import the data into the new Aurora schema. # 4. Import the data into the new Aurora schema using hanatool.sh
echo "⬆️ Importing data and renaming schema to '${AURORA_SCHEMA}'..." echo "⬆️ Importing data and renaming schema to '${AURORA_SCHEMA}'..."
"$HDBSQL" -U "$DB_ADMIN_KEY" "IMPORT \"${SOURCE_SCHEMA}\".\"*\" FROM '${EXPORT_DIR}' WITH IGNORE EXISTING RENAME SCHEMA \"${SOURCE_SCHEMA}\" TO \"${AURORA_SCHEMA}\";" >/dev/null "$HANATOOL_PATH" "$DB_ADMIN_KEY" import-rename "$SOURCE_SCHEMA" "$AURORA_SCHEMA" "$EXPORT_DIR" -t "$THREADS"
echo " -> Import complete." if [[ $? -ne 0 ]]; then
echo "❌ Error: Import failed."
exit 1
fi
# 5. Update company name in CINF and OADM tables. # 5. Update company name in CINF and OADM tables.
echo "✍️ Updating company name fields in the new schema..." echo "✍️ Updating company name fields in the new schema..."
# First, get the original company name from the source schema. # First, get the original company name from the source schema.
# The query returns a header and the name in quotes. sed gets the second line, tr removes the quotes, xargs trims whitespace.
echo " -> Fetching original company name from '${SOURCE_SCHEMA}'..." echo " -> Fetching original company name from '${SOURCE_SCHEMA}'..."
ORIGINAL_COMPNY_NAME=$("$HDBSQL" -U "$DB_ADMIN_KEY" "SELECT \"CompnyName\" FROM \"${SOURCE_SCHEMA}\".\"CINF\"" | sed -n '2p' | tr -d '"' | xargs) ORIGINAL_COMPNY_NAME=$("$HDBSQL" -U "$DB_ADMIN_KEY" "SELECT \"CompnyName\" FROM \"${SOURCE_SCHEMA}\".\"CINF\"" | sed -n '2p' | tr -d '"' | xargs)
@@ -91,13 +87,11 @@ echo "🔑 Granting ALL privileges on '${AURORA_SCHEMA}' to '${AURORA_USER}'..."
echo " -> Privileges granted." echo " -> Privileges granted."
# 7. Run post-import SQL scripts, if any are defined. # 7. Run post-import SQL scripts, if any are defined.
if [ -n "$POST_IMPORT_SQL" ]; then if [[ -n "$POST_IMPORT_SQL" ]]; then
echo "⚙️ Running post-import SQL scripts..." echo "⚙️ Running post-import SQL scripts..."
# Use word splitting intentionally here
# shellcheck disable=SC2086
for sql_file in $POST_IMPORT_SQL; do for sql_file in $POST_IMPORT_SQL; do
full_path="${SQL_SCRIPTS_ROOT}/${sql_file}" full_path="${SQL_SCRIPTS_ROOT}/${sql_file}"
if [ -f "$full_path" ]; then if [[ -f "$full_path" ]]; then
echo " -> Executing: ${sql_file}" echo " -> Executing: ${sql_file}"
"$HDBSQL" -U "$DB_ADMIN_KEY" -I "$full_path" "$HDBSQL" -U "$DB_ADMIN_KEY" -I "$full_path"
else else
@@ -114,7 +108,7 @@ rm -rf "$EXPORT_DIR"
echo " -> Cleanup complete." echo " -> Cleanup complete."
echo "--------------------------------------------------------" echo "--------------------------------------------------------"
echo "✅ [$(date "+%T")] Aurora Refresh finished successfully!" echo " Aurora Refresh finished successfully!"
echo echo
exit 0 exit 0

View File

@@ -37,6 +37,9 @@ COMPRESS_SCHEMA=true
# for a 40GB tenant. # for a 40GB tenant.
COMPRESS_TENANT=true COMPRESS_TENANT=true
# Number of threads to use for schema export.
THREADS=1
# --- Target Identifiers --- # --- Target Identifiers ---
# The name of the schema to be exported when BACKUP_TYPE is 'schema' or 'all'. # The name of the schema to be exported when BACKUP_TYPE is 'schema' or 'all'.

View File

@@ -11,7 +11,12 @@ HDBSQL_PATH_INPUT=$(which hdbsql)
# Default values if not found # Default values if not found
HDBSQL_PATH_INPUT=${HDBSQL_PATH_INPUT:-"/usr/sap/hdbclient/hdbsql"} HDBSQL_PATH_INPUT=${HDBSQL_PATH_INPUT:-"/usr/sap/hdbclient/hdbsql"}
# Calculate default threads (half of available)
TOTAL_THREADS=$(nproc --all)
THREADS_DEFAULT=$((TOTAL_THREADS / 2))
# Update backup.conf # Update backup.conf
sed -i "s#^HDBSQL_PATH=\".*\"#HDBSQL_PATH=\"$HDBSQL_PATH_INPUT\"#" backup.conf sed -i "s#^HDBSQL_PATH=\".*\"#HDBSQL_PATH=\"$HDBSQL_PATH_INPUT\"#" backup.conf
sed -i "s#^THREADS=.\"*\"#THREADS=\"$THREADS_DEFAULT\"#" backup.conf
echo "backup.conf updated successfully!" echo "backup.conf updated successfully!"

View File

@@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
# Version: 1.0.8 # Version: 1.1.0
# Author: Tomi Eckert # Author: Tomi Eckert
# ============================================================================== # ==============================================================================
# SAP HANA Backup Script # SAP HANA Backup Script
@@ -47,6 +47,9 @@ case "$BACKUP_TYPE" in
for schema in $SCHEMA_NAMES; do for schema in $SCHEMA_NAMES; do
echo "⬇️ Starting schema export for '${schema}'..." echo "⬇️ Starting schema export for '${schema}'..."
SCHEMA_EXPORT_OPTIONS="$COMMON_OPTIONS" SCHEMA_EXPORT_OPTIONS="$COMMON_OPTIONS"
if [[ -n "$THREADS" ]]; then
SCHEMA_EXPORT_OPTIONS+=" -t $THREADS"
fi
if [[ "$COMPRESS_SCHEMA" == "true" ]]; then if [[ "$COMPRESS_SCHEMA" == "true" ]]; then
SCHEMA_EXPORT_OPTIONS+=" --compress" SCHEMA_EXPORT_OPTIONS+=" --compress"
fi fi
@@ -77,6 +80,9 @@ case "$BACKUP_TYPE" in
for schema in $SCHEMA_NAMES; do for schema in $SCHEMA_NAMES; do
echo "⬇️ Starting schema export for '${schema}'..." echo "⬇️ Starting schema export for '${schema}'..."
SCHEMA_EXPORT_OPTIONS="$COMMON_OPTIONS" SCHEMA_EXPORT_OPTIONS="$COMMON_OPTIONS"
if [[ -n "$THREADS" ]]; then
SCHEMA_EXPORT_OPTIONS+=" -t $THREADS"
fi
if [[ "$COMPRESS_SCHEMA" == "true" ]]; then if [[ "$COMPRESS_SCHEMA" == "true" ]]; then
SCHEMA_EXPORT_OPTIONS+=" --compress" SCHEMA_EXPORT_OPTIONS+=" --compress"
fi fi

View File

@@ -10,8 +10,8 @@
declare -A SCRIPT_PACKAGES declare -A SCRIPT_PACKAGES
# Format: short_name="Display Name|Version|Description|URL1 URL2..." # Format: short_name="Display Name|Version|Description|URL1 URL2..."
SCRIPT_PACKAGES["aurora"]="Aurora Suite|2.1.0|A collection of scripts for managing Aurora database instances.|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"]="Aurora Suite|2.5.0|A collection of scripts for managing Aurora database instances.|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"]="Backup Suite|1.0.8|A comprehensive script for backing up system files and databases.|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"]="Backup Suite|1.1.0|A comprehensive script for backing up system files and databases.|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["monitor"]="Monitor Suite|1.3.1|Scripts for monitoring system health and performance metrics.|https://git.technopunk.space/tomi/Scripts/raw/branch/main/monitor/monitor.sh https://git.technopunk.space/tomi/Scripts/raw/branch/main/monitor/monitor.conf|https://git.technopunk.space/tomi/Scripts/raw/branch/main/monitor/monitor.hook.sh" SCRIPT_PACKAGES["monitor"]="Monitor Suite|1.3.1|Scripts for monitoring system health and performance metrics.|https://git.technopunk.space/tomi/Scripts/raw/branch/main/monitor/monitor.sh https://git.technopunk.space/tomi/Scripts/raw/branch/main/monitor/monitor.conf|https://git.technopunk.space/tomi/Scripts/raw/branch/main/monitor/monitor.hook.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["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"