Backup with restic.

Restic is my favourite backup software, but their quickstart is lacking. So here’s mine.

  1. Install restic. On Windows use Scoop, on Linux it’s a bit more complicated (I’m working on a curl | bash, the copy-pasta refrences it). I suggest on getting the binary, instead of your package manager. More on that later. Have bzip2 installed and copy-pasta:
curl -s | grep 'browser_download_url.*linux_amd64.bz2"' | cut -d : -f 2,3 | tr -d \" | xargs -n 1 curl -sSL > /tmp/restic.bz2 && sudo sh -c 'bzip2 -dc /tmp/restic.bz2 > /usr/local/bin/restic && chmod +x /usr/local/bin/restic'

Copy-pasta this for auto-updates via cron:

cronhour=$(awk -v min=$(($(date +%H)-2)) -v max=$(($(date +%H)+2)) 'BEGIN{srand(); print int(min+rand()*(max-min+1))}')
if (( 24 <= $cronhour )); then cronhour=$(($cronhour-24)); fi
(crontab -l; echo "$((0+RANDOM%59)) $cronhour */3 * * $restic_location self-update -q # Auto-update restic, added by the one-line install script.")|crontab -
  1. Where do you want your backups to be stored? (Don’t do local) Restic supports these. Since it supports rclone, it supports pretty much anything. If you don’t have anywhere to put your backups, I suggest using Backblaze B2 they are low effort cheap. When exporting enviroment variables, remember, you must also have them for cron.

So, you have ended up with something like restic -r

  1. Init. Bring what you ended up, restic -r, now add -p ~/.restic-password (where the plaintext password will be stored) and init, ending up with:
restic -r -p ~/.restic-password init

You will be asked for the encryption password, store it outside your home (if your house burns down).

  1. Ready to go, let’s make the first backup. Replace init with backup with directories or files you wish to backup. I suggest the home directory. You can also exclude things. I suggest using --exclude-caches --exclude *cache*. Now we have:
restic -r -p ~/.restic-password backup ~ --exclude-caches --exclude *cache*
  1. The first backup has been made. Make it automated.

You probably want to automatically delete older backups, to your cron command, add && restic -r -p ~/.restic-password forget --prune --keep-last 10 --keep-daily 30 --keep-monthly 120. The keep-last explains itself, however the others (keeps 1 backup for each month within the last 120 months (10yrs), unless it’s within 30 days, in what case, keep 1 backup for each day) is explained in the docs.

We now end up with:

restic -r -p ~/.restic-password backup ~ --exclude-caches --exclude *cache* && restic -r -p ~/.restic-password forget --prune --keep-last 10 --keep-daily 30 --keep-monthly 120
  • Linux: Use cron. If cron sends you mail about successful backups, use -q to only send you mail on failures.
  • Windows: Use Cronical.
  1. Use your backups. If something ever goes wrong, you can quickly restore. On linux, you can just mount it, with restic -r -p ~/.restic-password mount /mnt/restic. For Windows and other ways, refer to the docs

Any other questions? Ask me, or RTFM.

If you do contact me, remind me to wrap this all in to the installer. The restic’s curl piped to bash script would not only install restic, but also interactively set up your backups.

Do also mind the formatting. Didn’t bother as I hope to get this all in to a bash and powershell scripts.

530 Words

2020-05-24 00:00 0000