diegosouzapw/OmniRoute · error · Error

Backup not found

Error message

Backup not found: ${backupId}

What it means

restoreDbBackup validated the backup ID format and traversal safety, but no file exists at the resolved path inside the backup directory — the requested backup was never created, was deleted by retention/cleanup, or the ID is stale.

Solutions

  1. List available backups (e.g. via the backup listing API) and pick an existing db_<timestamp>_<reason>.sqlite ID
  2. Re-create a fresh backup before attempting restore if none exists
  3. Refresh any cached/stored backup IDs that may have been pruned by cleanup policies
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/lib/db/backup.ts:388 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of diegosouzapw/OmniRoute@a179ffed5b (2026-08-25). Data as JSON: /api/errors/42b746ff7f9e1fe8. Report an issue: GitHub.

Appendix: source

Thrown at src/lib/db/backup.ts:388

    !backupId.startsWith("db_") ||
    !backupId.endsWith(".sqlite") ||
    backupId.includes(path.sep) ||
    backupId.includes("/")
  ) {
    throw new Error("Invalid backup ID");
  }

  const backupPath = path.resolve(backupDir, backupId);
  // Prevent path traversal: resolved path must stay within backupDir
  if (
    !backupPath.startsWith(path.resolve(backupDir) + path.sep) &&
    backupPath !== path.resolve(backupDir)
  ) {
    throw new Error("Invalid backup ID: path traversal detected");
  }

  if (!fs.existsSync(backupPath)) {
    throw new Error(`Backup not found: ${backupId}`);
  }

  // Validate backup integrity
  try {
    const { tryOpenSync } = await import("@/lib/db/adapters/driverFactory");
    const testDb = tryOpenSync(backupPath, { readonly: true });
    if (!testDb) {
      throw new Error("Backup file is corrupt: could not open");
    }
    let result: Array<{ integrity_check?: string }>;
    try {
      result = testDb.pragma("integrity_check") as Array<{ integrity_check?: string }>;
    } finally {
      testDb.close();
    }
    if (result[0]?.integrity_check !== "ok") {
      throw new Error("Backup integrity check failed");
    }

View on GitHub (pinned to a179ffed5b)