Function: createDatabaseBackup()
createDatabaseBackup(
dbPath
:string
,fileName
:string
):Promise
<DatabaseBackupResult
>
Defined in: electron/services/database/utils/databaseBackup.ts:109
Creates a backup of the SQLite database by reading the file into a buffer.
Parameters
dbPath
string
Absolute path to the SQLite database file to backup.
fileName
string
= BACKUP_DB_FILE_NAME
Optional custom filename for the backup (defaults to "uptime-watcher-backup.sqlite").
Returns
Promise resolving to a DatabaseBackupResult containing the backup buffer, filename, and metadata.
Remarks
Reads the entire SQLite database file into memory as a Buffer and returns a
structured result with buffer data, filename, and comprehensive metadata.
Uses dynamic import of fs/promises
to minimize startup overhead. Enhanced
error handling for import failures and file operations. Loads the entire
database into memory (suitable for typical database sizes). For very large
databases, consider streaming approaches.
Example
const backup = await createDatabaseBackup("/path/to/database.sqlite");
// backup.buffer contains the database data
// backup.fileName contains "uptime-watcher-backup.sqlite"
// backup.metadata contains operation details
Throws
Re-throws file system errors after logging for upstream handling, including dynamic import failures and file read errors.