db.backup

SQLite backup/export/restore helpers for the webapp database.

These utilities provide safe, deterministic file-level operations for the webapp SQLite database. They intentionally avoid HTTP concerns and focus on filesystem + SQLite behavior only.

Classes

BackupResult

Summary metadata returned after a backup or export.

RestoreResult

Summary metadata returned after a restore/import operation.

Functions

backup_database(db_path, *[, output_path, overwrite])

Create a point-in-time backup of the webapp database.

export_database(db_path, *, output_path[, overwrite])

Export the database to a file path.

restore_database(db_path, *, import_path[, overwrite, ...])

Restore the webapp database from an existing SQLite file.

Module Contents

class db.backup.BackupResult

Summary metadata returned after a backup or export.

path: pathlib.Path
bytes_written: int
sha256: str
created_at: str
class db.backup.RestoreResult

Summary metadata returned after a restore/import operation.

restored_path: pathlib.Path
bytes_written: int
sha256: str
created_at: str
backup_path: pathlib.Path | None = None
db.backup.backup_database(db_path, *, output_path=None, overwrite=False)

Create a point-in-time backup of the webapp database.

Parameters:
  • db_path (pathlib.Path) – Source SQLite database to back up.

  • output_path (pathlib.Path | None) – Optional destination file. When omitted, a timestamped sibling file is created next to db_path.

  • overwrite (bool) – When True, allow replacing an existing file.

Returns:

BackupResult with the path and content hash of the backup.

Return type:

BackupResult

db.backup.export_database(db_path, *, output_path, overwrite=False)

Export the database to a file path.

This is a convenience wrapper over backup_database() that keeps the naming explicit for API users.

db.backup.restore_database(db_path, *, import_path, overwrite=False, create_backup=True, backup_path=None)

Restore the webapp database from an existing SQLite file.

Parameters:
  • db_path (pathlib.Path) – Destination database path used by the webapp.

  • import_path (pathlib.Path) – Existing SQLite file to restore from.

  • overwrite (bool) – When True, allow replacing an existing destination DB.

  • create_backup (bool) – When True and the destination exists, create a timestamped backup first.

  • backup_path (pathlib.Path | None) – Optional explicit backup path used when create_backup is enabled.

Returns:

RestoreResult with the restored DB path and optional backup path.

Return type:

RestoreResult