/** * postgres-mcp — Backup Manager * * Pre-mutation snapshot capture for the audit trail. * Creates DDL snapshots (+ optional data) of database objects * before write/admin tools modify them. Snapshots are stored * as gzip-compressed JSON files in a `snapshots/` directory * alongside the audit log. * * §3: Captures row_count + total_size_bytes from pg_class at snapshot time * for semantic diffing (volume drift detection). * §4: Gzip compression, size-bounded data capture, and async fire-and-forget writes. * * Non-throwing by design: snapshot failures log to stderr * but never block tool execution. */ import type { BackupConfig, SnapshotMetadata, SnapshotContent } from "./types.js"; /** * Interface for database queries needed by the backup manager. * Avoids circular imports from the full adapter. */ export interface SnapshotQueryAdapter { executeQuery(sql: string, params?: unknown[]): Promise<{ rows?: Record[]; }>; describeTable(table: string, schema?: string): Promise<{ columns?: { name: string; type: string; nullable: boolean; defaultValue?: unknown; }[]; primaryKey?: string[] | null; }>; } export declare class BackupManager { readonly config: BackupConfig; private readonly snapshotDir; private dirEnsured; private readonly pendingWrites; constructor(config: BackupConfig, auditLogPath: string); /** * Check if a tool should receive a pre-mutation snapshot. */ shouldSnapshot(toolName: string): boolean; /** * Create a pre-mutation snapshot of the target object. * * @returns Relative path to the snapshot file, or undefined if skipped/failed */ createSnapshot(toolName: string, args: Record, requestId: string, adapter: SnapshotQueryAdapter, logAs?: string): Promise; /** * List available snapshots with metadata. */ listSnapshots(): Promise; /** * Read a specific snapshot by filename. */ getSnapshot(filename: string): Promise; /** * Apply retention policy — delete oldest snapshots that exceed limits. */ cleanup(): Promise; /** * Flush all pending async snapshot writes. * Call during graceful shutdown to ensure all snapshots are persisted. */ flush(): Promise; getStats(): Promise<{ count: number; oldestAge?: string; totalSizeKB: number; }>; private captureObjectSnapshot; /** * Build a CREATE TABLE DDL string from the adapter's table description. */ private buildTableDdl; /** * Capture row count and total size bytes from pg_class catalog. * Near-zero cost catalog reads; failures are silently ignored (best-effort). */ private captureVolumeMetadata; /** * Capture row data as INSERT statements, subject to size bounds. * Returns empty output (data: undefined, dataSkipped: false) when * `includeData` is disabled in config, or when the table is too large. */ private captureTableData; private captureSchemaSnapshot; private captureSchemaDropSnapshot; private writeSnapshot; /** * Read and decompress a snapshot file (supports both gzip and legacy JSON). */ private readSnapshotFile; private ensureDirectory; } //# sourceMappingURL=backup-manager.d.ts.map