# The backup that hid a partial snapshot

A backup wrapper prints success, but one synthetic file is missing from the
snapshot. Investigate restic's real exit status, correct the wrapper, and
restore a complete snapshot without raising backup privileges.

## Before you begin

Use a disposable Linux environment with Bash, Python 3, restic and util-linux
(`unshare` and `setpriv`). Unprivileged user namespaces must be enabled. Work
on a private Linux filesystem with normal Unix permissions; shared or mounted
filesystems that ignore permission bits are unsuitable.

The lab creates a local restic repository and synthetic files in `.lab-state`.
The fixed repository password is public and **not suitable for real backups**.
Never put real data there. The backup runs in a user namespace with DAC
override and read-search capabilities removed, so the unreadable file remains
unreadable even when the lab is launched by root. No host mounts or system
permissions are changed.

## Investigate

```sh
./setup.sh
./lab.sh inspect
./lab.sh snapshots
./lab.sh contents
```

Compare the wrapper's success message with the actual restic status, then
inspect `backup.sh` and the synthetic file permissions. Make the wrapper
return a nonzero exit for **every** failed restic run, including a partial
backup, and allow the lab user to read the file. Do not change the synthetic
file contents or run with extra privileges.

```sh
./lab.sh backup
./verify.sh
./teardown.sh
```

Verification creates an additional partial snapshot while checking failure
handling, checks a wrong-password failure, then creates a complete snapshot.
It also tests how the wrapper handles simulated nonzero exit statuses.
It restores that snapshot into a new temporary directory, compares both files,
and runs `restic check --read-data`. Teardown removes the lab repository and
synthetic data after checking the state marker and host mounts; configuration
edits remain. Re-extract the archive to reset the exercise.

The [related restore runbook and demo](https://opsbreakfix.com/devops/test-a-backup-restore-before-you-need-it/#see-it-run)
show a real partial restic backup and restore check. The lab uses an isolated
namespace to make the permission failure reproducible.
