clone to some location like /opt/restic:
git clone https://gist.github.com/Alistair1231/c3bfa81d2c3016a7138b2839d32996a8 /opt/resticLinux is the primary target, but everything here also runs on macOS. Install the missing pieces via Homebrew first:
brew install bash flock coreutils jq resticbash— macOS ships bash 3.2; the scripts use associative arrays andmapfile, which need bash >= 4.flock— macOS has no built-inflock(1);restic.shuses it for the run lock.coreutils— providesgdate(GNU date), whichfind-changed.shuses for parsing relative/absolute times. macOS's built-indateis BSD date and doesn't support the same flags.jq,restic— same as Linux.
restic.sh picks up restic from PATH automatically, so no extra config
is needed there. restic.exclude.example is written for a Linux/Steam
setup (/home/*/.local/share/Steam/..., flatpak, etc.); those patterns
just won't match anything on macOS, so adapt restic.exclude to your own
paths instead (e.g. ~/Library/Caches, ~/Library/Application Support/Steam).
- Add a
.restic-passwordfile in the same directory asrestic.shwith your repository password. - Copy the
restic.env.exampleandrestic.exclude.examplefiles and modify to your liking:
cp restic.env.example restic.env
vim restic.env
cp restic.exclude.example restic.exclude
vim restic.exclude# source the environment variables
source restic.env
# init the repository
restic initInstall the dependencies (e.g. on Arch Linux):
sudo pacman -S restic jq cronieAdd a crontab entry to run the backup script:
# enable cronie if not already running
sudo systemctl enable --now cronie
# then, either as current user
sudo EDITOR=vim crontab -u $USER -e
# or as root
sudo EDITOR=vim crontab -eSHELL=/bin/bash
PATH=/bin:/usr/bin:/usr/local/bin
# Syntax:
# An example of setting a task through the scheduler:
# .---------------- minutes (0 - 59)
# | .------------- hours (0 - 23)
# | | .---------- days (1 - 31)
# | | | .------- months (1 - 12) OR may,jun,sept,aug ...
# | | | | .---- weekdays (0 - 6) OR mon,tue,wed,thu,fri,sat,sun
# | | | | |
# * * * * * the command you want to schedule
# test it out: https://crontab.guru/
# every 15 minutes, call the backup script and log the output. To view logs, run `journalctl -t restic`
*/15 * * * * /opt/restic/restic.sh 2>&1 | logger -t restic --prio-prefixMacOS ships BSD cron, so the same crontab -e approach works:
# then, either as current user
sudo EDITOR=vim crontab -u $USER -e
# or as root
sudo EDITOR=vim crontab -e# Homebrew's bin dir goes first so restic/jq/flock/gdate/bash are found.
# Apple Silicon: /opt/homebrew/bin — Intel: /usr/local/bin
PATH=/opt/homebrew/bin:/usr/local/bin:/bin:/usr/bin
# every 15 minutes, call the backup script and log the output.
# macOS's logger has no --prio-prefix, so it's left off. View logs with
# `log show --predicate 'eventMessage contains "restic"'` or search
# "restic" in Console.app.
*/15 * * * * /opt/restic/restic.sh 2>&1 | logger -t resticcron needs Full Disk Access to read protected folders (Documents,
Desktop, Downloads, Pictures, etc.), or backups of those will silently
come back incomplete. Grant it once in System Settings → Privacy &
Security → Full Disk Access → add /usr/sbin/cron (press Cmd+Shift+G in the file
picker to type the path).
You can restore using restic mount, e.g.:
cd /opt/restic
source restic.env
restic mount /mnt/resticafterwards, just use cp to copy the files you want to restore.
For other options and more info check the restore-docs