fix(backup): keep a dump locally only where it survives the container

The image creates DB_BACKUP_DIR owned by the app user, so an install that
runs it without the backups volume could write there, and every nightly and
pre-migration dump landed in the container's own layer. The next update
threw them away while the admin page, the boot line and the readiness card
called them kept on this server.

A dump directory now counts as kept only when it survives the container:
inside a container (Docker, Podman, Kubernetes, a container cgroup or an
overlay root) the directory must sit on a mount of its own that is not a
tmpfs, read from /proc/self/mountinfo with a device-number fallback;
outside one, a writable directory is a disk. Otherwise no dump is written
there: the nightly run uploads off-host only and records not_persistent,
the pre-migration dump is skipped with a warning, the boot line says the
directory is inside the container, the backups page stops promising local
dumps and ignores local-only ledger rows, and readiness fails with no
bucket and notes the bucket-only setup otherwise.

The Unraid template gains a path for the dumps, the Unraid and TrueNAS
pages say why it is needed, and the restore drill first runs the stack
without the volume and checks that nothing is kept or claimed.
This commit is contained in:
Marc-André Bombeck committed 2026-10-25 16:00:34 +01:00
1 parent fb4ab29aad
commit 351e7d1fe0
32 files changed
+882 -126

No files matched your search

@@ -17,6 +17,8 @@ const HEALTHY: DatabaseBackupHealth = {
directory: "/var/lib/healthlog/backups",
keepNightly: 7,
localDirWritable: true,
localPersistent: true,
localReason: "volume",
offhostConfigured: true,
lastGood: {
at: "2026-10-24T23:31:00.000Z",
@@ -77,17 +79,36 @@ describe("<DatabaseDumpRow>", () => {
});
it("says when dumps go off-host only, or cannot be taken at all", () => {
expect(render({ ...HEALTHY, localDirWritable: false }, null)).toContain(
"dumps go off-host only",
const unwritable = {
...HEALTHY,
localDirWritable: false,
localPersistent: false,
localReason: "not_writable" as const,
};
expect(render(unwritable, null)).toContain("dumps go off-host only");
expect(render({ ...unwritable, offhostConfigured: false }, null)).toContain(
"no database dump can be taken",
);
expect(
render(
{ ...HEALTHY, localDirWritable: false, offhostConfigured: false },
null,
),
).toContain("no database dump can be taken");
expect(render({ ...HEALTHY, lastGood: null }, null)).toContain(
"No database dump yet",
);
});
it("does not promise dumps on this server from a directory inside the container", () => {
const layer = {
...HEALTHY,
localPersistent: false,
localReason: "container_layer" as const,
lastGood: { ...HEALTHY.lastGood!, local: false },
};
const html = render(layer);
expect(html).toContain('data-slot="database-dump-setup"');
expect(html).toContain("lost at the next update");
expect(html).toContain("Dumps go off-host only");
expect(html).not.toContain("kept on this server");
expect(html).toContain("removed after 30 days");
const nowhere = render({ ...layer, offhostConfigured: false }, null);
expect(nowhere).toContain("no database dump is kept anywhere");
expect(nowhere).not.toContain('data-slot="database-dump-retention"');
});
});
@@ -6,7 +6,10 @@
* The account copies below it restore one account on this server; the dump is
* the copy that rebuilds the server. So the row leads the card and says three
* things: when the newest good dump was taken and where it is, whether the
* newest run failed, and whether this server can keep a dump at all.
* newest run failed, and whether this server can keep a dump at all. A
* directory inside the container (the image's own, without the volume) is
* writable and still keeps nothing past the next update, so "kept on this
* server" is only said of a directory that survives it.
*/
import { AlertTriangle, HardDrive } from "lucide-react";
@@ -45,7 +48,15 @@ export function DatabaseDumpRow({
let setupProblem: string | null = null;
if (!health.enabled) {
setupProblem = t("admin.section.backups.database.disabled");
} else if (!health.localDirWritable) {
} else if (health.localDirWritable && !health.localPersistent) {
setupProblem = health.offhostConfigured
? t("admin.section.backups.database.notPersistentOffhost", {
dir: health.directory,
})
: t("admin.section.backups.database.notPersistent", {
dir: health.directory,
});
} else if (!health.localPersistent) {
setupProblem = health.offhostConfigured
? t("admin.section.backups.database.noDirectoryOffhost", {
dir: health.directory,
@@ -55,6 +66,19 @@ export function DatabaseDumpRow({
});
}
const retention = [
health.localPersistent
? t("admin.section.backups.database.retentionLocal", {
nights: health.keepNightly,
})
: null,
bucketLifecycle?.state === "configured"
? t("admin.section.backups.database.retentionOffhost", {
days: bucketLifecycle.expirationDays ?? 0,
})
: null,
].filter((line): line is string => line !== null);
return (
<div className="space-y-2" data-slot="database-dump">
<div className="flex items-start gap-2">
@@ -80,19 +104,14 @@ export function DatabaseDumpRow({
</p>
{/* How long a deleted account stays in the dumps: the operator's
side of the deletion promise (GDPR retention of backups). */}
<p
className="text-muted-foreground text-xs"
data-slot="database-dump-retention"
>
{t("admin.section.backups.database.retentionLocal", {
nights: health.keepNightly,
})}
{bucketLifecycle?.state === "configured"
? ` ${t("admin.section.backups.database.retentionOffhost", {
days: bucketLifecycle.expirationDays ?? 0,
})}`
: null}
</p>
{retention.length > 0 ? (
<p
className="text-muted-foreground text-xs"
data-slot="database-dump-retention"
>
{retention.join(" ")}
</p>
) : null}
</div>
</div>