You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 8167c8a
Browse filesBrowse the repository at this point in the historyBrowse files
fix(selfhost): snapshot.sh asks where DATABASE_URL points, not only whether postgres is defined
A postgres service that is still defined while env/api.env names another host
(NEON.md's step 5 skipped, or any managed Postgres) holds nothing the services
write; archiving it was a snapshot of the wrong database, and a rollback would
have restored it and started the stack against the untouched real one. Now
that case is external, with a note naming the host (never the credentials).
DATABASE_URL_FILE, which the host cannot read, falls back to the service.
Proven on oa-ci: bundled -> volume (and 0/50 wrong over repeats), URL elsewhere
-> external + note, restore of a volume snapshot there -> refused,
DATABASE_URL_FILE -> volume, neon overlay -> external.
Copy file name to clipboardExpand all lines: infra/selfhost/snapshot.sh
+35-5Lines changed: 35 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -124,21 +124,47 @@ volume_at() {
124
124
echo"$name"
125
125
}
126
126
127
-
# True when this compose project runs its own Postgres. Asked of the resolved
128
-
# configuration, so an override that moves `postgres` behind a profile — which
129
-
# is what `docker-compose.neon.yml` does — counts as not running it.
127
+
# True when this compose project defines a `postgres` service. Asked of the
128
+
#resolved configuration, so an override that moves `postgres` behind a profile
129
+
#— which is what `docker-compose.neon.yml` does — counts as not defining it.
130
130
#
131
131
# The list is captured before it is searched, never piped into `grep -q`: under
132
132
# `pipefail`, grep exiting at its first match can SIGPIPE compose while it is
133
133
# still writing, and the pipeline then reads as "no postgres" — which would
134
134
# silently leave a bundled database out of the snapshot. For the same reason a
135
135
# configuration compose cannot resolve is an error here, not an answer.
136
-
postgres_in_stack() {
136
+
postgres_service_defined() {
137
137
local services
138
138
services="$(compose config --services)"|| die "docker compose could not resolve this stack's configuration, so it cannot tell whether Postgres is part of it"
139
139
grep -qx postgres <<<"$services"
140
140
}
141
141
142
+
# The host the api's DATABASE_URL names, or empty when env/api.env gives it
143
+
# through DATABASE_URL_FILE instead — that path is inside the container, so the
144
+
# host cannot read it. Host only: the credentials never leave this function.
[ "$pg_mode"= external ] || [ -f"$from/pg-data.tar.gz" ] || die "$from/pg-data.tar.gz is missing"
337
367
[ -f"$from/ch-data.tar.gz" ] || die "$from/ch-data.tar.gz is missing"
338
368
if [ "$pg_mode"= volume ] &&! postgres_in_stack;then
339
-
die "$from holds a Postgres volume, but this stack runs no postgres service — restore it into a stack that does, or restore the database by hand"
369
+
die "$from holds a Postgres volume, but this stack does not use a bundled postgres (no such service, or DATABASE_URL names another host) — restore it into a stack that does, or restore the database by hand"
0 commit comments