feat: add managed database capture and operator restore

PostgreSQL and MySQL backups run through paired outposts, with operator sign-in, off-site copies, and legacy import. Retention stays on each orbit, so the unused retention console is removed.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-11-10 23:26:49 +07:00
parent 30a1a9b8f0
commit 6320b6f244
96 changed files with 11061 additions and 725 deletions

View File

@@ -1,6 +1,7 @@
import { useEffect, useState } from "react";
import { motion } from "motion/react";
import type { Snapshot } from "../../api";
import { DatabaseRestore } from "./DatabaseRestore";
import { formatBytes, formatWhen } from "../../lib/format";
import { Button } from "../ui/Button";
import { Hint } from "../ui/EmptyState";
@@ -11,6 +12,7 @@ const GRACE = 12;
export function ReconstituteWizard({
snapshots,
selected,
scopedExport,
onStart,
onPoll,
onAbort,
@@ -18,6 +20,7 @@ export function ReconstituteWizard({
}: {
snapshots: Snapshot[];
selected: string | null;
scopedExport?: boolean;
onStart: (snapId: string, target: string) => Promise<{
session_id: string;
session: { seconds_remaining: number; state: string };
@@ -27,7 +30,8 @@ export function ReconstituteWizard({
onBusyChange: (busy: boolean) => void;
}) {
const [snapId, setSnapId] = useState(selected ?? snapshots[0]?.id ?? "");
const [target, setTarget] = useState("./restore/out");
const [databaseMode, setDatabaseMode] = useState(true);
const [target, setTarget] = useState(scopedExport ? "restored.dump" : "./restore/out");
const [sessionId, setSessionId] = useState<string | null>(null);
const [remaining, setRemaining] = useState(GRACE);
const [state, setState] = useState("idle");
@@ -36,6 +40,7 @@ export function ReconstituteWizard({
const [reconnecting, setReconnecting] = useState(false);
const snap = snapshots.find((s) => s.id === snapId);
const managed = snap?.capture?.restore_ready ? snap.capture : undefined;
const inCountdown = state === "countdown" || state === "confirming";
const busy = !!action || inCountdown || state === "restoring";
@@ -72,7 +77,7 @@ export function ReconstituteWizard({
return (
<div className="space-y-4">
<p className="text-sm text-star-300">
Choose a snapshot and a destination on the hub.
Choose a recovery point and a destination.
</p>
{snap && (
@@ -87,7 +92,7 @@ export function ReconstituteWizard({
<select
className="mt-1 w-full rounded-xl bg-space-950 border border-space-700 px-3 py-2.5"
value={snapId}
onChange={(e) => setSnapId(e.target.value)}
onChange={(e) => { setSnapId(e.target.value); setDatabaseMode(true); }}
disabled={busy}
>
{snapshots.map((s) => (
@@ -98,8 +103,25 @@ export function ReconstituteWizard({
</select>
</label>
{managed && (
<div className="flex flex-wrap gap-2" aria-label="Recovery destination" role="group">
<Button type="button" aria-pressed={databaseMode} disabled={busy}
variant={databaseMode ? "primary" : "ghost"} onClick={() => setDatabaseMode(true)}>
Restore to database
</Button>
<Button type="button" aria-pressed={!databaseMode} disabled={busy}
variant={databaseMode ? "ghost" : "primary"} onClick={() => setDatabaseMode(false)}>
Export file on hub
</Button>
</div>
)}
{managed && databaseMode ? (
<DatabaseRestore key={snapId} snapshot={snapId} application={managed.application_id}
engine={managed.engine} />
) : <>
<label className="block text-sm">
<span className="text-star-400">Target path</span>
<span className="text-star-400">{scopedExport ? "Export filename on hub" : "Export file path on hub"}</span>
<input
className="mt-1 w-full rounded-xl bg-space-950 border border-space-700 px-3 py-2.5 font-mono text-xs"
value={target}
@@ -151,7 +173,7 @@ export function ReconstituteWizard({
await onAbort(sessionId);
} catch {
setAction(undefined);
setError("Could not cancel the restore. Check the current session status.");
setError("Could not cancel the file export. Check the current session status.");
}
}}
>
@@ -170,39 +192,40 @@ export function ReconstituteWizard({
setState(res.session.state);
setRemaining(res.session.seconds_remaining);
} catch {
setError("Could not confirm that the hub started the restore.");
setError("Could not confirm that the hub started writing to the destination.");
} finally {
setAction(undefined);
}
}}
>
Begin restore
Begin file export
</Button>
</div>
{error && <p role="alert" className="text-orbit-red text-sm">{error}</p>}
{reconnecting && <p role="status" className="text-orbit-amber text-sm">Reconnecting to the restore session…</p>}
{state === "restoring" && <p role="status" className="text-orbit-amber text-sm">Restoring snapshot…</p>}
{reconnecting && <p role="status" className="text-orbit-amber text-sm">Reconnecting to the export session…</p>}
{state === "restoring" && <p role="status" className="text-orbit-amber text-sm">Exporting snapshot…</p>}
{state === "unavailable" && (
<p role="alert" className="text-orbit-red text-sm">The hub no longer has this restore session. Check the destination before retrying.</p>
<p role="alert" className="text-orbit-red text-sm">The hub no longer has this export session. Check the destination before retrying.</p>
)}
{state === "completed" && (
<p className="text-orbit-green text-sm text-center">Reconstitute complete.</p>
<p className="text-orbit-green text-sm text-center">File export complete.</p>
)}
{state === "aborted" && (
<p className="text-star-300 text-sm text-center">Reconstitute cancelled. Nothing was changed.</p>
<p className="text-star-300 text-sm text-center">File export cancelled.</p>
)}
{state === "failed" && (
<p className="text-orbit-red text-sm text-center">Reconstitute failed — check telemetry.</p>
<p className="text-orbit-red text-sm text-center">File export failed. Check telemetry.</p>
)}
<Hint>The hub writes after the countdown. An existing file at the destination may be overwritten.</Hint>
<Hint>{scopedExport ? "The hub writes to its exports directory after the countdown." : "The hub writes after the countdown. An existing file at the destination may be overwritten."}</Hint>
{sessionId && (
<TelemetryPanel label="Session">
{JSON.stringify({ sessionId, state, remaining }, null, 2)}
</TelemetryPanel>
)}
</>}
</div>
);
}