backup method
Online backup: write a consistent SQLite-format snapshot of the
current database to destPath. Acquires the writer arm of the
engine's read/write lock briefly to take the snapshot, then writes
outside the lock so concurrent readers/writers are not blocked
for the duration of the disk I/O.
The destination is written via <dest>.tmp + atomic rename, so
readers of destPath either see the previous file or the new
complete file, never a partial write.
Implementation
Future<void> backup(String destPath, {int pageSize = 4096}) async {
final bytes = await _lock.write(
() async => _buildSqliteBytes(pageSize: pageSize),
);
await _atomicWriteBytes(destPath, bytes);
}