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:
183
web/src/api.ts
183
web/src/api.ts
@@ -4,18 +4,27 @@ export type Snapshot = {
|
||||
taken_at: string;
|
||||
orbit_name: string;
|
||||
size_bytes: number;
|
||||
capture?: { job_id: string; application_id: string; engine: "postgres" | "mysql"; format: string; restore_ready: boolean } | null;
|
||||
};
|
||||
|
||||
export type BackupSource = "filesystem" | "database";
|
||||
export type BackupAccess = "hub" | "outpost";
|
||||
|
||||
export type Orbit = {
|
||||
id: string;
|
||||
name: string;
|
||||
provider: string;
|
||||
provider_config?: string;
|
||||
source: BackupSource | null;
|
||||
access: BackupAccess;
|
||||
last_status: string;
|
||||
dry_run: boolean;
|
||||
schedule?: string | null;
|
||||
decay_preset?: string;
|
||||
retention?: RetentionPolicy | null;
|
||||
application_id?: string | null;
|
||||
capture_schedule?: { hour: number; minute: number; timezone: string } | null;
|
||||
capture_retention?: { mode: "age"; days: number } | { mode: "count"; keep: number } | null;
|
||||
retention_source?: "orbit" | "profile" | "default";
|
||||
};
|
||||
|
||||
export type RetentionPolicy = {
|
||||
@@ -29,14 +38,52 @@ export type RetentionSettings = { decay_preset: string } | { retention: Retentio
|
||||
|
||||
export type CreateOrbitInput = {
|
||||
name: string;
|
||||
provider: "filesystem" | "postgres";
|
||||
paths: string[];
|
||||
schedule?: string;
|
||||
dry_run: boolean;
|
||||
} & RetentionSettings;
|
||||
} & RetentionSettings & (
|
||||
| { source: "filesystem"; access: "hub"; provider_config: { paths: string[] } }
|
||||
| { source: "database"; access: "hub"; provider_config: {
|
||||
engine: "postgres" | "mysql"; transport?: "direct"; host: string; port?: number;
|
||||
database: string; user: string; password_file: string;
|
||||
tls?: { mode: "verify_full_with_ca" | "verify_identity_with_ca"; ca_file: string };
|
||||
} }
|
||||
| { source: BackupSource; access: "outpost"; provider_config: Record<string, never> }
|
||||
);
|
||||
|
||||
export type OperatorSession = {
|
||||
login_enabled: boolean;
|
||||
authorized: boolean;
|
||||
actor: string | null;
|
||||
csrf: string | null;
|
||||
};
|
||||
|
||||
let csrf: string | null = null;
|
||||
|
||||
export async function fetchOperatorSession(signal?: AbortSignal): Promise<OperatorSession> {
|
||||
const session = await api<OperatorSession>("/api/v1/operator/session", { signal });
|
||||
csrf = session.csrf;
|
||||
return session;
|
||||
}
|
||||
|
||||
export async function loginOperator(password: string): Promise<OperatorSession> {
|
||||
const session = await api<OperatorSession>("/api/v1/operator/login", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ password }),
|
||||
});
|
||||
csrf = session.csrf;
|
||||
return session;
|
||||
}
|
||||
|
||||
export async function logoutOperator(): Promise<void> {
|
||||
await request("/api/v1/operator/session", { method: "DELETE" });
|
||||
csrf = null;
|
||||
}
|
||||
|
||||
async function request(path: string, init?: RequestInit): Promise<Response> {
|
||||
const r = await fetch(path, init);
|
||||
const headers = new Headers(init?.headers);
|
||||
if (csrf && init?.method && init.method !== "GET") headers.set("X-Tessera-CSRF", csrf);
|
||||
const r = await fetch(path, { ...init, headers });
|
||||
if (!r.ok) {
|
||||
const text = await r.text().catch(() => "");
|
||||
throw new Error(text || `${path} failed`);
|
||||
@@ -68,14 +115,7 @@ export async function createOrbit(input: CreateOrbitInput): Promise<Orbit> {
|
||||
return api("/api/v1/orbits", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
name: input.name,
|
||||
provider: input.provider,
|
||||
provider_config: { paths: input.paths },
|
||||
schedule: input.schedule || null,
|
||||
...("retention" in input ? { retention: input.retention } : { decay_preset: input.decay_preset }),
|
||||
dry_run: input.dry_run,
|
||||
}),
|
||||
body: JSON.stringify(input),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -120,3 +160,120 @@ export async function pollReconstitute(sessionId: string) {
|
||||
if (!response.ok) throw new Error("Could not read restore status");
|
||||
return response.json() as Promise<{ state: string; seconds_remaining: number }>;
|
||||
}
|
||||
|
||||
|
||||
export type CaptureProfile = {
|
||||
application_id: string;
|
||||
orbit_id: string;
|
||||
outpost_id: string;
|
||||
format: "postgres_custom" | "postgres_sql" | "mysql_sql" | "filesystem";
|
||||
schedule?: Orbit["capture_schedule"];
|
||||
};
|
||||
|
||||
export function registerCaptureProfile(profile: CaptureProfile): Promise<CaptureProfile> {
|
||||
return api("/api/v1/capture-profiles", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(profile),
|
||||
});
|
||||
}
|
||||
|
||||
export type CaptureJob = {
|
||||
id: string;
|
||||
profile: CaptureProfile;
|
||||
actor: string;
|
||||
status: "queued" | "running" | "completed" | "failed";
|
||||
phase: string;
|
||||
created_at: number;
|
||||
snapshot_id: string | null;
|
||||
offsite_status: "pending" | "failed" | "copied" | null;
|
||||
};
|
||||
|
||||
export type CaptureEvent = { at: number; phase: string };
|
||||
|
||||
export function fetchCaptureProfiles(): Promise<CaptureProfile[]> {
|
||||
return api("/api/v1/capture-profiles");
|
||||
}
|
||||
|
||||
export function enqueueCapture(application: string): Promise<CaptureJob> {
|
||||
return api(`/api/v1/capture-profiles/${application}/jobs`, { method: "POST" });
|
||||
}
|
||||
|
||||
export function fetchCaptureJobs(application: string, status: string): Promise<CaptureJob[]> {
|
||||
const filter = new URLSearchParams();
|
||||
if (application) filter.set("application_id", application);
|
||||
if (status) filter.set("status", status);
|
||||
return api(`/api/v1/capture-jobs?${filter}`);
|
||||
}
|
||||
|
||||
export function fetchCaptureEvents(job: string): Promise<CaptureEvent[]> {
|
||||
return api(`/api/v1/capture-jobs/${job}/events`);
|
||||
}
|
||||
|
||||
export function deleteSnapshot(snapshot: string): Promise<void> {
|
||||
return api(`/api/v1/snapshots/${snapshot}`, { method: "DELETE" });
|
||||
}
|
||||
|
||||
|
||||
export type Outpost = { id: string; name: string | null; last_seen: string | null; pairing_state: string };
|
||||
|
||||
export function fetchOutposts(): Promise<Outpost[]> {
|
||||
return api("/api/v1/wormhole/outposts");
|
||||
}
|
||||
|
||||
|
||||
export type RestoreTarget = {
|
||||
id: string;
|
||||
name: string;
|
||||
outpost_id: string;
|
||||
engine: "postgres" | "mysql";
|
||||
application_id: string;
|
||||
identity: { instance: string; database: string };
|
||||
};
|
||||
|
||||
export type SnapshotRestoreTarget = RestoreTarget & { ineligible_reason: string | null };
|
||||
|
||||
export function registerRestoreTarget(target: RestoreTarget): Promise<RestoreTarget> {
|
||||
return api("/api/v1/restore-targets", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(target),
|
||||
});
|
||||
}
|
||||
|
||||
export type RestoreJob = {
|
||||
id: string;
|
||||
snapshot_id: string;
|
||||
target: RestoreTarget;
|
||||
status: "queued" | "running" | "applying" | "failed" | "completed" | "recovery_required" | "reconciled" | "cancelled";
|
||||
phase: string;
|
||||
safety_snapshot_id: string | null;
|
||||
};
|
||||
|
||||
export function fetchRestoreTargets(snapshot: string): Promise<SnapshotRestoreTarget[]> {
|
||||
return api(`/api/v1/snapshots/${snapshot}/restore-targets`);
|
||||
}
|
||||
|
||||
export function fetchRestoreJobs(snapshot: string): Promise<RestoreJob[]> {
|
||||
return api(`/api/v1/snapshots/${snapshot}/restore-jobs`);
|
||||
}
|
||||
|
||||
export function enqueueRestore(snapshot: string, target: string, confirmation: string): Promise<RestoreJob> {
|
||||
return api("/api/v1/restore-jobs", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ snapshot_id: snapshot, target_id: target, confirmation }),
|
||||
});
|
||||
}
|
||||
|
||||
export function cancelRestore(job: string): Promise<void> {
|
||||
return api(`/api/v1/restore-jobs/${job}`, { method: "DELETE" });
|
||||
}
|
||||
|
||||
export function reconcileRestore(job: string, confirmation: string): Promise<void> {
|
||||
return api(`/api/v1/restore-jobs/${job}/reconcile`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ confirmation }),
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user