Monitoring snapshots with a heartbeat check (actions + error webhook), tested on 0.23.1

I’m the founder of Watchgoose (cron and heartbeat monitoring), so I have an interest here.

I wanted to know exactly how actions behave when a snapshot fails, since it comes up here a lot (the “Snapshot error action?” and “Understanding Kopia actions” threads, for example). I tested on kopia 0.23.1 with a local filesystem repository. The findings apply to any ping-URL service.

What I found:

  • The after-snapshot-root action runs when the upload finishes, even if files failed to read (kopia printed “Found 1 fatal error(s)” and exited 1). It gets no status variable.
  • It does not run if the snapshot stops before the upload: a failing essential before action, or a missing source path.
  • Actions are essential by default, so a failing curl fails the backup. Add || true.
  • Actions must be enabled: --enable-actions on kopia repository connect, or --force-enable-actions per snapshot.

So the after action is a “finished” signal. For failures, a webhook notification profile with --min-severity=error fired in every failure case I tried.

/usr/local/bin/kopia-watchgoose-start.sh:

#!/bin/sh
curl -fsS -m 10 --retry 3 -o /dev/null https://watchgoose.com/ping/your-check-uuid/start || true

/usr/local/bin/kopia-watchgoose-done.sh:

#!/bin/sh
curl -fsS -m 10 --retry 3 -o /dev/null \
  --data-raw "kopia $KOPIA_VERSION finished $KOPIA_SOURCE_PATH" \
  https://watchgoose.com/ping/your-check-uuid || true
chmod +x /usr/local/bin/kopia-watchgoose-*.sh
kopia policy set /path/to/data --before-snapshot-root-action /usr/local/bin/kopia-watchgoose-start.sh
kopia policy set /path/to/data --after-snapshot-root-action /usr/local/bin/kopia-watchgoose-done.sh
kopia notification profile configure webhook --profile-name=watchgoose-fail \
  --endpoint=https://watchgoose.com/ping/your-check-uuid/fail \
  --method=POST --format=txt --min-severity=error

What arrives:

  • OK snapshot: start, then success.
  • Unreadable file: start, success, then fail with the snapshot report as the body. The check ends up down.
  • Failing before action or missing path: fail.
  • Kopia not running at all: nothing arrives, and the check alerts when it is overdue.

Notes:

  • Kopia sends two notifications per failure, so you’ll see two fail events.
  • Don’t add ?rid=$KOPIA_SNAPSHOT_ID. The snapshot ID is not a UUID, so the ping is rejected.
  • In KopiaUI the action field takes a path without arguments, so keep curl in a script.
  • I only tested the CLI. Server and KopiaUI scheduled snapshots send the same report notification, but I haven’t tested that path.

If you’d rather not use actions, a cron wrapper also works:
kopia snapshot create /path/to/data > /tmp/kopia.log 2>&1; tail -c 10000 /tmp/kopia.log | curl -fsS -m 10 --retry 3 --data-binary @- https://watchgoose.com/ping/your-check-uuid/$?

Watchgoose has a support plan for Open Source maintainers (Open Source Program - Watchgoose). I am happy to answer any questions questions.

Cheers!