# Operations [← kernelwatch](../README.md) Day-to-day tasks: querying the fleet from a script, and backing up the database. ## Scripting: `kernelwatch status` `kernelwatch status` prints the fleet the way the dashboard shows it, from the database, with no network port or token involved. It needs `sudo`, like the other [admin commands](server.md#admin-commands). Run it over SSH from anywhere else. ``` $ sudo kernelwatch status stale new01 ? (last seen never) - never reported reboot web01 6.8.0-136 -> 6.8.0-138 (last seen 1m ago) - kernel: running 6.8.0-136, 6.8.0-138 installed - 2 security updates pending ok db01 6.12.57 (last seen 1m ago) 3 hosts: 1 stale, 1 reboot, 0 update, 1 ok ``` Hosts come worst first, in the dashboard's order, and use the same status logic (Livepatch cover, the hostname note and so on). Narrow it with `--host NAME` and `--level stale|reboot|update|ok` (repeatable); both also work with `--json`. `--json` is for scripts. It has `generated_at`, `counts` and `hosts`. The counts always cover the whole fleet, and the filters only trim `hosts`. Each host has `name`, `status`, `reasons`, `last_report_at` (UTC ISO 8601, or `null` if it never reported), `last_report_age_seconds`, `os`, `kernel_running`, `kernel_newest_installed`, `reboot_required`, `updates_pending`, `security_updates`, `kernel_updates`, `services_need_restart`, `livepatch` (or `null`), `uptime_seconds` and `agent_version`. Fields a host hasn't reported are `null`, and the keys are always present. It never includes tokens or password hashes. ```sh # hosts that need a reboot sudo kernelwatch status --json | jq -r '.hosts[] | select(.status=="reboot") | .name' # one line per host that needs attention, with the reasons sudo kernelwatch status --json --level reboot --level update | jq -r '.hosts[] | "\(.name): \(.reasons | join("; "))"' # from your workstation; exits non-zero (for cron or a monitor) if any host is stale ssh triton 'sudo kernelwatch status --json' | jq -e '.counts.stale == 0' >/dev/null ``` There's deliberately no HTTP endpoint for this. It would expose every host's kernel and pending security updates to anything holding a token, and nothing needs it yet. If something has to poll remotely, add one behind your proxy's IP allow-list rather than relying on a token alone. ## Backups Everything kernelwatch knows lives in one SQLite file, `/var/lib/kernelwatch/kernelwatch.db`: host tokens (hashed), dashboard logins and report history. Without it you'd re-register every host and reinstall its token. Don't copy the file while the server runs, since recent writes can sit in its `-wal` sidecar. Use: ```sh sudo kernelwatch backup /var/lib/kernelwatch/backups/kernelwatch.db ``` This uses SQLite's online backup, so it's safe while hosts are reporting. It replaces any existing file at that path and writes it mode 0600. It refuses to overwrite the live database. The command runs as the `kernelwatch` user, so the 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 ``` If a run fails, whether from an error, the 10-minute timeout, an out-of-memory kill or a crash, systemd starts `kernelwatch-backup-failed.service` (`OnFailure=`), which sends a high-priority message to your ntfy topic naming the newest backup still on disk. The cause is in `journalctl -u kernelwatch-backup`. Without `ntfy_url` it only logs that it had nothing to send to. If ntfy itself is unreachable at that moment, the failure shows up only in the journal (`journalctl -u kernelwatch-backup-failed`). It can't tell you that the timer never ran at all, for example because the host was down; that needs a [heartbeat monitor](alerts.md#heartbeat-is-kernelwatch-itself-running). You can check delivery with `sudo kernelwatch notify-backup-failure`, which sends the same message. 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.