can1357/oh-my-pi · error · Error
Unable to allocate unique backup path in
Error message
Unable to allocate unique backup path in ${destinationDir} What it means
writeBackupFile tries repeatedly to find a non-existing backup filename (with unique suffix tokens) via exclusive create; if every attempt collides with EEXIST it exhausts its attempts and throws this Error. It effectively means the backup directory is full of colliding names or the uniqueness scheme failed.
Solutions
- Clean up old backup files from destinationDir and retry the backup
- Use a fresh/empty backup directory (pass backupDir to createBackup)
- Increase spacing between backup runs or include more entropy in filenames
Example fix
// before
createBackup(dbPath, "/var/backups/mnemopi"); // thousands of stale files
// after
fs.rmSync("/var/backups/mnemopi", { /* prune files older than N days */ });
createBackup(dbPath, "/var/backups/mnemopi"); Defensive patterns
Strategy: retry
Try / catch
try {
const result = createBackup(dbPath, backupDir);
} catch (err) {
if (err.message.startsWith("Unable to allocate unique backup path")) {
pruneOldBackups(backupDir, { keep: 10 });
const result = createBackup(dbPath, backupDir);
}
} Prevention
- Rotate/prune old backups regularly
- Use distinct backup directories per run or per environment
- Avoid backing up many times per second into the same directory
- Monitor backup directory file counts
When it happens
Trigger: Many backups within the same timestamp window exhausting the unique-token attempts; a destinationDir stuffed with thousands of files from prior runs; a filesystem where exclusive-create semantics misbehave; extremely long backup filenames plus busy directory causing persistent collisions.
Common situations: Cron jobs writing backups every second into one directory; archived backup dirs migrated onto systems that preserved all files; clock skew producing identical timestamps with exhausted random tokens.
Related errors
- archive artifacts destination exists
- archive destination exists
- archive destination exists
- backing up might destroy source; not moved
- Database not found
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/938a8183ae7ff9a2.
Report an issue: GitHub.
Appendix: source
Thrown at packages/mnemopi/src/dr/recovery.ts:123
typeof error === "object" &&
"code" in error &&
(error as { readonly code?: unknown }).code === code
);
}
function writeBackupFile(destinationDir: string, timestamp: string, bytes: Uint8Array): string {
for (let attempt = 0; attempt < 64; attempt += 1) {
const suffix = attempt === 0 ? "" : `_${nextUniqueToken()}`;
const backupPath = join(destinationDir, `mnemopi_backup_${timestamp}${suffix}.db.gz`);
try {
writeFileSync(backupPath, bytes, { flag: "wx" });
return backupPath;
} catch (error) {
if (hasErrorCode(error, "EEXIST")) continue;
throw error;
}
}
throw new Error(`Unable to allocate unique backup path in ${destinationDir}`);
}
function restoreTempPath(targetPath: string): string {
return join(dirname(targetPath), `.${basename(targetPath)}.${process.pid}.${nextUniqueToken()}.restore.tmp`);
}
function defaultBackupDir(env: Env = process.env): string {
const explicit = env.MNEMOPI_BACKUP_DIR;
if (explicit !== undefined && explicit.length > 0) return explicit;
const dir = configuredDataDir(env);
return join(dirname(dir), "backups");
}
export function getDefaultPaths(env: Env = process.env): RecoveryPaths {
return {
dataDir: configuredDataDir(env),
backupDir: defaultBackupDir(env),
dbPath: configuredDbPath(env),View on GitHub (pinned to 9690622007)