tutorial / Nov 27, 2026
Prove a SQLite Backup With a Disposable Restore
Take a consistent SQLite snapshot, verify its integrity, and rehearse a restore away from your live homelab service.

A home server can report that its SQLite backup command exited successfully while the only copy remains unopenable, incomplete, or useless to the application. This drill creates a consistent snapshot, checks it independently, and opens a disposable restore copy without touching the live database. It is written for a single SQLite database used by a self-hosted application; adapt the paths and the application-level query before running it.
Before you start: identify the real database
Find the application's documented data path and confirm the file is SQLite. The examples use /srv/app/data/app.db as the source and /srv/backup-drill as an empty, separate working directory. Replace those paths with your own; do not point the output at the live file or a directory your app manages. You need read access to the source, write access to the drill directory, enough free space for a second database, and the sqlite3 command-line program. If the app runs in Docker, determine whether its database lives in a named volume or bind mount before assuming a host path; Docker's volume documentation describes how volume data is mounted and backed up.
An app may keep configuration, encryption keys, uploads, or companion databases outside this file. This drill verifies one database, not a complete service restore. Record the app version, any migration prerequisites, and a real table plus a non-sensitive record or count that a recovered instance should show. If the application uses PostgreSQL, a remote database, or a vendor-specific store, stop and use its own backup method instead.

Create a consistent snapshot, not a casual file copy
SQLite's online backup API copies a consistent snapshot while other connections can continue using the source. The sqlite3 shell exposes it as .backup, documented in its command reference. This matters when a live database uses write-ahead logging: copying only app.db with a generic file command is not the same procedure as asking SQLite for a snapshot.
- Confirm the source already exists. Run
test -f /srv/app/data/app.dband stop if it fails. Do not letsqlite3quietly create an empty database at a mistyped source path. - Make a private staging directory outside the live application:
mkdir -m 700 -p /srv/backup-drill. Check that/srv/backup-drill/app-snapshot.sqlitedoes not already exist, so this drill does not overwrite an earlier recovery point. - Run
sqlite3 /srv/app/data/app.db ".timeout 5000" ".backup /srv/backup-drill/app-snapshot.sqlite". A busy database may need an application-specific quiet window; a timeout is a failure to investigate, not evidence that a partial output is safe. - Close the shell and confirm the output is a nonempty regular file with
test -s /srv/backup-drill/app-snapshot.sqlite. Keep the live database and any WAL or shared-memory files under the application's control.
A snapshot on the same disk is a useful local recovery point, not an off-device backup. Copy the checked snapshot and its required configuration to a second failure domain using your usual encrypted backup system. A separate directory on the same physical disk cannot protect against disk loss.
Inspect the snapshot before trusting it
Open the snapshot, not the production path: sqlite3 -readonly /srv/backup-drill/app-snapshot.sqlite "PRAGMA integrity_check;". SQLite says a full integrity check returns one row containing ok when it finds no errors; any other result needs investigation. Run sqlite3 -readonly /srv/backup-drill/app-snapshot.sqlite "PRAGMA foreign_key_check;" as a separate test if the application uses foreign keys, because integrity_check does not detect foreign-key errors. A clean foreign-key check returns no rows.
Then inspect a known table or harmless marker: sqlite3 -readonly /srv/backup-drill/app-snapshot.sqlite "SELECT name FROM sqlite_schema WHERE type='table' ORDER BY name LIMIT 10;". Replace that generic listing with an app-specific read-only query before declaring the backup useful. A database with a valid header and empty schema can pass a superficial file-size test but still be the wrong database. Record the expected count or marker from the live application and compare it with the snapshot at the point of capture; concurrent writes can make later live counts differ, so do not compare against an unbounded future state.
Open a disposable restore, not the production volume
- Copy the snapshot to a distinct test path:
cp /srv/backup-drill/app-snapshot.sqlite /srv/backup-drill/restore-test.sqlite. The test path must not be mounted by the production application. - Run
sqlite3 -readonly /srv/backup-drill/restore-test.sqlite "PRAGMA integrity_check;"and repeat the app-specific read-only marker query there. For a complete rehearsal, start a disposable instance of the same app version against this test copy plus the matching configuration and uploads; do not attach it to production endpoints or allow it to send mail, fetch downloads, or run destructive migrations. - Compare the restored instance's expected records or settings with the written recovery checklist. Note the elapsed restore time and any missing dependencies. A successful SQLite check proves structural consistency, not that the service can authenticate, find media, or read its companion files.
Docker users can restore into a new test volume and disposable container rather than overwriting the live volume. Docker documents the archive-and-restore pattern for volumes, but a raw archive of a changing SQLite file is not this SQLite snapshot step; first create the consistent database snapshot, then include it with the other volume data needed for the test.
Test the failure path as deliberately as the allowed path

The allowed path is concrete: the snapshot exists, the integrity result is exactly ok, any foreign-key check is empty, and the application-level marker appears in the disposable restore. Now test a denied path without harming data. Rename only a test copy of the snapshot, then verify that test -s /srv/backup-drill/missing-snapshot.sqlite fails and your drill stops before launching an app against a nonexistent file. Alternatively, use a deliberately wrong table name in a read-only query and require the SQLite error to fail the run. Never deliberately corrupt or delete a production database to demonstrate failure handling.
A script that merely prints a warning and continues after a missing file has not passed this test. Make failures visible to the operator, retain the previous known-good recovery point, and investigate before rotating backups. Store the command results, the app-level marker, the snapshot date, and the location of the off-device copy together; a future restorer needs more than a green dashboard tile.
Troubleshoot and roll back safely
If .backup reports database is locked, check the app's documented maintenance window and permissions, then try again with a new output filename after resolving the contention. Do not promote an incomplete first attempt. If the snapshot fails integrity_check, keep the original untouched, inspect source health and storage, and use the last independently verified backup while diagnosing. If foreign-key checks fail, determine whether the app already contains violations; this check is separate from SQLite's structural result.
If the disposable app cannot start, compare its version, configuration, key material, and external dependencies with the source environment. A database-only snapshot may be insufficient even when SQLite says ok. Rollback here means stop the disposable test instance and leave production running on its original data. Do not copy the test file back into the live directory as a reflex; an actual production restore needs an app-specific outage, a preserved pre-restore copy, and an explicit decision about what changes since the snapshot may be lost.
Verification ledger