几年前,我把下面的expect脚本放在Tiger Server下执行Open Directory备份 ,并在Leopard Server下运行良好:
#!/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
它是仍然存在于root的crontab中的less数几个脚本之一,而不是一个launchd plist。 只是出于安全的原因,它只是root权限。
现在,问题是我几个星期前升级我的开放目录主到Mac OS X 10.6.4雪豹服务器,并没有工作,因为…当由Cron运行。 如果我以root用户身份login并手动运行,它将正常工作并创build生成的encryption磁盘映像。 当由cron运行时,它会经历完整的运动(包括/Library/Logs/slapconfig.log中的输出,与手动运行时的输出相匹配),但永远不会创build磁盘映像文件。 但是,在`/var/log/system.log/中,我看到以下输出:
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)
手动运行时,输出如下(没有diskimages-helperexception):
Jul 23 14:29:27 servername hdiejectd[7776]: running Jul 23 14:29:40 servername hdiejectd[7776]: quitCheck: calling exit(0)
在这两种情况下都没有用户通过GUIlogin。 我有几个朋友在OD Master上运行相同的脚本,并且升级到Snow Leopard Server后也不再运行cron。
我记得一些Mac OS X的命令行磁盘映像工具需要钥匙串访问的问题,但我不记得具体细节。 有没有相关的东西在雪豹服务器更严格?
任何想法或build议?
我遇到了同样的问题debugging了原来的脚本,对我来说默认的期望超时10秒是导致embedded的hdiutil命令被中止。 我通过添加以下内容来解决此问
设置超时120
在期望的脚本。 现在脚本再次正常工作。 我的脚本:
#!/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" set timeout 120 spawn /usr/sbin/slapconfig -backupdb $archive_path/$archive_name-$date expect "Enter archive password" send "$archive_password\r" expect eof
好的,我现在有一个工作的解决scheme。 我开始写一个新的bash脚本(而不是使用expect ),这个脚本包装了Apple的serveradmin工具(本身就是一个围绕slapconfig -backupdb的包装,我直接从expect脚本调用):
#!/bin/bash dst="/path/to/your/backup/directory" pass="password" host=$(hostname) date=$(date +%Y-%m-%d-%H%M) serveradmin command <<-EOC dirserv:backupArchiveParams:archivePassword = $pass dirserv:backupArchiveParams:archivePath = ${dst}/od_backup-${host}-${date} dirserv:command = backupArchive EOC
它基于这个脚本 ,但是使用bash “here文档”而不是在包含要运行的serveradmin命令(包括明文密码)的光盘上创build一个文件。
从命令行运行也能正常工作,但是从cron运行时,仍然没有创build.sparseimage 。 所以,我修正的第二个阶段,就像我上面在我原来的问题的评论中提到的那样,创build一个launchd plist来运行它:
<?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>tld.domain.od_backup</string> <key>ProgramArguments</key> <array> <string>/var/root/sbin/od_backup</string> </array> <key>StartCalendarInterval</key> <dict> <key>Hour</key> <integer>2</integer> <key>Minute</key> <integer>30</integer> </dict> </dict> </plist>
自然,我加载了plist w / sudo launchctl load /Library/LaunchDaemons/tld.domain.od_backup.plist改为保护标识)。 而且, launchd调用它似乎运行正常。 如果被launchd调用,原始脚本也可能正确运行,但是我没有testing过它。