Restic example gists

I posted a variety of the Restic related scripts and config files I use as gists. While they’re all tailored for my unique use case, I decided to publish them in case anyone can benefit from seeing additional examples.

How I use Restic is admittedly unusual so a bit of background may help the various examples make more sense:

  • The repo is maintained on a raid-10 volume on my Linux server.
  • The server backs itself up via the standard restic backup command since the repo is locally accessible.
  • The server also runs scheduled jobs (via systemd timers) for maintenance tasks.
  • The local repo is synced to AWS S3 via the AWS CLI for offsite storage. Except for a disaster or disk failure, I can restore locally as much as I want without worrying about S3 retrieval fees (at the expense of local disk space usage).
  • The server makes the repo available over to clients on my local network via REST. This is done via RClone’s ability to serve restic’s REST backend API over HTTP. Caddy is used to reverse proxy to the service exposed by Rclone. This provides a bit security control over how the API is exposed.

I also published unlock, stats, and snapshot scripts.

This all requires a few prerequisites which I have not (at least at this time) published gists for. Basically, most everything runs as a service account so user/group permissions and Linux capabilities (setcap) will need to be configured appropriately.

This is certainly an atypical use case. While I’m not advocating for anyone to adopt this, I still thought a few of the examples could benefit the community. I also know room for improvement exists so I’m open to suggestions.

The biggest feature I would still like to implement is auto-monitoring for failures so I do not have to periodically check the log outputs to see if restic check returned any errors or if the maintenance script fails due to the repo not getting unlocked (happens to me occasionally, likely due to a laptop disconnecting during the middle of a backup).

1 Like

If you’re using GNU/Linux, you can make the scripts to send you a notification or an email if there are any errors. To send a notification you could use notify-send package. That way you can catch an exit code (if non-zero) after the command and send you a notification/email. Example with notify-send:

restic backup #command
if [[ $? -ne 0 ]] ; then #if the exit code is not 0, then it could be an error
  notify-send "Restic backup failed" #send notification to desktop

Example with mail:

restic backup #command
if [[ $? -ne 0 ]] ; then #if the exit code is not 0, then it could be an error 
  mail -s "Restic Backup failed" < /dev/null #email subject is between quotes

I bet there is a better way to do this but this works. To use mail you need to install mailutils and set it up to send emails outside your network.

I’ve tinkered with using Pushbullet and Discord hooks to do the same. Both can be pushed to very easily using curl. The primary issue with both services is lack of redelivery attempts if something fails. Using mail is IMO the best approach because the message will get queued locally and delivery will be attempted for up to 5 days if there is a network interruption.

Thanks for the tips. Historically, I’ve used mail as well and agree it works well. I typically go the route of configuring postfix as send-only using a gmail account. I haven’t taken the time to do it with these scripts. Twilio is another option I’ve considered.

Ideally, a periodic test restore would also be automated. I’d like to eventually implement something like the Automated Restore Test shared by hbauer.

I typically go the route of configuring postfix as send-only using a gmail account.

For the record, this is exactly what I do here. Tested Pushbullet a few years ago but found it nothing to write home about, perhaps it’s better now?

Many thanks. I will definitely take a look.

Here is mine

Is just a WIP while i’m learning how to use restic.
My goal is to refine the scripts to have a sort of single config file for manual and automated backup.
Any advice is welcome.