Cannot restore a single file (just folders)

Am I doing something wrong?
ddd

C:\Users\restint001>restic -r d:\BKRETIC\REPO1 ls latest
enter password for repository:
repository 7adb0697 opened (version 2, compression level auto)
[0:00] 100.00%  3 / 3 index files loaded
snapshot c978f33d of [c:\TOBK] at 2025-11-06 19:52:00.0610255 +0100 CET by GROUP\restint001@CSCO-W-PW0JCGJ7 filtered by []:
/c
/c/TOBK
/c/TOBK/20240908_011833.mp4
/c/TOBK/20240908_021722.mp4
/c/TOBK/20240908_164258.mp4
/c/TOBK/MOVIES
/c/TOBK/PICS
/c/TOBK/PICS/20240908_021559.jpg
/c/TOBK/PICS/20240908_151129.jpg
/c/TOBK/PICS/20240908_151153.jpg
/c/TOBK/PICS/20240908_164550.jpg
/c/TOBK/TurboTax 2007.iso
/c/TOBK/x1.txt


C:\Users\restint001>restic -r d:\BKRETIC\REPO1 restore latest:/c/TOBK/PICS --target c:/TOREST
enter password for repository:
repository 7adb0697 opened (version 2, compression level auto)
[0:00] 100.00%  3 / 3 index files loaded
restoring snapshot c978f33d of [c:\TOBK] at 2025-11-06 19:52:00.0610255 +0100 CET by GROUP\restint001@CSCO-W-PW0JCGJ7 to c:/TOREST
Summary: Restored 4 files/dirs (21.439 MiB) in 0:00

C:\Users\restint001>restic -r d:\BKRETIC\REPO1 restore latest:/c/TOBK/x1.txt --target c:/TOREST
enter password for repository:
repository 7adb0697 opened (version 2, compression level auto)
[0:00] 100.00%  3 / 3 index files loaded
path c/TOBK/x1.txt: not a directory

C:\Users\restint001>

This syntax is clearly your invention.

And it gave you error code which was rather self-explanatory.

As per docs:

To only restore a specific subfolder, you can use the <snapshot>:<subfolder> syntax…

and

Use --exclude and --include to restrict the restore to a subset of files in the snapshot.

If not sure what to do read documentation first.

1 Like

Oh.. thanks for the clue. Sorry, I’m starting with restic and its still confusing, and google searches where not helpful. Any doc you have pointing at this details will be welcome.

So I see restic doesn’t really support specific file restore (at least directly). You can only restore specific folders and then use a pattern to match the file name. But this have pitfalls, because the same file name could be under a subfolder and you would end up restoring two files.

Do I get it?

It actually doesn’t need too much of invention to think that such a path could work for restore. It is also not too hard to implement - however, this feature is missing in restic.

2 Likes

You can restore a specific file by using the include option:
% restic restore latest --include restic-path-to-file --target .

  • restic-path-to-file means the path as given to Restic for the backup.
  • --target . means to restore into the current directory in this case.
  • --include can re replaced by --iinclude if you are unsure about upper or lower case in the filename.
  • You can add --dry-run to the command to check syntax and that it could be working.

Another possibility is to mount the whole backup with

% restic mount /mnt

Then you can find all the files of your backup under /mnt/ and copy out the one you want to restore.

2 Likes

How would I do it in this case?

I want to restore /c/TOBK/x1.txt, but it also restore /c/TOBK/SUBFOLDER/x1.txt

C:>restic -r d:\BKRETIC\REPO1 ls latest
enter password for repository:
repository 7adb0697 opened (version 2, compression level auto)
[0:00] 100.00% 4 / 4 index files loaded
snapshot 55e70510 of [c:\TOBK] at 2025-11-14 20:09:46.8555186 +0100 CET by CISCO\jalcaide@CSCO-W-PW0JCGJ7 filtered by :
/c
/c/TOBK
/c/TOBK/20240908_011833.mp4
/c/TOBK/PICS
/c/TOBK/PICS/20240908_021559.jpg
/c/TOBK/SUBFOLDER
/c/TOBK/SUBFOLDER/x1.txt
/c/TOBK/x1.txt

C:\TOREST3>restic -r d:\BKRETIC\REPO1 restore latest:/c/TOBK --include x1.txt --target .
enter password for repository:
repository 7adb0697 opened (version 2, compression level auto)
[0:00] 100.00% 4 / 4 index files loaded
restoring snapshot 55e70510 of [c:\TOBK] at 2025-11-14 20:09:46.8555186 +0100 CET by CISCO\jalcaide@CSCO-W-PW0JCGJ7 to .
Summary: Restored 3 / 2 files/dirs (17 B / 17 B) in 0:00

You get what you ask for:

means: include any file named x1.txt in /c/TOBK (including subfolders)

You have to be more precise. I think it should be:

--include "/c/TOBK/1.txt"
1 Like

to be fair, even after 2+ years of using restic I still make this mistake often enough that I have had to create a simple wrapper around my restores. Intuitively there’s no difference so it’s an easy mistake to make.

2 Likes

I know it’s a little OT but just to make a note of it: I basically always use the mount feature to restore anything:

restic -r repo mount /mnt

This way you can browse the files using command line or UI file browsers and then just copy over whatever you’re looking for. And even an old f*rt like me can remember that syntax :grimacing:

As we are already getting off-topic here by including mount into the discussion, I just wanted to throw in that it does make a difference whether to restore using mount or the restore command.

Especially, restore is very much optimized to omit duplicate reads from the backend and in general for performance; most of these optimizations are not possible when using mount.

So, from a functional point of view I can understand that people come up with the mount solution, but it can be a big difference performance-wise.

To propose another off-topic option: For a single file you can also use restic dump (which AFAIK also doesn’t implement the <snap>:/path/to/file syntax) which has similar performance implications like restic mount.

And to get completely off-topic: rustic does offer the <snap>:/path/to/file syntax for `restore`.

1 Like

I cannot use mount since I use Windows

Thanks for the tips. But still I’m not able to do what I want:

C:\TOREST>restic -r d:\BKRETIC\REPO1 restore latest:/c/TOBK/x1.txt --target .
enter password for repository:
repository 7adb0697 opened (version 2, compression level auto)
[0:00] 100.00% 4 / 4 index files loaded
path c/TOBK/x1.txt: not a directory

C:\TOREST>restic -r d:\BKRETIC\REPO1 restore latest:/c/TOBK --include “/c/TOBK/x1.txt” --target .
enter password for repository:
repository 7adb0697 opened (version 2, compression level auto)
[0:00] 100.00% 4 / 4 index files loaded
restoring snapshot 55e70510 of [c:\TOBK] at 2025-11-14 20:09:46.8555186 +0100 CET by CISCO\jalcaide@CSCO-W-PW0JCGJ7 to .
Summary: Restored 0 files/dirs (0 B) in 0:00

Am I missing something? Can you give me the exact command for me to test?

Use restic ls. This should show you all files and folders.
Then cross check that with your --include, probably your “include” does not match the snapshot.

So far only subpaths that include folders are supported in restic. Being able to reference a file requires special handling.

It would be great if someone opens a feature request on Github (if there isn’t already one), it’s just not possible to keep track on the forum.

If someone is adventurous maybe even give it a try or take a look whether we can mirror the implementation approach for that in restic :wink: .

I am not too familiar with the current restic implementation. The trick, however, was to not handle Tree objects in commands, but instead Node objects (which can be either a tree node or a file node) - and to create an artificial Node containing only the root tree for snapshots without a path. But there might be other maybe better fitting solutions..

I had ‘restic ls’ above. Nothing worked. IF you have a specific set command, please let me know and I’ll try it.

From my own Restic beginners experience:
I had to learn that there are different notations of the path. The path to a file that Restic uses is not necessarily identical to the path at the filesystem level. The Restic path depends on the command used to backup the files. If your backup command starts in a subdirectory, the Restic path starts at the same place.

For example:
If backup starts from within the /home directory, path to the files in the backup does not begin with /home/username, but only/username .

Regarding your question about ‘ls’ usage: The simplest form is
% restic ls latest
For me this lists all files in my backup. (You already used it above.) You can derive the correct path syntax from this.

A command like
% restic ls latest /username/subdir/foo.bar
lists the file foo.bar from subdir/. But note that there is no colon between the snapshot id and the file path.

1 Like