Automated Restore Test

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)

# 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 ]] 
    echo "Backup looks good" | mail -s 'Backup Good' $BACKUP_ADMIN

    echo 'Warning: have a look at your backup ' | mail -s 'Backup Warning' $BACKUP_ADMIN 
1 Like

That is a very good idea :slight_smile:

I’ve taken the liberty to reformat your post so the shell script is nicely highlighted.

Neat – I’ve been thinking about doing this too. But I always came back to: isn’t this what basically what restic check does? I guess it removes the possibility of restic check missing an error, but I presume that with the tests behind the code, that restic check will catch anything an arbitrary file restore would catch too.

I am of course aware of restic check. But since I am paranoid I dont trust a check that is performed by the program that I want to verify. (Alexander dont get me wrong ;-))

I would tell everybody to do additional real live test of a backup but at least you can eliminate some simple restore tests.

Don’t worry, I fully understand and support what you’r doing :wink: