Script "restic diff" between the last two snapshots


So I wrote a backup script for a client:


ECHO Setting environment variables, please wait…

ECHO Updating Restic, please wait…
C:\scripts\restic.exe self-update

ECHO Backing up, please wait…
C:\scripts\restic.exe backup “C:\scripts” “E:\data” >C:\Scripts\backup-b2.log

ECHO Emailing results, please wait…
C:\scripts\sendemail.exe -f -t -u Backblaze Backup Log -s -xu -xp PasswordGoesHere -o message-file=C:\Scripts\backup-b2.log

I tried various levels of verbosity (1-4) but couldn’t find one that shows JUST added/deleted/modified files - it seems 3 and 4 both show all skipped files too?

Is there a way to show just added / deleted / modified files? OR is there a way to automatically do a restic “diff” between the last two snapshots and pipe that out to a text file? Either one would work.

Just curious. Thanks! :slight_smile:


Unless I’m missing something, restic diff without -v does exactly what you’re describing.


Oh, sorry, I wasn’t clear. I meant I tried -v -vv -vvv and -vvvv with “restic backup” in the script with >backup.log at the end. I was hoping for a level that would only show what’s changed, omitting skipped files.

Separately, I was wondering if there was a way to do “restic diff” and automatically compare the last two snapshots without specifying their IDs (or a way to programmatically grab them in order to specify them, perhaps from a “restic snapshots” listing).

Either option would get me what I’m wanting - just a list of added/modified/deleted files, which I could then email myself after a script execution.


There’s probably an easier way but this is what I use on Linux:

PREV=$(/opt/restic/restic snapshots --compact --repo /path/to/Restic | tail -5 | head -1 | awk '{print $1}')
LAST=$(/opt/restic/restic snapshots --compact --repo /path/to/Restic | tail -3 | head -1 | awk '{print $1}')
/opt/restic/restic diff "$PREV" "$LAST" --repo /path/to/Restic >> ${LOG} 2>&1

It would be great if this was easier, perhaps it could be what restic diff does by default?


Sure, that’s what --json is for. Assuming the hostname is foobar and all snapshots have the same paths, something like this will work on Linux where command substitution and jq are available:

restic diff $(restic snapshots --host foobar | jq -r '.[-2:][].id')

Presumably you can do something similar on Windows using PowerShell – or maybe even in batch files, though it will likely be a bit trickier.