Schedule icon
Webhook icon
Commands icon
Docker icon
If icon
Fail icon
Set icon
SlackIncomingWebhook icon
Pause icon

Daily restic Restore Drill with RPO, Integrity and Checksum Checks

Prove restic backups restore. Snapshot age against RPO, check --read-data-subset, a sample restore compared by sha256, stale locks, and approved pruning.

Categories
Infrastructure

restic backups fail quietly. The cron job stops writing snapshots, a pack file rots on the storage, a backup dies and leaves a lock that blocks the next run, or the files restore but are not the files you backed up. restic check alone does not read your data, and restic snapshots does not tell you whether a restore works.

This blueprint runs a real restore drill every day and posts the result.

How it works

  1. drill (restic in Docker):
    • opens the repository and takes the newest snapshot (optionally for one host or tag);
    • lists the repository locks, then runs restic unlock, which removes only stale locks: restic refreshes a live lock every 5 minutes, so one not refreshed for 30 minutes belongs to a process that died;
    • runs restic check --read-data-subset. The default rotate reads one seventh of the pack files each day, chosen by the weekday, so every pack is read once a week. check waits up to lock_wait for a backup that is still running;
    • restores sample_files random files with restore --verify and, when source_root is set, compares each with the source by sha256. Files changed since the snapshot are skipped, not reported.
  2. rpo_check fails the drill when the newest snapshot is older than rpo_hours. The age is computed in Kestra from restic's timestamp.
  3. remember_good_drill writes the time and snapshot to the KV store; every failure message quotes the last good drill.
  4. retention (only with forget_policy, and only after a passing drill) previews restic forget and asks for approval before forget --prune.

Error handling

These are the messages from the tests:

  • Stale snapshot: "the newest snapshot 31aaec18 is 50.0 h old, over the 26 h RPO. The repository itself is readable; the backup job is not producing snapshots."
  • Corrupted pack: "restic check found a problem in subset 100%: pack 2c525e71… contains 2 errors: … ciphertext verification failed".
  • Wrong password: "cannot open the repository: Fatal: wrong password or no key found".
  • Stale lock (a backup that died 2 hours ago): removed, and the drill passed and named the host and PID that held it.
  • Live lock: a running backup is waited for; after lock_wait the drill fails with who holds the lock and since when, and the lock is left alone.
  • Backend down: restic retries an unreachable backend for many minutes, so the drill gives up after connect_timeout_seconds and quotes the connection error.
  • Restored bytes differ from the source although size and mtime are unchanged (bit rot on the source or the backup): the file and both checksums are named.
  • A failing drill never prunes.
  • One run at a time. concurrency (limit 1, QUEUE) makes a new run wait while another one waits for approval; answer or kill the waiting run first.

What this blueprint teaches about Kestra

  • Shell script outputs (::{"outputs":...}::) read by later tasks. The snapshot time feeds an If that computes the snapshot's age with the timestamp filter.
  • Ternaries around secret(), so demo mode needs no repository secrets.
  • Pause with a BOOL onResume input, as an approval step for a destructive operation (prune) that only runs after the checks pass.
  • Schedule plus Webhook: a daily drill, and an immediate one at the end of each backup job.

Prerequisites

  • A restic repository on any backend restic supports (S3, B2, SFTP, rest-server, local).
  • A Kestra worker that can run Docker containers.
  • For the source comparison, the backed-up paths mounted read-only into the drill container (Docker runner volumes, which needs volume-enabled: true in the Docker runner's plugin configuration).

Secrets

  • RESTIC_REPOSITORY: e.g. s3:s3.amazonaws.com/bucket/restic or rest:https://user:pass@backup:8000/host1.
  • RESTIC_PASSWORD: the repository password.
  • SLACK_WEBHOOK_URL.
  • RESTIC_DRILL_WEBHOOK_KEY: a long random string for the webhook your backup job calls.
  • For S3 or B2, add the backend's credentials to the env of the drill task the same way (for example AWS_ACCESS_KEY_ID).

Inputs

  • mode: demo (default; a local repository inside the container) or repository.
  • host, tag: optional snapshot filters.
  • rpo_hours (26), read_data_subset (rotate, or e.g. 5%, 2/10), sample_files (20), source_root, lock_wait (10m), connect_timeout_seconds (120).
  • forget_policy (e.g. --keep-daily 7 --keep-weekly 5), approval_timeout (PT8H), restic_image (restic/restic:0.19.1).

Outputs

  • result (JSON): snapshot id and time, files in the snapshot, the subset read, files restored and compared, restore seconds, stale locks removed.

Quick start

  1. Add SLACK_WEBHOOK_URL and run the flow. The demo backs up generated files, then checks, restores and compares 20 of them: "restic restore drill PASSED (demo) … 20 match the source by sha256".
  2. Add RESTIC_REPOSITORY and RESTIC_PASSWORD, switch mode to repository, and set host / tag to the backup you want to drill.
  3. Enable daily_drill, or call the webhook at the end of the backup job.

How to extend

  • Drill several repositories: call this flow from a parent flow with a Loop over your hosts.
  • Store restore_seconds per day and alert when restores get slower.
  • Run restic check --read-data (100%) monthly with a second Schedule.

Plugins used

See How

New to Kestra?

Use blueprints to kickstart your first workflows.