backupAsync
external fun backupAsync(sourceDb: DatabaseSync, path: String, options: BackupOptions = definedExternally): ERROR CLASS: Symbol not found for Promise<ERROR CLASS: Symbol not found for js.core.Void>(source)
external fun backupAsync(sourceDb: DatabaseSync, path: Buffer<*>, options: BackupOptions = definedExternally): ERROR CLASS: Symbol not found for Promise<ERROR CLASS: Symbol not found for js.core.Void>(source)
external fun backupAsync(sourceDb: DatabaseSync, path: ERROR CLASS: Symbol not found for URL, options: BackupOptions = definedExternally): ERROR CLASS: Symbol not found for Promise<ERROR CLASS: Symbol not found for js.core.Void>(source)
This method makes a database backup. This method abstracts the sqlite3_backup_init()
, sqlite3_backup_step()
and sqlite3_backup_finish()
functions.
The backed-up database can be used normally during the backup process. Mutations coming from the same connection - same DatabaseSync
- object will be reflected in the backup right away. However, mutations from other connections will cause the backup process to restart.
import { backup, DatabaseSync } from 'node:sqlite';
const sourceDb = new DatabaseSync('source.db');
const totalPagesTransferred = await backup(sourceDb, 'backup.db', {
rate: 1, // Copy one page at a time.
progress: ({ totalPages, remainingPages }) => {
console.log('Backup in progress', { totalPages, remainingPages });
},
});
console.log('Backup completed', totalPagesTransferred);
Content copied to clipboard
Since
v23.8.0
Parameters
sourceDb
The database to backup. The source database must be open.
path
The path where the backup will be created. If the file already exists, the contents will be overwritten.
options
Optional configuration for the backup. The following properties are supported: