Expand description
Single-file backup and restore for the libSQL database.
Backup uses VACUUM INTO, which writes a fully-checkpointed, consistent
snapshot to a brand-new file with no -wal/-shm sidecars, regardless of
the live database’s journal mode. Restore validates the snapshot, takes a
safety backup of the current database, swaps the file into place atomically,
and then deletes any stale WAL sidecars — left behind they would be replayed
onto the restored file and corrupt it.
Hardening: both operations hold an exclusive lock file so a concurrent
backup/restore (or a running MCP server doing the same) can’t race; snapshots
are written 0600 (dir 0700) since the graph may hold secrets; every
snapshot is PRAGMA integrity_check-verified before it is trusted; and the
default backup directory is pruned to the most recent keep snapshots.
Functions§
- backup
- Snapshot the live database to
output(or a timestamped default in the managed directory) viaVACUUM INTO, verify its integrity, and — when using the default location — prune to the newestkeepsnapshots. Returns the path written. Refuses to overwrite an existing file. - effective_
db_ path - The live database file the CLI operates on:
MIKU_DATABASE_URLif set, otherwise the resolved workspacedb_path(). Backup and restore both go through this so they always target the same file ascrate::db::init_db. - restore
- Replace the live database with
source. Consumes the opendb/connso the connection is fully closed (and the WAL flushed) before the file is swapped.