Skip to content

Hooks

A volume can declare a per-volume hook — a command the agent runs to nudge an external tool when the volume’s content changes. Squirrel stays tool-agnostic: it never learns what the command does (a backup with kopia/restic, an rclone copy, a shell script — all the same to squirrel). It exec’s the command without a shell, passes context through environment variables, and records only the generic outcome (exit code, timestamps).

[volumes.pictures.hook]
command = ["kopia", "snapshot", "create", "."]
timeout = "30m" # optional, defaults to 1h
interval = "24h" # optional — also fire on this cadence (see below)

A hook fires on two triggers, both reusing the same command:

  • on change — after every successful index run on the volume (which the agent runs on the index_every / sync_every cadence). This answers “is the latest content backed up?”. It keys off content settling, not a sync to a remote, so a volume needs no sync_to destination for the hook to be useful.
  • on interval — every interval, regardless of whether anything changed. This answers “is the existing backup still intact?”. Verification is orthogonal to change — bitrot happens to static data — so re-checks have to run on a clock. Omit interval to fire on-change only.

The command tells the two triggers apart via SQUIRREL_TRIGGER, so a single command can back up on change and verify on interval:

VariableMeaning
SQUIRREL_VOLUMEvolume name
SQUIRREL_PATHabsolute volume path
SQUIRREL_RUN_IDthe index run that triggered the hook (empty on the interval trigger)
SQUIRREL_CHANGEDtrue/false — whether the run observed changes (so the command can cheaply no-op); always false on the interval trigger
SQUIRREL_TRIGGERchange or interval

Because the command is exec’d without a shell, the volume path is never string-concatenated into a command line. If you want shell features, make the command ["sh", "-c", "…"] yourself.

A hook is best-effort: a hook failure or timeout never fails or blocks the run that triggered it, and overlapping invocations for the same volume are skipped rather than stacked.

Recorded outcomes are visible via squirrel hooks and the TUI’s Hooks tab:

Terminal window
squirrel hooks
squirrel hooks --volume pictures --limit 5