Skip to content

Commit 3a67d88

Browse files
committed
fix: use actual db name, not restore name
1 parent 8cc603b commit 3a67d88

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

internal/workers/crunchy_bridge_restore.sh

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,20 @@ set -euo pipefail
55
# Configuration from template
66
readonly PG_VERSION="{{.PgVersion}}"
77
readonly 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
910
readonly DATA_DIR="{{.DataDir}}" # e.g., /opt/branchd/restore_20250915120000/data
1011
readonly PGBACKREST_CONF="{{.PgBackRestConfPath}}"
1112
readonly STANZA_NAME="{{.StanzaName}}"
1213

1314
# Paths
1415
readonly 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"
1718
readonly PG_BIN="/usr/lib/postgresql/${PG_VERSION}/bin"
1819
readonly 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
2324
log() {
@@ -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}"
6970
log "PostgreSQL version: ${PG_VERSION}, Port: ${PG_PORT}"
7071
log "Data directory: ${DATA_DIR}"
7172
log "Stanza: ${STANZA_NAME}"
@@ -241,7 +242,7 @@ log "PostgreSQL configuration complete"
241242
log "Creating systemd service: ${SERVICE_NAME}"
242243
sudo 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})
245246
After=network.target zfs-mount.service
246247
Requires=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'
298299
DROP EXTENSION IF EXISTS crunchy_pooler CASCADE;
299300
EOSQL
300301

internal/workers/restore_crunchy_bridge.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ var crunchyBridgeRestoreScript string
2222
type crunchyBridgeRestoreParams struct {
2323
PgVersion string
2424
PgPort int
25-
DatabaseName string
25+
RestoreName string // Name of the restore (e.g., restore_20251211000011) - used for logs, ZFS, service
26+
TargetDatabaseName string // Actual database name in PostgreSQL
2627
DataDir string
2728
PgBackRestConfPath string
2829
StanzaName string
@@ -132,7 +133,8 @@ func (p *CrunchyBridgeProvider) StartRestore(ctx context.Context, params Restore
132133
scriptParams := crunchyBridgeRestoreParams{
133134
PgVersion: params.Config.PostgresVersion,
134135
PgPort: params.Port,
135-
DatabaseName: params.Restore.Name,
136+
RestoreName: params.Restore.Name,
137+
TargetDatabaseName: params.Config.CrunchyBridgeDatabaseName,
136138
DataDir: dataDir,
137139
PgBackRestConfPath: pgbackrestConfPath,
138140
StanzaName: backupToken.Stanza,

0 commit comments

Comments
 (0)