Example: Scheduling regular backups on macOS

Very well. Here it goes:


Purpose: backing up personal data (as of now 5.3GB) from Mac to B2 using two scripts (backup and maintenance) and schedule them both using launch agents.

(All links are from Github)

restic.backup.sh:

  • It has a include file that is fed to --files-from and an exclude file [0].
  • Then it runs check with --with-cache to keep B2 cost low (as it will run 4 times a day)
  • Then it just runs stats and resets all the credential env vars.
  • Every command’s output is appended to a single log file.
  • Frequency: everyday at 0800, 1200, 1600, 2200 (launch agent amar.restic.backup.plist)

restic.maintain.sh:

  • runs forget with --prune keeping last 10, 7 daily, 5 weekly, 12 monthly, and 3 yearly snapshots
  • runs check without cache then prints stats.
  • Same env vars and logging method as the backup script.
  • Frequency: Every Monday and Thursday at 1330 (launch agent amar.restic.maintenance.plist).

[0] Restic file/dir include/exclude files, credentials file, and a file with env vars are as described in this gist here.

Issues and things I have not figured out:

  1. How can I trigger desktop notifications whenever the scripts run (and possibly an email too, with summary of what happened - esp. for fail cases)?
  2. I could not find any option to compress data - did I miss something? (this is a trial backup set – I have actual data set that’s a lot larger than this)
  3. For subsequent backups I would like to see what actually changed i.e.
    • What files/folders were new
    • What were modified (changed/deleted etc)
    • And if that means a little bigger log output, I can live with that. The thing is every backup is adding ~20MB files to repo and I can’t see why (whether it’s the Mail/V5 folder and I wanted to make sure).

Or in general please suggest anything that I should change to make it better, simpler, and more portable.