aurora
This commit is contained in:
33
aurora/aurora.conf
Normal file
33
aurora/aurora.conf
Normal file
@@ -0,0 +1,33 @@
|
||||
# Configuration for the HANA Aurora Refresh Script
|
||||
# Place this file in the same directory as the aurora_refresh.sh script.
|
||||
|
||||
# --- Main Settings ---
|
||||
|
||||
# The source production schema to be copied.
|
||||
SCHEMA="SBO_DEMO"
|
||||
|
||||
# The user who will be granted privileges on the new Aurora schema.
|
||||
AURORA_SCHEMA_USER="B1_53424F5F4348494D5045585F4155524F5241_RW"
|
||||
|
||||
# The database user for performing backup and administrative tasks.
|
||||
BACKOP_USER="CRONKEY"
|
||||
|
||||
|
||||
# --- Paths and Files ---
|
||||
|
||||
# The root directory where the script and its associated files are located.
|
||||
SCRIPT_ROOT="/usr/sap/NDB/home/tools"
|
||||
|
||||
# The base directory for storing the temporary schema export.
|
||||
BACKUP_DIR="/hana/shared/backup/schema"
|
||||
|
||||
# The full path to the HANA hdbsql executable.
|
||||
HDBSQL="/usr/sap/NDB/HDB00/exe/hdbsql"
|
||||
|
||||
|
||||
# --- Post-Import Scripts ---
|
||||
|
||||
# A space-separated list of SQL script files to run after the import is complete.
|
||||
# These scripts should be located in the SCRIPT_ROOT directory.
|
||||
#POST_SQL="NAVO_PARAMS.sql GRANT_OLI_ARF.sql"
|
||||
POST_SQL=""
|
||||
125
aurora/aurora.sh
Normal file
125
aurora/aurora.sh
Normal file
@@ -0,0 +1,125 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Exit immediately if a command exits with a non-zero status.
|
||||
set -e
|
||||
|
||||
# === SETUP ===
|
||||
# Determine script's directory and source the configuration file.
|
||||
SCRIPT_DIR=$(dirname "$0")
|
||||
CONFIG_FILE="${SCRIPT_DIR}/aurora.conf"
|
||||
|
||||
if [ ! -f "$CONFIG_FILE" ]; then
|
||||
echo "Error: Configuration file not found at ${CONFIG_FILE}"
|
||||
exit 1
|
||||
fi
|
||||
# shellcheck source=aurora.conf
|
||||
. "$CONFIG_FILE"
|
||||
|
||||
# === DERIVED VARIABLES ===
|
||||
TIMESTAMP=$(date "+%Y-%m-%d %H:%M:%S")
|
||||
AURORA="${SCHEMA}_AURORA"
|
||||
AURORA_TEMP_DIR="${BACKUP_DIR}/${AURORA}"
|
||||
LOGFILE="${SCRIPT_ROOT}/aurora.log"
|
||||
temp_compnyname=${SCHEMA#SBO_} # Remove SBO_ prefix
|
||||
COMPNYNAME=${temp_compnyname%_PROD} # Remove _PROD suffix if it exists
|
||||
|
||||
# === FUNCTIONS ===
|
||||
|
||||
log() { echo "$(date +"%Y-%m-%d %H:%M:%S") - $1" | tee -a "$LOGFILE"; }
|
||||
run_sql() {
|
||||
log "Executing: $1"
|
||||
"$HDBSQL" -U "${BACKOP_USER}" "$1" >/dev/null
|
||||
}
|
||||
|
||||
show_info() {
|
||||
echo "Source Schema: ${SCHEMA}"
|
||||
echo "Target Schema: ${AURORA}"
|
||||
echo "Target Schema User: ${AURORA_SCHEMA_USER}"
|
||||
echo "Company Name: ${COMPNYNAME}"
|
||||
echo "Export Directory: ${AURORA_TEMP_DIR}"
|
||||
echo "Log File: ${LOGFILE}"
|
||||
}
|
||||
|
||||
usage() {
|
||||
echo "Usage: $0 [-n | -c | -i]"
|
||||
echo " -n (new) : Export, import, and rename. (No privileges or post-scripts)"
|
||||
echo " -c (complete) : Drop, export, import, grant privileges, and run post-scripts."
|
||||
echo " -i (info) : Show configuration information."
|
||||
}
|
||||
|
||||
export_schema() {
|
||||
log "Starting schema export for '${SCHEMA}'."
|
||||
mkdir -p "$AURORA_TEMP_DIR"
|
||||
run_sql "EXPORT \"${SCHEMA}\".\"*\" AS BINARY INTO '$AURORA_TEMP_DIR' WITH REPLACE;"
|
||||
log "Schema export completed."
|
||||
}
|
||||
|
||||
import_and_rename() {
|
||||
log "Starting import and rename to '${AURORA}'."
|
||||
run_sql "IMPORT \"${SCHEMA}\".\"*\" FROM '$AURORA_TEMP_DIR' WITH RENAME SCHEMA \"${SCHEMA}\" TO \"${AURORA}\";"
|
||||
log "Updating company name fields."
|
||||
local update_sql="
|
||||
UPDATE \"${AURORA}\".CINF SET \"CompnyName\"='AURORA ${COMPNYNAME} ${TIMESTAMP}';
|
||||
UPDATE \"${AURORA}\".OADM SET \"CompnyName\"='AURORA ${COMPNYNAME} ${TIMESTAMP}';
|
||||
UPDATE \"${AURORA}\".OADM SET \"PrintHeadr\"='AURORA ${COMPNYNAME} ${TIMESTAMP}';"
|
||||
"$HDBSQL" -U "${BACKOP_USER}" -c ";" -I - <<EOF
|
||||
${update_sql}
|
||||
EOF
|
||||
log "Import and rename completed."
|
||||
}
|
||||
|
||||
grant_privileges() {
|
||||
log "Granting privileges on '${AURORA}' to '${AURORA_SCHEMA_USER}'."
|
||||
run_sql "GRANT ALL PRIVILEGES ON SCHEMA \"${AURORA}\" TO \"${AURORA_SCHEMA_USER}\";"
|
||||
log "Privileges granted."
|
||||
}
|
||||
|
||||
drop_aurora_schema() {
|
||||
log "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."
|
||||
log "Old schema dropped."
|
||||
}
|
||||
|
||||
run_post_scripts() {
|
||||
log "Running post-import SQL scripts: ${POST_SQL}"
|
||||
for sql_file in $POST_SQL; do
|
||||
log "Running script: ${sql_file}"
|
||||
"$HDBSQL" -U "${BACKOP_USER}" -I "${SCRIPT_ROOT}/${sql_file}"
|
||||
done
|
||||
log "All post-import scripts completed."
|
||||
}
|
||||
|
||||
# === SCRIPT EXECUTION ===
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
while getopts "nci" option; do
|
||||
case "$option" in
|
||||
n)
|
||||
log "=== Starting 'new' operation ==="
|
||||
export_schema
|
||||
import_and_rename
|
||||
log "=== 'New' operation finished successfully ==="
|
||||
;;
|
||||
c)
|
||||
log "=== Starting 'complete' operation ==="
|
||||
drop_aurora_schema
|
||||
export_schema
|
||||
import_and_rename
|
||||
grant_privileges
|
||||
run_post_scripts
|
||||
log "=== 'Complete' operation finished successfully ==="
|
||||
;;
|
||||
i)
|
||||
show_info
|
||||
;;
|
||||
*)
|
||||
echo "Error: Invalid option."
|
||||
usage
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
Reference in New Issue
Block a user