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

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>
This commit is contained in:
patrickandClaude Sonnet 5.5 committed 2026-10-30 10:23:45 -04:00
1 parent 3624f0e5d9
commit 4a9bc77a08
10 files changed
+281 -3

No files matched your search

+23
View File
@@ -464,6 +464,7 @@ sudo kernelwatch set-password USER create a user / change password (logs out t
sudo kernelwatch remove-user USER
sudo kernelwatch list-users
sudo kernelwatch backup PATH write a consistent copy of the database (safe while running)
sudo kernelwatch scheduled-backup dated copy in backup_dir, then prune old ones (what the timer runs)
sudo kernelwatch check-alerts check for stale, recovered, reboot and update alerts now
sudo kernelwatch test-alert send a test notification to the configured ntfy topic
```
@@ -486,6 +487,28 @@ destination directory has to be writable by it (create one with
`sudo install -d -o kernelwatch -g kernelwatch -m 0700 /var/lib/kernelwatch/backups`),
then copy the result off the machine with your usual backup tool.
### Nightly backups
`server/install.sh` also enables `kernelwatch-backup.timer`, which runs
`kernelwatch scheduled-backup` at about 03:30 (up to 30 minutes late; a run missed
while the machine was off happens at the next boot). It writes
`/var/lib/kernelwatch/backups/kernelwatch-YYYY-MM-DD.db` (UTC date, mode 0600,
directory 0700) and then deletes dated backups that are `backup_keep_days` (default
7) or more days old. It deletes only files with exactly that name, and only after
the new backup succeeded, so a failing run never costs you the ones you have. Set
`backup_keep_days = 0` to keep them all. The unit can only write under
`/var/lib/kernelwatch`, so keep `backup_dir` there unless you give it more access.
```sh
systemctl list-timers kernelwatch-backup.timer
journalctl -u kernelwatch-backup # a failed run shows up here
sudo systemctl start kernelwatch-backup # back up now
```
These copies sit on the dashboard host, so they protect against a corrupted or
mistakenly changed database but not against losing the machine. Copy
`/var/lib/kernelwatch/backups/` elsewhere with whatever you already back up with.
To restore, stop the service, put the file at `db_path` owned by `kernelwatch`
(mode 0600), and start it again. The stale-alert state restores with it.