Docs / Surfaces / Databases / SQLite

SQLite

SafeGrd backs up a SQLite file on the host, WAL mode included, with nothing else to install. This page covers a one-off backup, a scheduled surface, and restoring the file.

# a database file on this host; no client tools needed
safegrd backup --database-url sqlite:///var/lib/app/app.db --retention-days 14

That is one backup, now. For backups on a schedule, with Fire Drills, name the file as a surface in ~/.safegrd/config.yaml and run the daemon. Pick one of the two for a database: a surface starts its own history, so backups taken with --database-url before it show in the console as a separate surface.

# ~/.safegrd/config.yaml
surfaces:
  - id: app-db
    type: sqlite
    database_url: sqlite:///var/lib/app/app.db
    schedule: 6h
# check it, then run it as a service
safegrd config validate && safegrd daemon install

A file copied off the disk while the app writes can be torn, and in WAL mode the newest transactions are still in the -wal file, which a copy of the database file misses. SafeGrd copies the database through SQLite itself, inside one read transaction: every committed transaction is in the copy, the WAL's included, and writers carry on. SQLite WAL mode and backups shows the difference on a test database.