Run whole-data archives and restores in the background

A data archive or restore ran inside its request, which sent nothing
until tar finished: Bun closes a silent socket after 10s (its default
idleTimeout in production) and a proxy cuts it at about 100s, so the
page showed a network error while the archive kept going, and a retry
said another backup was already running.

The routes now start the run (startDataBackupRun, refused while the
backup lock is held) and answer at once. The page follows it by polling
api/admin/backups/data-status: an archive reloads once written, a
restore once the status comes from a new process after its restart,
and a failure shows its error. A run in progress survives a reload.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-25 08:34:29 +01:00
co-authored by Claude Opus 5.5
parent 86becd50bc
commit 4161863587
22 changed files with 630 additions and 179 deletions
@@ -1,6 +1,7 @@
import grabSuperAdminUser from "@/src/functions/backend/backups/grab-super-admin-user";
import grabDbBackups from "@/src/functions/backend/backups/grab-db-backups";
import grabDataBackups from "@/src/functions/backend/backups/grab-data-backups";
import { grabDataBackupRun } from "@/src/functions/backend/backups/data-backup-run";
import { SettingsDefaultPath } from "@/src/dict/settings-pages-dict";
import type { PagePropsType } from "@/src/types";
import type { BunextPageServerFn } from "@moduletrace/bunext/types";
@@ -10,7 +11,8 @@ type Params = Parameters<BunextPageServerFn<PagePropsType>>[0];
/**
* Shared server props for the `/admin/settings/backups` sub-pages: the
* saved database snapshots and the whole-data archives. Super admins
* saved database snapshots, the whole-data archives and the archive or
* restore running now, so a reload mid-run picks it back up. Super admins
* only; everyone else lands on the general settings.
*/
export default async function grabBackupsServerProps(params: Params) {
@@ -32,6 +34,7 @@ export default async function grabBackupsServerProps(params: Params) {
...settings.props,
backups: grabDbBackups(),
data_backups: grabDataBackups(),
data_backup_run: grabDataBackupRun(),
},
};
}