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]>
28 lines
851 B
TypeScript
28 lines
851 B
TypeScript
import adminFetchHandler from "@/src/functions/frontend/admin-fetch-handler";
|
|
import type { DataBackupRun } from "@/src/types";
|
|
|
|
/**
|
|
* Starts the archive, which runs in the background on the server, and
|
|
* hands back its run for the page to follow.
|
|
*/
|
|
export default async function createDataBackup() {
|
|
if (
|
|
!window.confirm(
|
|
`Archive all of the data volume now? It can take a while on a busy install.`,
|
|
)
|
|
) {
|
|
return { success: false, cancelled: true };
|
|
}
|
|
|
|
const res = await adminFetchHandler({
|
|
url: "/api/admin/backups/create-data",
|
|
method: "POST",
|
|
});
|
|
|
|
return {
|
|
success: Boolean(res.success),
|
|
msg: res.success ? undefined : res.msg || `Couldn't create archive`,
|
|
run: res.success ? (res.singleRes as DataBackupRun | undefined) : undefined,
|
|
};
|
|
}
|