Skip to content

fix(deploy): make the nightly control-db backup work without the sqlite3 CLI - #90

Merged
OsherElhadad merged 1 commit into
mainfrom
fix/backup-sqlite3-0822
Aug 22, 2026
Merged

OsherElhadad merged 1 commit into
mainfrom
fix/backup-sqlite3-0822

Conversation

@OsherElhadad

Copy link
Copy Markdown
Collaborator

The backup has never once succeeded

context-guru-backup.timer reports enabled and fires daily at 03:17. Every run has failed:

context-guru-backup.sh: line 38: sqlite3: command not found
context-guru-backup.service: Main process exited, code=exited, status=127/n/a
context-guru-backup.service: Failed with result 'exit-code'.

The script shells out to sqlite3 .backup, and the sqlite3 CLI is not part of a minimal
RHEL install. Because the unit is a timer-triggered oneshot, the only symptom is a journal
line nobody reads — systemctl list-timers shows a healthy schedule, and is-enabled
returns 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, and
migrate() renames the database aside on a schema_version mismatch. Restoring a
working backup before the next deploy is the point.

The fix

Drive SQLite's online-backup API through python3 rather than the CLI. python3 is
already a hard requirement of install.sh and of the proxy's helper scripts, and
Connection.backup() is the same online-backup API .backup calls — so the WAL-safe
snapshot property the script was written around is unchanged. Installing the sqlite
package would also work, but it adds a host dependency to remove one that is already
satisfied.

Two smaller changes in the same spirit:

  • Verification now reads the snapshot back through a separate read-only connection,
    so it checks the file rather than the handle that just wrote it.
  • install.sh preflight now checks the backup's runtime dependencies (python3,
    rclone), and only when the backup script is actually installed. A oneshot that dies
    at 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 cg service user with the unit's own environment.

backup: box:context-guru/backup/cg-control-20260822T041736Z.db.gz uploaded (15 tenants)
EXIT=0

Then downloaded and restored to confirm the artifact is usable, which is the property the
old script claimed and never demonstrated:

remote object: cg-control-20260822T041736Z.db.gz  14320 bytes  2026-08-21T21:17:42-07:00
RESTORE CHECK -> tenants: 15 | tokens: 15 | audit: 62 | integrity: ok | user_version: 7

bash -n clean on both scripts. No Go code is touched, so the Go suite is unaffected.

Notes for the reviewer

  • The restore procedure in the script's header comment is unchanged and still correct.
  • KEEP_DAYS ageing-out is untouched.
  • The chmod 600 on the temp snapshot and the trap cleanup are untouched; the snapshot
    still contains token hashes and per-tenant config and is still not world-readable.
  • This does not change what is backed up, only whether the backup runs at all.

…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
OsherElhadad merged commit c789112 into main Aug 22, 2026
4 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Aug 22, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant