Sub topic 10
Checking that the repository is healthy
Assume you can use the Linux command line, SSH, file permissions, and either restic or Borg. You also need access to an initialized repository and its password or key. A successful backup command proves only that one run completed. It does not prove that every repository object can still be read or that a restore will work.
What to check
A healthy repository should pass these checks:
- The tool can open the repository with the expected credentials.
- Repository metadata has no missing or corrupt objects.
- Stored data can be read from the storage backend.
- Recent snapshots or archives contain the paths you expect.
- A test restore produces usable files.
Restic and Borg separate metadata checks from full data verification. Metadata checks are faster and should run regularly. Full verification reads much more data, so schedule it less often.
Run restic checks
Run restic check against the repository. It checks the repository structure and reports errors without changing stored data.
export RESTIC_REPOSITORY=sftp:[email protected]:/srv/restic/myserver
export RESTIC_PASSWORD_FILE=/etc/restic/password
restic check
restic snapshotsFor a deeper check, ask restic to read the stored data. This can take a long time and can consume bandwidth:
restic check --read-dataRecent restic versions can check a subset of data, which is useful for regular sampling:
restic check --read-data-subset=1/10A subset check is not a replacement for a complete check. Run the complete form during a planned maintenance window or according to your recovery policy.
Run Borg checks
Borg checks repository metadata with borg check. The command below does not rewrite the repository:
export BORG_REPO=ssh://[email protected]/./borg/myserver
export BORG_PASSCOMMAND='cat /etc/borg/passphrase'
borg check
borg list ::To verify the contents of stored data, use --verify-data:
borg check --verify-dataThis operation reads archive data and can be expensive. Do not use repair options automatically. A repair attempt can change repository metadata, and you should first preserve logs and investigate the storage or network problem.
| Check | What it tests | Typical frequency |
|---|---|---|
| Metadata check | Repository structure and indexes | Daily or weekly |
| Data verification | Can stored content be read | Weekly or monthly |
| Test restore | Files can be recovered and used | Every backup change or monthly |
Interpret failures
Treat a nonzero exit status as a failed check. Save the command output with your monitoring logs. Common causes include an interrupted upload, damaged storage, a wrong password, expired SSH access, or insufficient disk space.
Do not delete snapshots to hide an error. Confirm that the backup source is still available, check the remote storage, and rerun the check after correcting the cause. If the repository is damaged, restore from another repository copy or storage location according to your disaster recovery plan.
A check is strongest when paired with a restore. Select a small configuration file or directory, restore it into a temporary directory, and compare the result with the expected content.
mkdir -p /tmp/restore-check
restic restore latest --target /tmp/restore-check --include /etc/hostname
test -s /tmp/restore-check/etc/hostnameThe temporary target avoids overwriting live server files.
Exercise
Why should a full data verification be combined with a test restore?
Show answer
Data verification checks whether stored objects can be read. A test restore also checks that the backup can be assembled into usable files at the destination.