Sub topic 8
Browsing and restoring files
A backup is only useful if you can get the data back. This chapter covers how to find the right snapshot or archive, look inside it, and restore a single file or a whole directory without damaging the running server.
This chapter assumes you have a repository with at least one backup, and that RESTIC_REPOSITORY and RESTIC_PASSWORD_FILE (or BORG_REPO and BORG_PASSCOMMAND) are set in your shell, as in the earlier chapters.
The restore workflow
Every restore follows the same four steps, regardless of tool.
Restoring into a scratch directory first costs little and prevents a common mistake: overwriting a newer, good file with an older one.
Finding the right snapshot
With restic, restic snapshots lists every snapshot with its ID, time, host, and paths. The special name latest refers to the newest snapshot. On a repository shared by several servers, latest means the newest snapshot from any host, so filter it:
restic snapshots --host myserver --path /etc
restic ls latest --host myserver /etc/nginxWith Borg, each backup is an archive with a name you chose at creation time. borg list :: prints archive names and timestamps. The :: form means "the repository in BORG_REPO".
borg list ::
borg list --short ::The timestamped names from the earlier chapter, such as myserver-2026-11-27T02:00:00, make it easy to pick the archive from the day before an incident.
Looking inside a backup
Listing contents is cheap. It reads only metadata, not file data.
restic ls latest /etc/nginxThis prints the entries under /etc/nginx in the newest snapshot. Add --long for sizes, owners, and modes.
Borg lists the contents of one archive by naming it:
borg list '::myserver-2026-11-27T02:00:00' etc/nginxNotice the difference in paths. restic stores absolute paths (/etc/nginx). Borg 1.x strips the leading slash (etc/nginx). Borg path arguments to list and extract are written without the leading slash.
Finding a file you can't locate
If you don't know which snapshot holds a file, search across them.
restic find 'nginx.conf'
restic find --snapshot 4f2a9c1d '*.conf'restic find reports each snapshot where the matching path appears. This is how you find the last snapshot before a file was deleted.
Borg has no direct equivalent of find across archives. Loop over borg list --short output and list each archive with a path filter, or mount the repository (see below).
Comparing snapshots
To see what changed between two points in time, use the diff commands.
restic diff 4f2a9c1d 8b7e3d20
borg diff '::myserver-2026-11-26T02:00:00' myserver-2026-11-27T02:00:00In restic, + marks added files, - removed, M modified. Borg's diff takes the first archive with ::, and the second as a bare archive name.
Restoring with restic
The core command is restic restore. It requires --target, the directory to write into.
restic restore latest --target /tmp/restore --include /etc/nginx
restic ls latest /etc/nginxThe first command restores only /etc/nginx. Be aware that restic recreates the full original path under the target. The files land in /tmp/restore/etc/nginx, not /tmp/restore. The second command lists what the snapshot holds, so you can confirm the paths you expect.
You can also give a snapshot a subfolder to treat as the root:
restic restore latest:/etc/nginx --target /tmp/restore-nginxHere the files land directly in /tmp/restore-nginx, without the etc/nginx prefix.
Useful options:
| Option | Effect |
|---|---|
| `--include PATTERN` | Restore only matching paths |
| `--exclude PATTERN` | Skip matching paths |
| `--host`, `--path` | Narrow what `latest` refers to |
| `--verify` | Re-read restored files and compare them to the repository |
| `--dry-run` | Report what would be restored without writing (restic 0.16 and later, with `--verbose`) |
Extracting one file without a directory tree
restic dump writes a single file to standard output. This avoids the nested directory structure.
restic dump latest /etc/nginx/nginx.conf > /tmp/nginx.conf.recoveredYou can also dump a directory as a tar archive with restic dump latest /etc/nginx --archive tar, but check your version's help, because older releases only produce tar.
Restoring with Borg
borg extract writes into the current working directory. This catches many people out, so change directory first.
mkdir -p /tmp/restore && cd /tmp/restore
borg list ::
borg extract --dry-run --list '::myserver-2026-11-27T02:00:00' etc/nginxThe --dry-run flag together with --list prints what would be extracted without writing anything. When the list looks right, run the same command without --dry-run:
borg extract --list '::myserver-2026-11-27T02:00:00' etc/nginxFiles appear under /tmp/restore/etc/nginx. To drop leading path components, use --strip-components:
borg extract --strip-components 2 '::myserver-2026-11-27T02:00:00' etc/nginxWith --strip-components 2, etc/nginx/nginx.conf becomes nginx.conf.
For one file as a stream, use --stdout:
borg extract --stdout '::myserver-2026-11-27T02:00:00' etc/nginx/nginx.conf > /tmp/nginx.conf.recoveredMounting a backup as a file system
Both tools can present snapshots as a read-only directory tree through FUSE (Filesystem in Userspace). You then browse with ls, diff, and cp. This needs the FUSE package installed on the server.
mkdir -p /mnt/backup
restic mount /mnt/backuprestic mount runs in the foreground. Open a second terminal and look under /mnt/backup/snapshots/, /mnt/backup/hosts/, and /mnt/backup/ids/. Press Ctrl+C or run umount /mnt/backup to finish.
Borg's equivalent:
borg mount :: /mnt/backup
ls /mnt/backup
borg umount /mnt/backupMounting is convenient for exploring and for restoring a few scattered files. It is slow for large copies, because each file read goes through the repository's chunk lookup and decryption. For a bulk restore, use restore or extract.
Restoring in place
Sometimes you do want the files back at their original location, for example after a disk replacement. With restic, the target is /:
restic restore latest --target / --include /etc/nginxThis overwrites existing files that differ from the snapshot. With Borg, run borg extract from / in the same way.
cd / && borg extract --list '::myserver-2026-11-27T02:00:00' etc/nginxAfter restoring configuration files, check ownership and permissions. Both tools store and restore modes and ownership. Restoring as a non-root user cannot set owners to other users, so run restores that need correct ownership as root.
Common errors
- Wrong path form.
borg extract ... /etc/nginxmatches nothing in Borg 1.x because the archive paths have no leading slash. Useetc/nginx. - Restored into the wrong place. Borg writes into the current directory. restic writes under
--target, with the full original path inside it. latestpicked another host's snapshot. Add--hostand--pathfilters on shared repositories.- Mount fails. The FUSE package is missing, or the
fusekernel module or/dev/fuseis unavailable (common in containers). - Disk fills during restore. Check free space under the target first with
df -h. A restore needs the full uncompressed size of what you extract. - Locked repository. If a backup or prune is still running, or crashed, restic may report a lock. Read operations usually tolerate shared locks, but if a stale lock remains, run
restic unlockonly after confirming no other process is using the repository.
Exercise
A teammate deleted /etc/nginx/conf.d/site.conf sometime last week. You use restic and don't know which snapshot still has the file. Which commands do you use to find the file, and then to restore only that file without touching the live system?
Show answer
Run restic find site.conf (or restic find '/etc/nginx/conf.d/site.conf') to list the snapshots that contain the file, and pick the most recent one from before the deletion. Then restore only that path into a scratch directory, for example restic restore SNAPSHOT_ID --target /tmp/restore --include /etc/nginx/conf.d/site.conf. The file appears at /tmp/restore/etc/nginx/conf.d/site.conf. Review it, then copy it into /etc/nginx/conf.d/ and reload nginx. Alternatively, restic dump SNAPSHOT_ID /etc/nginx/conf.d/site.conf > site.conf writes the file directly.
Exercise
You run borg extract '::myserver-2026-11-27T02:00:00' /etc/nginx from your home directory and nothing is extracted. Give two things wrong with the command and the corrected version.
Show answer
First, Borg 1.x archive paths have no leading slash, so the path must be etc/nginx, not /etc/nginx. Second, borg extract writes into the current directory, so running it from your home directory would put files there rather than in a scratch directory. Change to a scratch directory first and use the correct path: mkdir -p /tmp/restore && cd /tmp/restore && borg extract --list '::myserver-2026-11-27T02:00:00' etc/nginx. Adding --dry-run first shows what would be extracted.