Maybe other people find this helpful or have some comments to improve it.
Of course i trust the capability of restic to do a restore but call me paranoid I would like to test it from time to time. In addition to some real test I wanted to create some sort of automated restore test.
So this is my idea
- create a testfile that I am sure will not change
- extract this test file after “some days”
- compare the extracted file with my good file
- (still missing: automated deletion of test files after DAYSOLD+10 DAYS)
#!/bin/bash
RESTIC_PASSWORD_FILE=/root/restic/repopassword.txt
RESTIC_REPOSITORY=/mypath/to/repo/restic-repo
BACKUP_ADMIN=backup_admin@yourdoamin.de
THISHOST=$(hostname)
DAYSOLD=2
# what is the snapshot id of the backup from $DAYSOLD days ?
SNAPSHOTNR="$(/usr/bin/restic -r $RESTIC_REPOSITORY -p $RESTIC_PASSWORD_FILE snapshots | grep $THISHOST | tail -n $DAYSOLD | head -n 1 | awk '{print $1;}')"
# what is the name of the testfile that we want to extract
FILENAME=/root/restic/dummy-files/$( date '+%Y-%m-%d' -d "-$DAYSOLD days" ).txt
# extract our testfile
/usr/bin/restic restore "${SNAPSHOTNR}" -r $RESTIC_REPOSITORY -p $RESTIC_PASSWORD_FILE --include $FILENAME --target /root/restic/test-files
ANY_DIFFERENCE="$(diff $FILENAME /root/restic/test-files/$FILENAME)"
if [[ ${#ANY_DIFFERENCE} -eq 0 ]]
then
echo "Backup looks good" | mail -s 'Backup Good' $BACKUP_ADMIN
else
echo 'Warning: have a look at your backup ' | mail -s 'Backup Warning' $BACKUP_ADMIN
fi