fix: harden docsgpt backup and docsgpt restore

From review of #2799:

- The archive is created 0600 rather than at the process umask: it holds the
  install's data, and --with-settings puts .env and its secrets in it.
- restore validates everything the manifest declares before the stack is
  stopped, so a damaged archive fails while DocsGPT is still running rather
  than after `compose down` has taken it away.
- Only the volumes a backup is made of are restored. A hand-made manifest can
  no longer point import_volume at postgres_data, whose contents it empties.
- psql runs with ON_ERROR_STOP=on, so a restore that fails halfway cannot
  start DocsGPT again and call it a success.
- import_volume unpacks into the container's own filesystem first and clears
  the live volume only once the tar has come out whole, so a corrupt one
  leaves the volume as it was.
- The backend and the worker stop while the archive is made and start again
  even if the dump fails, so the dump and the volume tars describe the same
  moment instead of drifting apart as ingestion writes.
This commit is contained in:
Alex committed 2026-09-16 21:55:33 +01:00
1 parent fe68fec69e
commit 447ae72fe2
7 files changed
+150 -16

No files matched your search

+5 -2
View File
@@ -119,8 +119,11 @@ class Docker:
"""Replace ``volume``'s contents with the tar at ``source``; the volume is created when missing."""
with source.open("rb") as handle:
self._run(
["docker", "run", "--rm", "-i", "-v", f"{volume}:/data", image,
"sh", "-c", "find /data -mindepth 1 -delete && tar xf - -C /data"],
["docker", "run", "--rm", "-i", "-v", f"{volume}:/data", image, "sh", "-c",
# Unpack into the container's own filesystem first: a truncated or corrupt tar must
# fail before the live volume is touched, not halfway through emptying it.
"set -e; rm -rf /stage; mkdir /stage; tar xf - -C /stage; "
"find /data -mindepth 1 -delete; tar cf - -C /stage . | tar xf - -C /data"],
stdin=handle,
)