Years ago I put together the following expect
script to perform Open Directory backups under Tiger Server and it's worked well under Leopard Server as well:
#!/usr/bin/expect -f
set date [timestamp -format "%Y-%m-%d"]
set archive_path "path/to/you/backup/dir"
set archive_password "password"
set archive_name "opendirectory_backup"
spawn /usr/sbin/slapconfig -backupdb $archive_path/$archive_name-$date
expect "Enter archive password"
send "$archive_password\r"
expect eof
It's one of the few scripts that still lives in root's crontab as opposed to having a launchd
plist. It's rwx
by root only for obvious security reasons.
Now, the problem is I upgraded my Open Directory Master to Mac OS X 10.6.4 Snow Leopard Server a couple weeks ago and it hasn't worked since... when run by cron. If I log in as the root user and run it manually it works correctly and creates the resulting encrypted disk image. When run by cron, it goes through the full motions (incl. output in /Library/Logs/slapconfig.log
that matches that of when it's run manually), but the disk image file is never created. However, in `/var/log/system.log/ I see the following output:
Jul 23 03:00:08 servername hdiejectd[93114]: running
Jul 23 03:00:11 servername diskimages-helper[93111]: -frameworkCallbackWithDictionary: threw exception calling home.
Jul 23 03:00:11 servername diskimages-helper[93111]: threw exception reporting results back to framework.
Jul 23 03:00:21 servername hdiejectd[93114]: quitCheck: calling exit(0)
When run manually, that output is as follows (no diskimages-helper
exceptions):
Jul 23 14:29:27 servername hdiejectd[7776]: running
Jul 23 14:29:40 servername hdiejectd[7776]: quitCheck: calling exit(0)
In both cases there is no user logged in via the GUI. I have a couple friends who're running the same script on their OD Masters and it also no longer runs via cron since upgrading to Snow Leopard Server.
I recall some issues with Mac OS X's command line disk image tools that required keychain access, but I don't recall the specifics. Did something related to that get more strict in Snow Leopard Server?
Any ideas or suggestions?
I experienced the same problem debugged the original script, for me the default expect timeout of 10 seconds was causing the embedded hdiutil command to be aborted. I fixed this by adding:
set timeout 120
In the expect script. Now the script is working fine again. My script:
Okay, I now have a working solution. I started by writing a new
bash
script (as opposed to usingexpect
) which wrapped around Apple'sserveradmin
utility (itself being a wrapper around theslapconfig -backupdb
I had been calling directly from theexpect
script):It's based on this script, but uses
bash
"here document" instead of creating a file on disc containing theserveradmin
commands (incl. plaintext password) to be run.This one worked fine when run from the command line as well, but still no
.sparseimage
was created when it was run from cron. So, the second stage of my fix was, as I mentioned above in the comments on my original question, to create alaunchd
plist to run it:Naturally, I loaded the plist w/
sudo launchctl load /Library/LaunchDaemons/tld.domain.od_backup.plist
(domain & tld changed to protect identity). And, it seems to run correctly when called bylaunchd
. The original script might've also run correctly if called bylaunchd
, but I haven't tested it.