update aurora, make it more compact

This commit is contained in:
2025-09-24 19:48:10 +02:00
parent f0a9d2d75a
commit b018908f64
2 changed files with 34 additions and 49 deletions

View File

@@ -1,5 +1,5 @@
#!/bin/sh #!/bin/sh
# Version: 1.1.0 # Version: 1.2.0
# Exit immediately if a command exits with a non-zero status. # Exit immediately if a command exits with a non-zero status.
set -e set -e
@@ -9,7 +9,7 @@ SCRIPT_DIR=$(dirname "$0")
CONFIG_FILE="${SCRIPT_DIR}/aurora.conf" CONFIG_FILE="${SCRIPT_DIR}/aurora.conf"
if [ ! -f "$CONFIG_FILE" ]; then if [ ! -f "$CONFIG_FILE" ]; then
echo "Error: Configuration file not found at ${CONFIG_FILE}" echo "Error: Configuration file not found at ${CONFIG_FILE}" >&2
exit 1 exit 1
fi fi
# shellcheck source=aurora.conf # shellcheck source=aurora.conf
@@ -19,15 +19,13 @@ fi
TIMESTAMP=$(date "+%Y-%m-%d %H:%M:%S") TIMESTAMP=$(date "+%Y-%m-%d %H:%M:%S")
AURORA="${SCHEMA}_AURORA" AURORA="${SCHEMA}_AURORA"
AURORA_TEMP_DIR="${BACKUP_DIR}/${AURORA}" AURORA_TEMP_DIR="${BACKUP_DIR}/${AURORA}"
LOGFILE="${SCRIPT_ROOT}/aurora.log" COMPNYNAME="${SCHEMA#SBO_}"
temp_compnyname=${SCHEMA#SBO_} # Remove SBO_ prefix [[ "$COMPNYNAME" == *_PROD ]] && COMPNYNAME="${COMPNYNAME%_PROD}" # Remove _PROD suffix if it exists
COMPNYNAME=${temp_compnyname%_PROD} # Remove _PROD suffix if it exists
# === FUNCTIONS === # === FUNCTIONS ===
log() { echo "$(date +"%Y-%m-%d %H:%M:%S") - $1" | tee -a "$LOGFILE"; }
run_sql() { run_sql() {
log "Executing: $1" echo "Executing: $1"
"$HDBSQL" -U "${BACKOP_USER}" "$1" >/dev/null "$HDBSQL" -U "${BACKOP_USER}" "$1" >/dev/null
} }
@@ -37,86 +35,73 @@ show_info() {
echo "Target Schema User: ${AURORA_SCHEMA_USER}" echo "Target Schema User: ${AURORA_SCHEMA_USER}"
echo "Company Name: ${COMPNYNAME}" echo "Company Name: ${COMPNYNAME}"
echo "Export Directory: ${AURORA_TEMP_DIR}" echo "Export Directory: ${AURORA_TEMP_DIR}"
echo "Log File: ${LOGFILE}"
} }
usage() { usage() {
echo "Usage: $0 [new | complete | info]" echo "Usage: $0 [--info]"
echo " new : Export, import, and rename. (No privileges or post-scripts)" echo " --info : Show configuration information."
echo " complete : Drop, export, import, grant privileges, and run post-scripts." echo " (No argument) : Drop, export, import, grant privileges, and run post-scripts."
echo " info : Show configuration information."
} }
export_schema() { export_schema() {
log "Starting schema export for '${SCHEMA}'." echo "Starting schema export for '${SCHEMA}'."
mkdir -p "$AURORA_TEMP_DIR" mkdir -p "$AURORA_TEMP_DIR"
run_sql "EXPORT \"${SCHEMA}\".\"*\" AS BINARY INTO '$AURORA_TEMP_DIR' WITH REPLACE;" run_sql "EXPORT \"${SCHEMA}\".\"*\" AS BINARY INTO '$AURORA_TEMP_DIR' WITH REPLACE;"
log "Schema export completed." echo "Schema export completed."
} }
import_and_rename() { import_and_rename() {
log "Starting import and rename to '${AURORA}'." echo "Starting import and rename to '${AURORA}'."
run_sql "IMPORT \"${SCHEMA}\".\"*\" FROM '$AURORA_TEMP_DIR' WITH RENAME SCHEMA \"${SCHEMA}\" TO \"${AURORA}\";" run_sql "IMPORT \"${SCHEMA}\".\"*\" FROM '$AURORA_TEMP_DIR' WITH RENAME SCHEMA \"${SCHEMA}\" TO \"${AURORA}\";"
log "Updating company name fields." echo "Updating company name fields."
local update_sql=" "$HDBSQL" -U "${BACKOP_USER}" -c ";" -I - <<EOF
UPDATE \"${AURORA}\".CINF SET \"CompnyName\"='AURORA ${COMPNYNAME} ${TIMESTAMP}'; UPDATE \"${AURORA}\".CINF SET \"CompnyName\"='AURORA ${COMPNYNAME} ${TIMESTAMP}';
UPDATE \"${AURORA}\".OADM SET \"CompnyName\"='AURORA ${COMPNYNAME} ${TIMESTAMP}'; UPDATE \"${AURORA}\".OADM SET \"CompnyName\"='AURORA ${COMPNYNAME} ${TIMESTAMP}';
UPDATE \"${AURORA}\".OADM SET \"PrintHeadr\"='AURORA ${COMPNYNAME} ${TIMESTAMP}';" UPDATE \"${AURORA}\".OADM SET \"PrintHeadr\"='AURORA ${COMPNYNAME} ${TIMESTAMP}';
"$HDBSQL" -U "${BACKOP_USER}" -c ";" -I - <<EOF
${update_sql}
EOF EOF
log "Import and rename completed." echo "Import and rename completed."
} }
grant_privileges() { grant_privileges() {
log "Granting privileges on '${AURORA}' to '${AURORA_SCHEMA_USER}'." echo "Granting privileges on '${AURORA}' to '${AURORA_SCHEMA_USER}'."
run_sql "GRANT ALL PRIVILEGES ON SCHEMA \"${AURORA}\" TO \"${AURORA_SCHEMA_USER}\";" run_sql "GRANT ALL PRIVILEGES ON SCHEMA \"${AURORA}\" TO \"${AURORA_SCHEMA_USER}\";"
log "Privileges granted." echo "Privileges granted."
} }
drop_aurora_schema() { drop_aurora_schema() {
log "Dropping existing '${AURORA}' schema." echo "Dropping existing '${AURORA}' schema."
"$HDBSQL" -U "${BACKOP_USER}" "DROP SCHEMA \"${AURORA}\" CASCADE;" >/dev/null 2>&1 || log "Could not drop schema '${AURORA}'. It might not exist." run_sql "DROP SCHEMA \"${AURORA}\" CASCADE;" 2>/dev/null || echo "Could not drop schema '${AURORA}'. It might not exist." >&2
log "Old schema dropped." echo "Old schema dropped."
} }
run_post_scripts() { run_post_scripts() {
log "Running post-import SQL scripts: ${POST_SQL}" echo "Running post-import SQL scripts: ${POST_SQL}"
for sql_file in $POST_SQL; do for sql_file in $POST_SQL; do
log "Running script: ${sql_file}" echo "Running script: ${sql_file}"
"$HDBSQL" -U "${BACKOP_USER}" -I "${SCRIPT_ROOT}/${sql_file}" "$HDBSQL" -U "${BACKOP_USER}" -I "${SCRIPT_ROOT}/${sql_file}"
done done
log "All post-import scripts completed." echo "All post-import scripts completed."
} }
# === SCRIPT EXECUTION === # === SCRIPT EXECUTION ===
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
usage echo "=== Starting 'complete' operation (default) ==="
exit 1
fi
case "$1" in
new)
log "=== Starting 'new' operation ==="
export_schema
import_and_rename
log "=== 'New' operation finished successfully ==="
;;
complete)
log "=== Starting 'complete' operation ==="
drop_aurora_schema drop_aurora_schema
export_schema export_schema
import_and_rename import_and_rename
grant_privileges grant_privileges
run_post_scripts run_post_scripts
log "=== 'Complete' operation finished successfully ===" echo "=== 'Complete' operation finished successfully ==="
;; exit 0
info) fi
case "$1" in
--info)
show_info show_info
;; ;;
*) *)
echo "Error: Invalid argument '$1'." echo "Error: Invalid argument '$1'." >&2
usage usage
exit 1 exit 1
;; ;;

View File

@@ -7,7 +7,7 @@
declare -A SCRIPT_PACKAGES 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.2.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.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["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["Monitor Suite"]="1.0.5|https://git.technopunk.space/tomi/Scripts/raw/branch/main/monitor/monitor.sh https://git.technopunk.space/tomi/Scripts/raw/branch/main/monitor/monitor.conf" SCRIPT_PACKAGES["Monitor Suite"]="1.0.5|https://git.technopunk.space/tomi/Scripts/raw/branch/main/monitor/monitor.sh https://git.technopunk.space/tomi/Scripts/raw/branch/main/monitor/monitor.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"