Quickly search through a single snapshot using FZF

If you haven’t tried FZF with Restic, you should! Restic’s find is great when you know what you’re looking for… but what if you’re not exactly sure, and don’t want to run the find command repeatedly?

Just install fzf (brew install fzf on MacOS), then pipe restic ls to it like so:

restic ls -q <snapshot-ID> | fzf -i

I use the -i switch to make it case-insensitive. As soon as ls starts piping filenames, you can begin typing to search. You’ll know Restic is still piping data by the spinning square at the bottom-left, which will stop when Restic is done. Once it fully loads the snapshot, you can search the same file listing over and over instantaneously. Use a ' to specify an exact phrase, like 'restic - otherwise it will match everything that has an r, e, s, t, i, c anywhere in the filename.

Alternatively, if you do restic mount you can just cd to the mounted directory and run fzf -i directly. This would also make it possible to search multiple snapshots at once, though I figure restic find is faster if you actually know what you’re looking for exactly.

Happy searching!

6 Likes

This is a very neat idea, thank you very much for sharing. I love fzf and this is another great use for it.

2 Likes

Can I suggest adding -q to restic,

restic ls -q latest | fzf -i

This will eliminate the header line containing snapshot ID and list of paths in the backup

2 Likes

That’s a very good point! Didn’t even think of that. :+1:

Very nice tip but does not work for me interactively:

restic ls latest | fzf
[1]+  Stopped                 restic ls latest | fzf

I have to:

restic ls latest > results.txt
cat results.txt | fzf

Hmm Restic may be prompting for the repo password behind the scenes, maybe? Do you have the RESTIC_PASSWORD environment variable loaded?

it is the same behavior regardless if asking for password (then I have pass prompt before) or if passed in env variable

actually I think it is because I use rclone repo - probably it messes up with STDIN stream.

Anyway - fantastic little tool - thx for sharing