Backup and Restore
Kora supports two backup paths:
- Local app backups for a client database, using
app.exportBackup()andapp.importBackup(). - Sync server backups for all synced operations on the server, using the
kora backupCLI.
Use local app backups for user-controlled export/import, desktop app data portability, or support workflows. Use sync server backups for production operations, disaster recovery, and environment migration.
Local App Backups
Every Kora app exposes backup methods after app.ready resolves:
await app.ready
const backup = await app.exportBackup()backup is a Uint8Array containing the operation log and metadata needed to restore the local store.
Download a Backup in the Browser
async function downloadBackup() {
await app.ready
const data = await app.exportBackup()
const blob = new Blob([data], { type: 'application/octet-stream' })
const url = URL.createObjectURL(blob)
const link = document.createElement('a')
link.href = url
link.download = `kora-backup-${Date.now()}.kora`
link.click()
URL.revokeObjectURL(url)
}Restore a Local Backup
async function restoreBackup(file: File) {
await app.ready
const data = new Uint8Array(await file.arrayBuffer())
const result = await app.importBackup(data, {
merge: true,
onProgress(progress) {
console.log(progress.phase, progress.progress)
},
})
console.log(`Restored ${result.operationsRestored} operations`)
}Use merge: true when you want to import without deleting existing local data. Use merge: false when you want the backup to replace the local store.
Export Selected Collections
const backup = await app.exportBackup({
collections: ['projects', 'todos'],
includeRecords: true,
onProgress(progress) {
console.log(progress.message)
},
})Sync Server Backups
For synced apps, back up the server operation log with the CLI:
kora backup create --url http://localhost:3001 --out ./backup.koraIf the server has KORA_BACKUP_TOKEN or KORA_ADMIN_TOKEN configured, pass the token explicitly or expose it in your shell:
kora backup create --url https://sync.example.com --token "$KORA_BACKUP_TOKEN"Restore it later:
kora backup restore ./backup.kora --url http://localhost:3001Merge with existing server data instead of replacing it:
kora backup restore ./backup.kora --url http://localhost:3001 --mergeInspect a backup file before restoring:
kora backup info ./backup.koraThe CLI talks to the sync server backup endpoints:
POST /__kora/backup/exportPOST /__kora/backup/import?merge=true|false
Your sync server must be running and reachable from the machine running the CLI. Production servers should protect backup endpoints with KORA_BACKUP_TOKEN or KORA_ADMIN_TOKEN.
Recommended Practice
- Store server backups outside the application host.
- Test restores regularly against a staging server.
- Keep a backup before running schema migrations or changing sync scopes.
- If sync encryption is enabled, keep encryption keys/passphrases safe. A backup cannot decrypt data without the correct key.
- Treat backup files as sensitive data. They can contain application records and operation history.