/Applications/MAMP/Library/bin/mysqldump --opt -u root -proot --host=localhost --all-databases > ~/Dropbox/Development/Shared\ DBs/BACKUPS/all_databases_-'date "+%Y-%m-%d_%H.%M.%S"'.sql
输入终端后,可以正常工作。
我需要自动执行此备份,因此编写了以下plist文件,并将其放入 ~/Library/LaunchAgents/com.localhost.cron.plist
然后运行launchctl load ~/Library/LaunchAgents/com.localhost.cron.plist
,但不会每2分钟触发一次。
知道我在做什么错吗?
<?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>com.localhost.cron.plist</string>
<key>ProgramArguments</key>
<array>
<string>/Applications/MAMP/Library/bin/mysqldump --opt -u root -proot --host=localhost --all-databases > ~/Dropbox/Development/Shared\ DBs/BACKUPS/all_databases_-`date "+%Y-%m-%d_%H.%M.%S"`.sql</string>
</array>
<key>StartInterval</key>
<integer>120</integer>
</dict>
</plist>
我正在使用OS X Mavericks和最新的MAMP。
提前致谢。
下面选择的答案很好地回答了我的问题,但我发现我认为是更好的方法(选择您的方法)。它在这里可用:将Stderr发送给dev / null,但是如果没有错误发生,请继续
您的ProgramArgument
值不正确。您应该为每个参数提供一个额外的字符串。这应该更好地工作:
<key>ProgramArguments</key>
<array>
<string>/Applications/MAMP/Library/bin/mysqldump</string>
<string>--opt</string>
<string>-u</string>
<string>root</string>
<string>-proot</string>
<string>--host=localhost</string>
<string>--all-databases</string>
</array>
输出重定向是通过key完成的StandardOutPath
,但是shell的扩展~
将无法工作。同时启动将不允许您的shell命令创建动态文件名。您最好将所有这些包装在shell脚本中,然后从launchd调用它。
为了仅在MySQL运行时运行此脚本,可以使用如下KeepAlive
键:
<key>KeepAlive</key>
<dict>
<key>PathState</key>
<dict>
<key>/var/run/mysql.pid</key>
<true/>
</dict>
</dict>
这种方法假定您的MySQL实例将其当前的PID写入文件/var/run/mysql.pid
。该文件仅在MySQL运行时存在。
正如您正确指出的那样StartInterval
,KeepAlive
不要一起工作。无论PID文件是否存在,都会触发脚本。正确的方法是使用ThrottleInterval
而不是StartInterval
。该键确定两次启动之间必须经过多少时间。像这样使用它:
<ThrottleInterval>
<integer>120</integer>
看一看launchd.plist(5)
。它详细解释了所有选项。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句