In case it helps anyone else, this is how I run backups on a regular basis on my MacBook.
-
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.) -
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">
<dict>
<key>Label</key>
<string>net.restic.backup</string>
<key>ProgramArguments</key>
<array>
<string>/bin/bash</string>
<string>-c</string>
<string>source /Users/USERNAME/.bashrc ; restic backup DATA_FOLDER</string>
</array>
<key>StandardOutPath</key>
<string>LOG_FILE</string>
<key>StandardErrorPath</key>
<string>LOG_FILE</string>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>22</integer>
<key>Minute</key>
<integer>0</integer>
<key>Weekday</key>
<integer>3</integer>
</dict>
</dict>
</plist>
-
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… -
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.
-
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.