Example: Scheduling regular backups on macOS


In case it helps anyone else, this is how I run backups on a regular basis on my MacBook.

  1. Use .bashrc or .bash_profile to export any environment variables your restic command may need, for example, the repository password. (This is convenient because it also allows you to get them in any Terminal you start.)

  2. Create a file called ~/Library/LaunchAgents/net.restic.backup.plist with these contents:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
		<string>source /Users/USERNAME/.bashrc ; restic backup DATA_FOLDER</string>

  1. Replace USERNAME with your login username, DATA_FOLDER with the folder to back up (you should put your proper restic command there, actually), and LOG_FILE with the path to the log file to back up. If your env variables are in .bash_profile instead of .bashrc, then make that change too. If your Mac is mobile or backing up over a network, I highly recommend using the --hostname flag; see this thread

  2. This particular script is configured to run every 3rd day of the week (Wednesday; 0 is Sunday, 6 is Saturday) at 10pm. You can change this, of course.

  3. Run launchctl load -w ~/Library/LaunchAgents/net.restic.backup.plist to permanently load the task; the -w persists it through restarts (I think). Note that this will cause your backup to run when the computer is ON. If it is sleeping during the scheduled time, it will run when you log back in. If the computer is OFF, it will skip that particular run. See https://developer.apple.com/library/content/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/ScheduledJobs.html for more info.

You can then invoke a backup to test it with launchctl start ~/Library/LaunchAgents/net.restic.backup (no .plist extension – start goes by the Label in the XML doc)

You can use unload -w similarly to stop the scheduled task.

Is there an introductory guide for non-techie mac users?

Very useful, thanks ! :+1:


Epilogue: If you backup to a network location, and your network interface takes a few moments to come online like mine does, you might want to prepend the command (the third argument to ProgramArguments) with something like sleep 300 to wait 5 minutes before running the backup. However, if your computer powers down before 5 minutes, I don’t know what will happen, but my guess is that the backup will not run for that time period. Still, if you turn on your computer and usually leave it on for more than a few minutes it should help.


I found another blog article on the same topic, so I’m including it here just for reference and diversity, even though it’s a bit like hijacking the thread :stuck_out_tongue:



Would love to see systemd for macOS! The network-online.target would be of great help here.
This https://blog.slaunchaman.com/2010/07/01/how-to-run-a-launchdaemon-that-requires-networking/ could also be of help if somebody is working on automating macOS restic backups to some network storage.