Using Rsync and LaunchD for backup
Using Rsync and LaunchD for backup, Posted in Tools, October 12th, 2006

This tutorial is mainly for OSX users.
Build and Install rsync
Create an empty file some where (I put mine in /usr/local/ )

Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/bin/bash
# Start Script
LOGFILE="/var/log/backup.log"
SRC='/Users'
DEST='/Volumes/backup'
 
echo "" >> $LOGFILE
echo "" >> $LOGFILE
echo "***************** New Log *****************" >> $LOGFILE
echo "Running Users Backup" >> $LOGFILE
date >> $LOGFILE
/usr/local/bin/rsync -a -v --stats --delete $SRC $DEST >> $LOGFILE
 
exit 0

Now create a .plist in /Library/LaunchDaemons/

Terminal:

1
sudo pico /Library/LaunchDaemons/myplist.plist

Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?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>users-backup-daily</string>
<key>LowPriorityIO</key>
<true/>
<key>Nice</key>
<integer>1</integer>
<key>ProgramArguments</key>
<array>
<string>/bin/sh</string>
<string>/usr/local/backupUsers</string>
</array>
<key>RunAtLoad</key>
<false/>
<key>ServiceDescription</key>
<string>Backing up /Users to /Volumes/backup</string>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>6</integer>
<key>Minute</key>
<integer>0</integer>
</dict>
</dict>
</plist>

the LABEL is very important, because this will be what launchd calls this process.

Replace ‘/usr/local/backupUsers’ with the path to your Bash Script.

Now, we need to load our plist into launchctl

Terminal:

1
%&gt; sudo launchctl load /Library/LaunchDaemons/myplist.plist

To test it

Terminal:

1
%&gt; sudo launchctl start LABEL (set above in the plist)