Backup and Restore¶
The backup system protects persistent data -- persistence DB, agent memory, and company configuration -- through automated and manual backups with configurable retention policies and validated restore.
Architecture¶
- BackupService: Central orchestrator coordinating component handlers, manifests, compression, and scheduling
- ComponentHandler protocol: Pluggable interface for backing up and restoring individual data components
PersistenceComponentHandler: SQLiteVACUUM INTOfor consistent point-in-time copiesMemoryComponentHandler:shutil.copytreewithsymlinks=Truefor agent memory data directoryConfigComponentHandler:shutil.copy2for company YAML configuration- BackupScheduler: Background asyncio task for periodic backups with interruptible sleep via
asyncio.Event - RetentionManager: Prunes old backups by count and age; never prunes the most recent backup or
pre_migration-tagged backups
Backup Triggers¶
| Trigger | When | Behavior |
|---|---|---|
| Scheduled | Configurable interval (default: 6h) | Background, non-blocking |
| Pre-shutdown | Company.shutdown() / SIGTERM |
Synchronous, skips compression |
| Post-startup | After config load, before accepting tasks | Snapshot as recovery point |
| Manual | POST /api/v1/admin/backups |
On-demand, returns manifest |
| Pre-migration | Before restore operations | Safety net, automatic |
Restore Flow¶
- Validate
backup_idformat (12-char hex) - Load and verify manifest (structural validation)
- Re-compute and verify SHA-256 checksum against manifest
- Validate component sources (handler-specific checks)
- Create safety backup (pre-migration trigger)
- Atomic restore per component (
.bakrollback on failure) - Return
RestoreResponsewith safety backup ID
Configuration¶
Backup settings live in the backup namespace with runtime editability via BackupSettingsSubscriber:
enabled: Toggle scheduler start/stopschedule_hours: Reschedule interval (1--168 hours)compression,on_shutdown,on_startup: Advisory (read at use time)path: Requires restart (not dispatched)
REST API¶
| Method | Path | Description |
|---|---|---|
POST |
/api/v1/admin/backups |
Trigger manual backup |
GET |
/api/v1/admin/backups |
List available backups |
GET |
/api/v1/admin/backups/{id} |
Get backup details |
DELETE |
/api/v1/admin/backups/{id} |
Delete a specific backup |
POST |
/api/v1/admin/backups/restore |
Restore from backup (requires confirm=true) |
See Also¶
- Persistence -- repository protocol, migrations, schema
- Deployment -- container runtime
- Design Overview -- full index