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]>
41 lines
1.5 KiB
TypeScript
41 lines
1.5 KiB
TypeScript
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";
|
|
import grabSettingsServerProps from "../../(functions)/grab-settings-server-props";
|
|
|
|
type Params = Parameters<BunextPageServerFn<PagePropsType>>[0];
|
|
|
|
/**
|
|
* Shared server props for the `/admin/settings/backups` sub-pages: the
|
|
* 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) {
|
|
const settings = await grabSettingsServerProps(params);
|
|
|
|
if (!settings.props) return settings;
|
|
|
|
if (!(await grabSuperAdminUser({ req: params.req }))) {
|
|
return {
|
|
redirect: {
|
|
destination: SettingsDefaultPath,
|
|
permanent: false,
|
|
},
|
|
};
|
|
}
|
|
|
|
return {
|
|
props: {
|
|
...settings.props,
|
|
backups: grabDbBackups(),
|
|
data_backups: grabDataBackups(),
|
|
data_backup_run: grabDataBackupRun(),
|
|
},
|
|
};
|
|
}
|