How to Restore a Single File from a Restic Backup Without Restoring Everything

Deleting one file by accident is a miserable feeling. You have a full backup, but restoring an entire snapshot just to get one wp-config.php back is worse: a full restore can overwrite files that changed since the backup was taken, and on a busy server it takes far longer than one file is worth. A single file restore from restic solves that. Restic gives you three ways to pull one file out of a snapshot: restore it with an include filter, dump it straight to standard output, or mount the snapshot and copy the file like any other. Each method takes under a minute once you know the file’s path, and none of them touch the rest of your data.

Find the file and the snapshot first

Before you restore anything, confirm which snapshot holds the version of the file you want. Restic keeps every backup as a snapshot, and the newest one is not always the right one: if the file was deleted a week ago, the latest snapshot may already be missing it. List your snapshots with their dates and hostnames:

restic -r /path/to/repo snapshots

Pick the snapshot ID from the list, or use latest when you know the newest backup still has the file. Then check that the file is actually inside that snapshot:

restic -r /path/to/repo ls latest /var/www/html

If you only remember part of the path, list the whole snapshot and filter it with grep:

restic -r /path/to/repo ls latest | grep wp-config

Note the exact path restic shows. All three restore methods below need it, and a wrong path is the most common reason a restore comes back empty. If you set up your backups following a guide to backing up a VPS to S3-compatible storage with restic, the repository path here is the same S3 bucket or local directory you used when you created the backup.

Single File Restore from Restic in Three Ways

All three methods below recover the same file. They differ in speed, setup, and how much room there is to make a mistake, so pick the one that fits your situation rather than the first one you find.

Method 1: restic restore with an include filter

Use the restic restore include flag to limit the restore to one file: only paths matching the --include pattern get restored. This is the cleanest way to do a restic restore single file job, because it uses the normal restore path and nothing else:

restic -r /path/to/repo restore latest 
  --target /tmp/restic-restore 
  --include /var/www/html/wp-config.php

Restic recreates the directory structure under the target, so the file lands at /tmp/restic-restore/var/www/html/wp-config.php. Copy it into place from there:

cp /tmp/restic-restore/var/www/html/wp-config.php /var/www/html/wp-config.php

Restore to an empty temporary directory, never straight over your live files. That way, if you picked the wrong snapshot or the wrong path, nothing on the live site changes while you check. This is also the method to use when you want to restore a file from a snapshot on a server where you cannot install extra tools: restore is built into every restic install. A full walkthrough of setting up restic the first time is in the restic tutorial for encrypted backups to S3-compatible storage.

Method 2: restic dump for one file, straight to stdout

The restic dump command prints a single file’s contents to standard output. Redirect that output to a file and you are done, with no directory tree to dig through:

restic -r /path/to/repo dump latest /var/www/html/wp-config.php > /tmp/wp-config.php

Dump is the fastest option when you know the exact path and just want the file back. It also works over a pipe: if the file is a text config you want to inspect before putting it back, drop the redirect and read it in the terminal. One thing to watch: dump writes the file’s raw bytes, so it does not preserve the original owner, group, or permissions. After copying the file into place, set them yourself to match the original, for example with chown and chmod. Dumping a directory instead of a file produces a tar archive on stdout, which you can unpack with tar -xvf - -C /tmp/restore.

Method 3: mount the snapshot and copy the file

If you are not sure of the exact path, or you want to grab several files from different folders, mount the repository and browse it like a normal filesystem. The restic mount snapshot approach turns every snapshot into a directory you can explore:

mkdir -p /mnt/restic
restic -r /path/to/repo mount /mnt/restic

Leave that command running in one terminal. In another, look under /mnt/restic/snapshots/, find your snapshot ID, and copy whatever you need:

cp /mnt/restic/snapshots/abc1234/var/www/html/wp-config.php /tmp/wp-config.php

When you are done, unmount with fusermount -u /mnt/restic (or umount /mnt/restic). Mounting needs FUSE on the server, which most VPS providers allow, but some minimal containers block it; if mount fails with a FUSE error, fall back to Method 1 or 2. Mounting is also read-only, so there is no way to accidentally change the snapshot while you browse it.

Which method should you pick?

Method Best when Needs FUSE Preserves permissions
restore --include You know the exact path and want the normal restore path No Yes
dump You want one file fast, or want to inspect it first No No
mount You are unsure of the path, or need files from several folders Yes Yes, on copy

For a single known file, dump is usually quickest. For anything where you might have the wrong path, mount lets you look around before committing. If neither appeals, restore --include is the safe middle ground.

Mistakes that turn a small restore into a bigger problem

Most restic restores go wrong in the same few ways, and all of them are avoidable. First, restoring straight over a live file before checking the snapshot date. If the file changed after the backup, the restored copy is older than the one you just overwrote, and there is no undo. Restore to /tmp, compare with diff, and only then copy it into place.

Second, picking the wrong snapshot. A backup from last Tuesday and one from last month can both contain the file, but with different contents. Check the snapshot list, match the date to when the file was last good, and verify the file’s contents before you put it back. A quick way to build this habit is to test your backup restores without breaking production on a schedule, so the restore steps are familiar before you actually need them.

Third, forgetting that a restored file is only as good as the backup it came from. Run a sanity check after copying: php -l wp-config.php for a PHP config, nginx -t after restoring an nginx file, or simply open the file and read it. A restore you never verify is a guess, not a recovery. If you have never done a full dry run, the guide to testing your VPS backup by restoring it before you actually need it walks through the process end to end.

Finally, permissions. A config file owned by root with mode 600 will break a site that expects its web server user to read it, and a private key restored world-readable is a security problem. After every restore, check the owner and mode against a sibling file in the same directory and fix them before restarting the service.

Frequently asked questions

Can I restore a single file from a remote S3 repository?

Yes. Restic only downloads the data chunks that make up the file you asked for, not the whole repository, so a single-file restore from S3 is quick even when the backup itself is large. This is one reason storing VPS backups off-site works well with restic: the backup lives elsewhere, but a small restore stays fast and cheap.

Does restoring a file change or damage the snapshot?

No. Snapshots are read-only. Restoring, dumping, and mounting only read data out of the repository, so you can repeat the restore as many times as you like without affecting the backup.

What if I only remember part of the filename?

List the snapshot and pipe it through grep, as shown above. If that still does not find it, mount the snapshot and search it with find /mnt/restic/snapshots/<id> -name "*partial*". Mounting is the easiest option when you are hunting rather than restoring a known path.

One deleted file does not call for a full restore. Find the right snapshot, pull the file out with restore --include, dump, or mount, check it in /tmp before it goes live, and fix the permissions. The whole job takes a few minutes, and your server never stops serving while you do it.

Ditulis oleh

Firdaus Safari Putra

Founder, PT FirKaizen Digital Solutions

Firdaus Safari Putra adalah founder PT FirKaizen Digital Solutions. Ia membangun dan mengoperasikan infrastruktur server di balik panduan ini, dan menulis berdasarkan apa yang benar-benar ia jalankan, uji, dan ukur — bukan teori.