2

I have been trying to configure a nightly backup job on my Mac Mini server, and after a lot of Googling and digging and man-page'ing, I figured out that launchd seemed to be the correct too, and tried setting up my own plist fil. I've come up with this (stored in /Library/LaunchDaemons/dk.revealit.NightlyRSyncBackup.plist):

<?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>dk.revealit.NightlyRSyncBackup</string>
        <key>ProgramArguments</key>
        <array>
                <string>/var/root/run-rsync</string>
        </array>
        <key>LowPriorityIO</key>
        <true/>
        <key>Nice</key>
        <integer>1</integer>
        <key>WorkingDirectory</key>
        <string>/var/root</string>
        <key>RunAtLoad</key>
        <false/>
        <key>StartCalendarInterval</key>
        <dict>
                <key>Hour</key>
                <integer>3</integer>
                <key>Minute</key>
                <integer>15</integer>
        </dict>
</dict>
</plist>

Problem is, it doesn't work. I can load it with launchctl, and it appears on launchctl list with exit status 0. But if I check my backup files, they are not updated.

Any clues as to what I'm doing wrong (assuming my backup script works as it should)?

  • What does /var/root/run-rsync contain ? – Mark Feb 26 '16 at 17:50
4

Several things come to mind:

  • Did you wait overnight for it to run? launchctl load won't make it run out of sequence -- if you want to make it run at some time other than 3:15 am, use sudo launchctl start dk.revealit.NightlyRSyncBackup after it's loaded.

  • Does the run-rsync script fire off any background processes, or does it do everything inline? 'Cause if the script exits and there are background processes still going, launchd thinks something has gone wrong and kills the background processes. If you don't want it to do this, add <key>AbandonProcessGroup</key><true/> to the .plist.

  • Does the script depend on PATH including any nonstandard directories (e.g. /opt/local/bin or something like that)?

One useful debugging technique is to add something like:

<key>StandardOutPath</key>
<string>/var/root/NightlyRSyncBackup.out</string>
<key>StandardErrorPath</key>
<string>/var/root/NightlyRSyncBackup.err</string>

to the .plist and see what shows up in those files.

  • As it turns out, it was an issue with the SSH-key not being read properly when run via launchd. Your tip with StandardOutPath and StandardErrorPath were invaluable in finding that problem, thanks :) – mikl Jul 14 '11 at 14:32
2

Once answered a similiar qst, so check this first:

from the man lanuchctl

Note that per-user configuration files (LaunchAgents) must be owned by the user loading them. All system-wide daemons (LaunchDaemons) must be owned by root. Configuration files must not be group- or world-writable. These restrictions are in place for security reasons, as allowing writability to a launchd configuration file allows one to specify which executable will be launched.

So, if your rsync should be stared as root

chown root  /Library/LaunchDaemons/your.plist 
chgrp wheel /Library/LaunchDaemons/your.plist 
chmod 644   /Library/LaunchDaemons/your.plist

and after these:

launchctl load /Library/LaunchDaemons/your.plist
  • That was a good tip, but the ownership/permissions were okay already :) – mikl Jul 14 '11 at 14:31
  • two weeks old question - still not working? that's must be something really weird problem... – jm666 Jul 14 '11 at 16:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .