DatabaseBackupService

Copies a device database out to a user-chosen sink, and stages a validated backup to replace it the next time that database is opened. A restore is never applied to an open database.

Constructors

Link copied to clipboard
constructor(manager: DatabaseManager, dispatchers: CoroutineDispatchers)

Functions

Link copied to clipboard
open suspend override fun backupTargetName(): String?

The device database to act on: the active one, or the last device's when none is selected. Null when no device database exists. Capture it before anything switches databases.

Link copied to clipboard
open suspend override fun export(dbName: String, sink: BufferedSink): Long

Snapshots dbName with VACUUM INTO, then streams the snapshot into sink. Returns the bytes written.

Link copied to clipboard
open suspend override fun stageRestore(dbName: String, source: BufferedSource): RestoreStageResult

Streams source beside the database dbName, checks it with SQLite, then atomically renames it into place as the staged restore. Nothing the live database reads changes.