can1357/oh-my-pi · error · FileNotFoundError

No backups found in ${dir}

Error message

No backups found in ${dir}

What it means

emergencyRestore() scans the given directory for files matching the backup naming pattern (mnemopi_backup_*.db.gz). If no matching files exist it throws FileNotFoundError naming the directory. It refuses to proceed rather than silently leaving a missing/corrupt database in place.

Source

Thrown at packages/mnemopi/src/dr/recovery.ts:300

				// Preserve the restore failure.
			}
		}
		throw error;
	}
}
export function emergencyRestore(backupDir?: string | null, dbPath?: string | null): EmergencyRestoreResult {
	const paths = getDefaultPaths();
	const dir = backupDir ?? paths.backupDir;
	const targetPath = dbPath ?? paths.dbPath;
	const backups = existsSync(dir)
		? readdirSync(dir)
				.filter(name => /^mnemopi_backup_.*\.db\.gz$/.test(name))
				.sort()
				.reverse()
				.map(name => join(dir, name))
		: [];

	if (backups.length === 0) throw new FileNotFoundError(`No backups found in ${dir}`);

	let attempts = 0;
	for (const backup of backups) {
		attempts += 1;
		try {
			const result = restoreBackup(backup, targetPath);
			if (result.integrity_check) return { restored: true, backup_used: backup, attempts };
		} catch {
			// Try the next backup, matching the Python recovery behavior.
		}
	}
	throw new Error("All backups failed integrity check");
}
export function verifyIntegrity(dbPath?: string | null): boolean {
	const targetPath = dbPath ?? getDefaultPaths().dbPath;
	if (!existsSync(targetPath)) return false;

	let db: Database | null = null;

View on GitHub (pinned to 9690622007)

Solutions

  1. List the directory and confirm mnemopi_backup_*.db.gz files exist; fix the dir path if wrong.
  2. Rename existing backup files to match the expected pattern, e.g. mv backup.db.gz mnemopi_backup_2026-08-31.db.gz.
  3. Generate a new backup with backupDatabase() into the expected directory, then retry.
  4. If no backups exist anywhere, restore from external/offsite copies before running emergencyRestore.

Example fix

// before
await emergencyRestore('/var/data/wrong-dir', dbPath);
// after
import { readdirSync } from 'node:fs';
const dir = '/var/backups/mnemopi';
const hasBackups = readdirSync(dir).some(n => /^mnemopi_backup_.*\.db\.gz$/.test(n));
if (!hasBackups) throw new Error(`No mnemopi backups in ${dir}; check path`);
await emergencyRestore(dir, dbPath);
Defensive patterns

Strategy: validation

Validate before calling

import { existsSync, readdirSync } from 'node:fs';
import { join } from 'node:path';
function findBackups(dir) {
  if (!existsSync(dir)) return [];
  return readdirSync(dir)
    .filter(name => /^mnemopi_backup_.*\.db\.gz$/.test(name))
    .map(name => join(dir, name));
}
if (findBackups(dir).length === 0) {
  throw new Error(`emergencyRestore: no mnemopi_backup_*.db.gz in ${dir}`);
}
await emergencyRestore(dir, targetPath);

Type guard

function hasBackupDir(dir) {
  return typeof dir === 'string' && dir.length > 0 && existsSync(dir);
}

Try / catch

try {
  await emergencyRestore(dir, targetPath);
} catch (err) {
  if (err instanceof FileNotFoundError && String(err).includes('No backups found')) {
    console.error(`Check backup dir (got: ${dir}); expected mnemopi_backup_*.db.gz files`);
  } else throw err;
}

Prevention

When it happens

Trigger: Calling emergencyRestore(dir, targetPath) where dir contains no files matching /^mnemopi_backup_.*\.db\.gz$/ (either the directory is empty/missing or backups were renamed).

Common situations: Pointing emergencyRestore at the wrong directory, backups stored with a custom naming scheme that breaks the regex, backups pruned by a retention job, or a typo in the dir path / wrong environment (staging vs prod).

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/6210c8ae44a6bfe2. Report an issue: GitHub.