Apple Time Machine can be used to make backups of the whole computer. Launchd serves to start a process at specified intervals and can be used make regular backups of a certain directory, for example your home directory.
The example below starts a bash script every 10 minutes, which calls rsync to do the actual backup over ssh. I implemented this to back up to a Raspberry Pi with a large USB disk attached. It requires the public/private ssh keys to be shared between the two machines.
The bash script /usr/local/bin/backup2fileserver.sh
contains the following:
#!/bin/bash
/sbin/ping -c 1 -q fileserver.local || exit 1
/usr/bin/rsync -a /Users/robert robert@fileserver.local:/media/backupdisk/
I made the plist file /Library/LaunchDaemons/com.zerowidth.launched.backup2fileserver.plist
with launchd instructions to start the script every 600 seconds using this online launchd plist generator. It contains the following:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.zerowidth.launched.backup2fileserver</string>
<key>ProgramArguments</key>
<array>
<string>sh</string>
<string>-c</string>
<string>/usr/local/bin/backup2fileserver.sh</string>
</array>
<key>UserName</key>
<string>root</string>
<key>StartInterval</key>
<integer>600</integer>
</dict>
</plist>
Subsequently I used the following command in the macOS terminal to tell launchd to manage the backup script:
sudo launchctl load -w /Library/LaunchDaemons/com.zerowidth.launched.backup2fileserver.plist /Library/LaunchDaemons/com.zerowidth.launched.backup2fileserver.plist