Recipe powershell diff of last two snapshots

Using Windows and Powershell but need to set up a diff of the last two snapshots? Here are commands which worked for me:

setup a bunch of variables. Change all of these to what you need.

$RESTICDIR = ‘K:\utility\restic’
$backupdrive = “L”
$RESTIC_BKUPYR = (get-date).ToString(“yyyy”)
$RESTICEXE = ‘K:\utility\restic\restic.exe’
$RESTIC_PASSWORD_FILE = ‘K:\utility\restic\restic_data.txt’
$RESTIC_SOURCE_DRIVE = ‘K’ #Drive letter with no colon or slash.
$RESTIC_REPOSITORY = “${backupdrive}:\restic_backup_${RESTIC_BKUPYR}${RESTIC_SOURCE_DRIVE}”
$env:RESTIC_REPOSITORY = “${backupdrive}:\restic_backup_${RESTIC_BKUPYR}${RESTIC_SOURCE_DRIVE}”

place cachedir on another drive

$CACHEDIR = “E:\z_temp\restic_${RESTIC_BKUPYR}cachedir${RESTIC_SOURCE_DRIVE}”

list snapshot ids

.${RESTICEXE} snapshots -compact -r $RESTIC_REPOSITORY | Out-File -FilePath $RESTIC_SNAPLIST_FILE -encoding ascii

get last 4 lines

$lines = (Get-Content -Path $RESTIC_SNAPLIST_FILE -Tail 4)
$arr = $lines[0] -split “\s+”
#Write-Host “The previous snapshot is ${prevsnapshot}” -fore green
$arr = $lines[1] -split “\s+”
Write-Host “The latest snapshot is ${latestsnapshot}” -fore green
$arr = $line -split “\s+”
.${RESTICEXE} diff ${latestsnapshot} ${prevsnapshot} --cache-dir $CACHEDIR | Out-File -FilePath .\restic_temp_stdout.log -encoding ascii
Rename-Item -Path .\restic_temp_stdout.log -NewName “restic_diff_${RESTIC_SOURCE_DRIVE}.log”

If you are using restic on Windows be sure to tell your antivirus program, such as Windows Defender, to ignore restic.exe This does improve the elapsed time.