Skip to content

Detect missing restic repositories by exit code and add destination check - #153

Open
kasparsd wants to merge 2 commits into
mainfrom
fix/backup-destination-probe
Open

kasparsd wants to merge 2 commits into
mainfrom
fix/backup-destination-probe

Conversation

@kasparsd

Copy link
Copy Markdown
Contributor

Fixes the backup findings from a real migration to a restic rest-server destination over WireGuard.

What was wrong

  • _control was never created on a REST destination. Control's backup only ran restic init when stderr matched a regex that does not cover the REST wording (<config/> does not exist), so the nightly control backup failed forever.
  • A mistyped S3 bucket could be created. The agent job used a much looser regex (does not exist) that also matches bucket does not exist, and restic init creates the bucket.

Both now use one classifier based on restic's exit code: 10 means the repository does not exist (restic 0.17+), and anything else is an error. I checked this against real backends with restic 0.19.1. A rest-server missing repository and an S3 missing key both exit 10. An S3 missing bucket keeps retrying and never exits 10.

Changes

  • src/backup/repository-probe.ts: the shared classifier and failure wording (wrong password, restic older than 0.17).
  • tug backup destination check (POST /api/v1/backup/destination/check, admin). From control's host it probes _control and every project with enabled backup targets, creates missing repositories (which proves write access), and stores the result in the existing checked_at/check_result_json columns. destination set runs it unless you pass --no-check.
  • The agent's backup.check job is now read-only and reports missing instead of initializing. This is an additive protocol value.
  • Destinations accept b2:, azure:, gs: and swift:. sftp: and rclone: are rejected with the reason.
  • tug backup password works before the first deploy (the password is derived from the name) and warns when the project is not deployed. backup run explains that targets come from the deployed Compose file.
  • Docs: a Destinations section (REST server credentials, plain HTTP on a private network, other backends marked unexercised), the check, migrating from an existing restic repository, and monitoring with backup list --check.

Verification

  • npm run typecheck, npm run lint (0 errors) and npm test: 1207 of 1207 pass.
  • checkRepository run against a real rest-server --no-auth with restic 0.19.1: an empty _control returns initialized, a second run returns ok, and a wrong password returns wrong repository password (restic exit code 12).
  • Not run: QEMU/real-host suites; B2, Azure, GCS and Swift against real accounts.

🤖 Generated with Claude Code

kasparsd and others added 2 commits November 20, 2026 15:26
…heck

restic exits with 10 only when the repository does not exist. Using that instead of matching stderr fixes control never creating `_control` on a rest-server destination, and stops a mistyped S3 bucket from being created by `restic init`.

- `tug backup destination check` probes `_control` and every project with backup targets from control's host, creating missing repositories, and stores the result; `destination set` runs it unless `--no-check`
- destinations accept b2:, azure:, gs: and swift:; sftp: and rclone: are rejected with the reason
- `tug backup password` works before the first deploy and warns when the project is not deployed
- docs for REST servers, the other backends, the check and migrating from an existing restic setup

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- the old-restic hint needs a known restic version below 0.17, since 0.19 adds the same stderr line to every failure
- a failed `_control` skips the project repositories and the check stops after 4 minutes, under the CLI's 300 s limit
- `destination set` exits 0 after a successful save and warns on a failed check or a control without the check route
- per-repository wording says where the check ran and calls a created repository new and empty
- the check and control's own backup never run together; a result is stored only for the destination it checked
- changesets and migration docs spell out the restic 0.17 floor, rejected sftp/rclone and copying old snapshots

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant