Back up the database nightly with a timer #17

Merged
patrick merged 1 commits from feat/backup-timer into main 2026-10-30 15:06:02 +00:00
Owner

Summary

kernelwatch backup exists but nothing runs it. This adds a nightly timer.

  • kernelwatch scheduled-backup writes kernelwatch-YYYY-MM-DD.db (UTC date,
    mode 0600, directory 0700) into backup_dir, replacing that day's file, then
    deletes dated backups backup_keep_days (default 7) or more days old; 0 keeps
    them all. It deletes only files with exactly that name, and only after the new
    backup succeeded.
  • kernelwatch-backup.timer runs it at ~03:30 (random delay up to 30 min,
    Persistent=true) as the unprivileged kernelwatch user with the alerts
    unit's sandbox plus PrivateNetwork=yes. server/install.sh enables it.
  • New server.toml settings backup_dir and backup_keep_days, validated.
  • README: nightly backups section; notes that the copies live on the dashboard
    host and should be copied elsewhere, and that backup_dir must stay under
    /var/lib/kernelwatch unless the unit gets more write access.

Stacked on #16 (installer tests); merge that first.

Testing

make test: 177 tests pass (11 new): dated private copy and directory creation,
same-day replacement, pruning boundary, only dated files deleted, keep=0, a
failed backup prunes nothing, the live DB is never pruned, CLI success/failure,
config validation, the timer is enabled by the installer, and every command a
unit runs exists in the CLI. I broke the code on purpose (off-by-one, prune
everything, delete non-matching files, no backup) and each was caught.

Not run: the timer on a real host.

🤖 Generated with Claude Code

## Summary `kernelwatch backup` exists but nothing runs it. This adds a nightly timer. - `kernelwatch scheduled-backup` writes `kernelwatch-YYYY-MM-DD.db` (UTC date, mode 0600, directory 0700) into `backup_dir`, replacing that day's file, then deletes dated backups `backup_keep_days` (default 7) or more days old; 0 keeps them all. It deletes only files with exactly that name, and only after the new backup succeeded. - `kernelwatch-backup.timer` runs it at ~03:30 (random delay up to 30 min, `Persistent=true`) as the unprivileged `kernelwatch` user with the alerts unit's sandbox plus `PrivateNetwork=yes`. `server/install.sh` enables it. - New `server.toml` settings `backup_dir` and `backup_keep_days`, validated. - README: nightly backups section; notes that the copies live on the dashboard host and should be copied elsewhere, and that `backup_dir` must stay under `/var/lib/kernelwatch` unless the unit gets more write access. Stacked on #16 (installer tests); merge that first. ## Testing `make test`: 177 tests pass (11 new): dated private copy and directory creation, same-day replacement, pruning boundary, only dated files deleted, keep=0, a failed backup prunes nothing, the live DB is never pruned, CLI success/failure, config validation, the timer is enabled by the installer, and every command a unit runs exists in the CLI. I broke the code on purpose (off-by-one, prune everything, delete non-matching files, no backup) and each was caught. Not run: the timer on a real host. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
patrick added 1 commit 2026-10-30 15:01:49 +00:00
Back up the database nightly with a timer
CI / tests (Python 3.10) (pull_request) Successful in 23s
CI / tests (Python 3.11) (pull_request) Successful in 25s
CI / tests (Python 3.12) (pull_request) Successful in 24s
CI / tests (Python 3.13) (pull_request) Successful in 24s
CI / lint (pull_request) Successful in 3s
4a9bc77a08
kernelwatch scheduled-backup writes kernelwatch-YYYY-MM-DD.db into backup_dir
and prunes dated copies backup_keep_days or older, only after the new backup
succeeded and only files with exactly that name. kernelwatch-backup.timer runs
it at about 03:30 as the unprivileged service user with no network, and
server/install.sh enables it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
patrick merged commit 6652a4d795 into main 2026-10-30 15:06:02 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: patrick/kernel-automation#17