with apologies

Discovering `restic`

Richard Mortier · August 26, 2024 · #old #tech #linux

I recently had cause to try to recover some files from my restic backups. These go back for over a year now, and I could not remember at which point I’d mistakenly nuked the directory I now wanted to recover. restic find purports to be able to do this by searching through snapshots but I found that it’s quite slow, and can only search within a time range which is not that helpful when you don’t know the time range you need.

So I did it by hand, which turned out to be rather faster.

 RESTIC_PASSWORD_FILE=/your/backup/password/file RESTIC_REPOSITORY=/your/backup/repository/ \
    # list snapshots, filtering by DATE regex, grabbing just the snapshot hash
    sudo -E restic snapshots -c \
    | rg DATE \
    | cut -b1-8 \
    | while read ss; do 
    echo "=== $ss"
    sudo -E restic ls $ss | rg /DIRECTORY/ ; done 
 done

The key thing with the above approach is that it’s also quite amenable to bisection, which makes it a lot faster.