Implement Backup and Restore

Backup is not done when the file is written. It is done when restore from that file works.

Backup Steps

  1. Pause or coordinate writes if your storage layer requires it.
  2. Create a consistent backup using the platform backup API.
  3. Include manifest metadata.
  4. Validate the backup in a separate handle/profile.
  5. Encrypt if it leaves the device and contains private data.
  6. 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

  1. Validate file extension, manifest, and version.
  2. Open backup read-only when possible.
  3. Run integrity checks.
  4. Create a pre-restore backup of current local data.
  5. Restore into a new database path.
  6. Swap only after validation passes.
  7. Rebuild derived indexes.
  8. 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.