Implement Backup and Restore
Backup is not done when the file is written. It is done when restore from that file works.
Backup Steps
- Pause or coordinate writes if your storage layer requires it.
- Create a consistent backup using the platform backup API.
- Include manifest metadata.
- Validate the backup in a separate handle/profile.
- Encrypt if it leaves the device and contains private data.
- Show the user the file location and result.
SQLite Backup Manifest
{
"format": "app-backup",
"formatVersion": 1,
"createdAt": "2026-07-19T10:00:00Z",
"appVersion": "1.8.0",
"databaseUserVersion": 7,
"integrityCheck": "ok",
"tables": {
"transactions": 4182,
"categories": 32
}
}
Restore Steps
- Validate file extension, manifest, and version.
- Open backup read-only when possible.
- Run integrity checks.
- Create a pre-restore backup of current local data.
- Restore into a new database path.
- Swap only after validation passes.
- Rebuild derived indexes.
- Show a clear success or rollback message.
Export vs Backup
Ship both when data matters:
- CSV/JSON export lets users inspect and migrate data manually.
- Full backup preserves complete app state.
- Encrypted backup protects private data in cloud drives or shared folders.