BigPizzaV3/CodexPlusPlus · error

Backup source database not found

Error message

Backup source database not found: {}

What it means

backup_source_db reads the source_db path recorded in a backup JSON, falling back to fallback_db_path when absent/blank, and bails if the resolved path is not an existing file. restore_backups needs the original database present on disk to write restored rows back into.

Solutions

  1. Recreate the target database (open codex once so it creates its DB) before restoring the backup.
  2. Fix the backup JSON's source_db (or pass a correct fallback_db_path) to point at the existing database file.
  3. Restore the DB from OS-level backup or copy it back if it was moved; verify with a path existence check before restore.
  4. If restoring from another machine, remap source_db to the local codex home path first.

Example fix

// before
storage.restore_backups(&backup)?; // backup.source_db = "/old/home/state.db" (deleted)
// after
let mut backup = backup.clone();
if !Path::new(backup["source_db"].as_str().unwrap_or("")).is_file() {
    backup["source_db"] = json!(codex_home.join("state").join("threads.sqlite")); // re-anchor to current home
}
storage.restore_backups(&backup)?;
Defensive patterns

Strategy: validation

Validate before calling

let source_db = backup["source_db"].as_str().unwrap_or("");
let resolved = if source_db.trim().is_empty() { &fallback_db_path } else { Path::new(source_db) };
if !resolved.is_file() {
    anyhow::bail!("cannot restore: source db {} is missing; open codex once to recreate it", resolved.display());
}

Type guard

fn backup_source_exists(backup: &Value, fallback: &Path) -> bool {
    let p = backup["source_db"].as_str().filter(|s| !s.trim().is_empty())
        .map(PathBuf::from).unwrap_or_else(|| fallback.to_path_buf());
    p.is_file()
}

Try / catch

match storage.restore_backups(&backup) {
    Ok(()) => println!("restored"),
    Err(e) if e.to_string().starts_with("Backup source database not found") => {
        eprintln!("{e}; recreate the codex db or fix source_db path first");
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Calling restore_backups with a backup whose source_db field points to a deleted/moved database file, or when both source_db is empty and the fallback_db_path doesn't exist on disk.

Common situations: Restoring a backup after the user deleted or relocated the codex DB (e.g. reinstalled codex, moved CODEX_HOME, ran cleanup tools); backup made on another machine with paths that don't exist locally; typo'd db_path configuration.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


AI-assisted analysis of BigPizzaV3/CodexPlusPlus@b1ed92e5e4 (2026-09-19). Data as JSON: /api/errors/86ccf4f76e6140bd. Report an issue: GitHub.

Appendix: source

Thrown at crates/codex-plus-data/src/storage.rs:1001

                insert_row(db, table, row)?;
            }
        }
    }
    Ok(())
}

fn backup_source_db(
    backup: &Value,
    fallback_db_path: &Path,
    allowed_db_paths: &[PathBuf],
) -> anyhow::Result<PathBuf> {
    let source_db = backup["source_db"]
        .as_str()
        .filter(|path| !path.trim().is_empty())
        .map(PathBuf::from)
        .unwrap_or_else(|| fallback_db_path.to_path_buf());
    if !source_db.is_file() {
        anyhow::bail!(
            "Backup source database not found: {}",
            source_db.to_string_lossy()
        );
    }
    let source_db = fs::canonicalize(source_db)?;
    let allowed = allowed_db_paths
        .iter()
        .filter_map(|path| fs::canonicalize(path).ok())
        .any(|path| path == source_db);
    if !allowed {
        anyhow::bail!("Backup source database is not an allowed local storage path");
    }
    Ok(source_db)
}

fn schema_kind(db: &Connection) -> anyhow::Result<Option<SchemaKind>> {
    if has_table(db, "sessions")? && has_columns(db, "sessions", &["id", "title"])? {
        if has_table(db, "messages")? && !has_columns(db, "messages", &["session_id"])? {

View on GitHub (pinned to b1ed92e5e4)