Repository navigation
fix(deploy): make the nightly control-db backup work without the sqlite3 CLI - #90
Merged
Merged
Conversation
…te3 CLI The backup timer has failed on every run since it was installed. Its script shells out to `sqlite3 .backup`, and the sqlite3 CLI is not part of a minimal RHEL install: context-guru-backup.sh: line 38: sqlite3: command not found context-guru-backup.service: Main process exited, code=exited, status=127/n/a The unit is a timer-triggered oneshot, so the only symptom was a journal line nobody reads: systemctl reported the timer enabled and firing daily. The control database -- tenants, token hashes, per-tenant configuration, the audit trail, and the one file this script's own header calls irreplaceable -- had never been backed up. Drive SQLite's online-backup API through python3 instead. python3 is already a hard requirement of install.sh and of the proxy's helper scripts, and Connection.backup() is the same API the CLI's .backup calls, so the WAL-safe snapshot property the script was written around is unchanged. Verification now reads the snapshot back through a separate read-only connection, so it checks the file rather than the handle that wrote it. Also preflight the backup's two runtime dependencies. A oneshot that dies at 03:17 with exit 127 is invisible, and 'install.sh preflight' is where a missing tool should surface; it was silent about this one. Verified end to end against the live control database, twice: once to a local target and once to the real remote. Snapshot -> gzip -> rclone -> download -> restore gives 15 tenants, 15 tokens, 62 audit rows, integrity_check ok, user_version 7 preserved. Signed-off-by: Osher-Elhadad <[email protected]>
OsherElhadad
pushed a commit
that referenced
this pull request
Aug 22, 2026
#86 (cache keep-alive), #90 and #89 landed on main and touched the same four files this branch does. Every conflict was two additive changes sharing a line; none had opposed intent, and both sides survive everywhere. dash/schema.go — additiveColumns holds all seven new columns (this branch's cache_ttl, sse_buffered, ttfb_ms plus main's cache_write_1h, keepalive, keepalive_pings, keepalive_saved_usd). schemaVersion stays 6: a bump renames the live database aside and would discard the dashboard's whole request history to gain a column that ALTER TABLE adds in place. dash/store.go — the requests INSERT takes the union of both column lists, with the placeholder count and the Exec argument list widened to match (60 columns, 60 placeholders, 60 values, in order). dash/overview.go — the Overview query appends both sides' aggregates and both sides' Scan targets in the same order (47 and 47): the streaming split, breakpoint placement and coverage counters from here, the keep-alive saving and 1h-write total from main. Filter.where()'s `r.keepalive = 0` exclusion is untouched, so ping rows still stay out of COUNT(*), SUM(cache_read) and the averages. proxy/proxy.go — the per-request defer runs both: main's keeper.record first, on the final round's body, then this branch's SSE accounting to the aggregator and the dashboard row. Still once per client request, not once per upstream round. Signed-off-by: Osher-Elhadad <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The backup has never once succeeded
context-guru-backup.timerreportsenabledand fires daily at 03:17. Every run has failed:The script shells out to
sqlite3 .backup, and thesqlite3CLI is not part of a minimalRHEL install. Because the unit is a timer-triggered oneshot, the only symptom is a journal
line nobody reads —
systemctl list-timersshows a healthy schedule, andis-enabledreturns
enabled.The consequence: the control database has no backup. That is the file this script's own
header calls irreplaceable — tenants, token hashes, per-tenant configuration, and the
config audit trail. The metrics database is explicitly out of scope because it is
derived and self-archives; the control database is not.
This is also why it matters now: three in-flight PRs touch
dash/schema.go, andmigrate()renames the database aside on aschema_versionmismatch. Restoring aworking backup before the next deploy is the point.
The fix
Drive SQLite's online-backup API through
python3rather than the CLI.python3isalready a hard requirement of
install.shand of the proxy's helper scripts, andConnection.backup()is the same online-backup API.backupcalls — so the WAL-safesnapshot property the script was written around is unchanged. Installing the
sqlitepackage would also work, but it adds a host dependency to remove one that is already
satisfied.
Two smaller changes in the same spirit:
so it checks the file rather than the handle that just wrote it.
install.sh preflightnow checks the backup's runtime dependencies (python3,rclone), and only when the backup script is actually installed. A oneshot that diesat 03:17 with exit 127 is invisible; preflight is where a missing tool should surface,
and it was silent about this one.
Evidence
Run end to end against the live control database, twice — once to a local target and
once to the real remote — as the
cgservice user with the unit's own environment.Then downloaded and restored to confirm the artifact is usable, which is the property the
old script claimed and never demonstrated:
bash -nclean on both scripts. No Go code is touched, so the Go suite is unaffected.Notes for the reviewer
KEEP_DAYSageing-out is untouched.chmod 600on the temp snapshot and thetrapcleanup are untouched; the snapshotstill contains token hashes and per-tenant config and is still not world-readable.