@@ -5,19 +5,20 @@ set -euo pipefail
55# Configuration from template
66readonly PG_VERSION=" {{.PgVersion}}"
77readonly PG_PORT=" {{.PgPort}}"
8- readonly DATABASE_NAME=" {{.DatabaseName}}"
8+ readonly RESTORE_NAME=" {{.RestoreName}}" # e.g., restore_20251211000011
9+ readonly TARGET_DATABASE_NAME=" {{.TargetDatabaseName}}" # e.g., db_prod
910readonly DATA_DIR=" {{.DataDir}}" # e.g., /opt/branchd/restore_20250915120000/data
1011readonly PGBACKREST_CONF=" {{.PgBackRestConfPath}}"
1112readonly STANZA_NAME=" {{.StanzaName}}"
1213
1314# Paths
1415readonly RESTORE_LOG_DIR=" /var/log/branchd"
15- readonly RESTORE_LOG=" ${RESTORE_LOG_DIR} /restore-${DATABASE_NAME } .log"
16- readonly RESTORE_PID=" ${RESTORE_LOG_DIR} /restore-${DATABASE_NAME } .pid"
16+ readonly RESTORE_LOG=" ${RESTORE_LOG_DIR} /restore-${RESTORE_NAME } .log"
17+ readonly RESTORE_PID=" ${RESTORE_LOG_DIR} /restore-${RESTORE_NAME } .pid"
1718readonly PG_BIN=" /usr/lib/postgresql/${PG_VERSION} /bin"
1819readonly RESTORE_DATASET_PATH=$( dirname " ${DATA_DIR} " ) # /opt/branchd/restore_YYYYMMDDHHMMSS
19- readonly ZFS_DATASET=" tank/${DATABASE_NAME } "
20- readonly SERVICE_NAME=" branchd-restore-${DATABASE_NAME } "
20+ readonly ZFS_DATASET=" tank/${RESTORE_NAME } "
21+ readonly SERVICE_NAME=" branchd-restore-${RESTORE_NAME } "
2122
2223# Helper functions
2324log () {
@@ -65,7 +66,7 @@ die() {
6566 exit 1
6667}
6768
68- log " Starting Crunchy Bridge restore: ${DATABASE_NAME } "
69+ log " Starting Crunchy Bridge restore: ${RESTORE_NAME } "
6970log " PostgreSQL version: ${PG_VERSION} , Port: ${PG_PORT} "
7071log " Data directory: ${DATA_DIR} "
7172log " Stanza: ${STANZA_NAME} "
@@ -241,7 +242,7 @@ log "PostgreSQL configuration complete"
241242log " Creating systemd service: ${SERVICE_NAME} "
242243sudo tee " /etc/systemd/system/${SERVICE_NAME} .service" > /dev/null << EOF
243244[Unit]
244- Description=PostgreSQL Restore Cluster from Crunchy Bridge (${DATABASE_NAME } )
245+ Description=PostgreSQL Restore Cluster from Crunchy Bridge (${RESTORE_NAME } )
245246After=network.target zfs-mount.service
246247Requires=zfs-mount.service
247248
@@ -294,7 +295,7 @@ log "Cleaning up schemas and extensions..."
294295
295296# Use Unix socket connection (no -h flag) to leverage peer authentication
296297# This avoids needing the postgres password from the restored database
297- sudo -u postgres ${PG_BIN} /psql -p ${PG_PORT} -d ${DATABASE_NAME } << 'EOSQL '
298+ sudo -u postgres ${PG_BIN} /psql -p ${PG_PORT} -d ${TARGET_DATABASE_NAME } << 'EOSQL '
298299DROP EXTENSION IF EXISTS crunchy_pooler CASCADE;
299300EOSQL
300301
0 commit comments