#20877: Store config backups in their own directory
size: S
Cluster:
Wizard Enhancements and Config Fixes
Config backup files were piling up directly in the .openclaw/ directory (openclaw.json.bak.1, .bak.2, etc). This moves them into a dedicated .openclaw/config-backup/ subdirectory and switches to datetime-based naming like openclaw.json.bak.2026-02-18T14-37-28.123Z.
Changes:
- backup-rotation.ts: new helpers to resolve backup dir/path, pruning now works with datetime-sorted files in the subdirectory
- io.ts: creates the config-backup/ dir and copies backups there instead of alongside the config
- Updated tests to match the new behavior
Keeps the same max backup count (5). Old numbered backups in .openclaw/ won't be cleaned up automatically but they can be deleted manually.
Fixes #20460
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Moves config backups from `.openclaw/` to `.openclaw/config-backup/` with datetime-based naming (`openclaw.json.bak.2026-02-18T14-37-28.123Z` instead of `.bak.1`, `.bak.2`, etc).
- New helper functions `resolveConfigBackupDir()` and `resolveConfigBackupPath()` encapsulate backup path logic
- Backup rotation now creates the subdirectory and prunes datetime-sorted files
- Tests updated to verify datetime naming and max backup count
- Log messages updated to reference the new backup directory
**Issue found**: The pruning logic has an off-by-one error on line 50 of `backup-rotation.ts`. The expression `backups.length - maxExisting + 1` removes one too many files, resulting in only 4 backups being kept instead of the intended 5 (`CONFIG_BACKUP_COUNT`).
<h3>Confidence Score: 2/5</h3>
- Has a logical error that prevents correct backup rotation behavior
- The off-by-one error in the pruning logic means the PR doesn't deliver on its promise to "keep the same max backup count (5)". While the test passes (it only checks `<= 5`), the actual behavior keeps only 4 backups. The rest of the refactoring (directory structure, datetime naming) is well-implemented, but this bug affects the core rotation logic.
- src/config/backup-rotation.ts line 50 requires correction to maintain 5 backups as intended
<sub>Last reviewed commit: cef6a59</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#13988: feat(backup): add backup/restore CLI with local + S3 storage
by n24q02m · 2026-02-11
78.1%
#21931: feat(config): auto-rollback to last known-good backup on invalid co...
by Protocol-zero-0 · 2026-02-20
76.1%
#11602: fix(config): skip stale legacy config files when openclaw.json exists
by akoscz · 2026-02-08
75.1%
#21994: Config: load valid backup when primary config is invalid
by islavutin · 2026-02-20
73.7%
#6697: Config: move backups into backups folder
by BrennerSpear · 2026-02-01
73.5%
#12368: fix(cron): respect OPENCLAW_STATE_DIR for cron store path
by ComBba · 2026-02-09
72.2%
#19484: Fix cron store backup churn
by guirguispierre · 2026-02-17
71.9%
#19650: [AI-assisted] feat: add encrypted S3-compatible backup system
by as3445 · 2026-02-18
71.6%
#19867: Logging: Add configurable log dir
by paudav · 2026-02-18
71.1%
#23779: fix(config): auto-repair invalid config keys from backup on load
by cintia09 · 2026-02-22
70.3%