Strategy for frequent backups of infrequently changing files?

tl,dr How do I filter snapshots that are identical to their parent from restic snapshots, or how do I prevent restic from making snapshots if they would be identical to the parent?

I have a folder that does not change most of the time, except for sporadic bursts of activity once or twice a week. When it is changing, I want it backed up frequently.

So far my strategy has been to automatically back it up hourly no matter if it changed or not, and restic has had my back space-wise and speed-wise, but it does mean my snapshots list is full of snapshots that are identical save for their date. I worry that ifwhen something happens and I need to restore something without knowing exactly when was the last good copy, finding which snapshots are worth looking at will be a pain.

So, is there a way I can filter out dupes when listing snapshots? Abort a backup if it would be a dupe? Clean up dupes after the fact? Something else?

If you’re using *nix, then you can use inotify to watch a directory and trigger a script (in this case a backup) when a file has changed.

I have no idea what to do if you’re on Windows, but you might look into Cygwin or see if the Windows Subsystem for Linux (WSL) might help.

1 Like

You can just restic mount the repository and browse it as a regular filesystem to find the last snapshot where the file you are interested in was “good”.

You can also use restic find to see which snapshots have a file, if you are looking for one that isn’t in all snapshots.

I agree with @diagon, just use a filesystem watcher to run restic when something of interest changes.

I’ll add that you need to make sure you use a lock so that if you have a flurry of changes, then you don’t get multiple backups running over each other. Add in a sleep command, and that way you’ll limit your backups to once every eg. 10 minutes. Something like this:

flock -n /tmp/bkuplk sh -c 'sleep 600; <restic command>'
2 Likes

Thanks! I ended up using incron and flock together and it is working like a charm.

3 Likes

Thank you for this thread, I have a similar situation that it looks like incron and flock could help me with.

1 Like