当尝试将 MySQL 备份到 S3 时,Ubuntu 中的 Ruby cron 作业默默失败
我有两个 ruby 脚本 cron 作业,试图在 AWS EC2 实例上的 Ubuntu 10.04.2 LTS 下运行。它们都默默地失败了 - 我看到它们在 /var/log/syslog 中运行,但没有生成文件,并且将输出通过管道传输到文件中不会产生任何结果。
这些脚本基于此处的 ruby sql 备份: http://pauldowman.com/2009/02/08/mysql-s3- backup/
(这是数据库的完整备份和增量 bin-log 输出。不确定这是否重要。)
如果由 root 或其他用户从命令行运行,该脚本可以正常工作 - 它运行,我看到文件出现在 S3 存储库中,
我已经使用简单的“touch ~/foo”类型条目测试了 cron,效果很好。
我的 root 下的 cron 条目是这样的:
*/5 * * * * /home/ubuntu/mysql_s3_backup/incremental_backup.rb
感谢任何帮助或调试建议。我的想法是,当 cron 运行作业时,某些 ruby 库依赖项可能不可用。但我不明白为什么我似乎根本无法得到任何输出返回给我。非常令人沮丧。谢谢。
I have two ruby script cron jobs that I'm trying to run under Ubuntu 10.04.2 LTS on an AWS EC2 instance. They are both failing silently - I see them being run in /var/log/syslog, but there's no resulting files, and piping the output into a file creates no result.
The scripts are based on the ruby sql backups here:
http://pauldowman.com/2009/02/08/mysql-s3-backup/
(It's a full backup of the db and an incremental bin-log output. Not sure that matters.)
The script works fine if run from the command line by either root or another user - it runs, and I see the files appearing in the S3 repo
I've tested cron with a simple "touch ~/foo" type entry and that worked fine.
My cron entry under root is this:
*/5 * * * * /home/ubuntu/mysql_s3_backup/incremental_backup.rb
Appreciate any help or debugging suggestions. My thought is that some of the ruby library dependencies might not be available when cron is running the job. But I don't understand why I can't seem to get any output at all returned to me. Very frustrating. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您链接到的
full_backup.rb
脚本包含以下内容:请注意,
mysqldump
上没有完整路径。 Cron 作业通常在其环境中以非常有限的PATH
运行,我猜mysqldump
不在那个有限的PATH
中。您可以尝试在 crontab 中或在 Ruby 脚本
中设置自己的
PATH
:或者在备份脚本中指定mysqldump
(以及任何其他外部可执行文件)的完整路径。我会选择后两个选项之一(即在脚本中指定 ENV['PATH'] 或使用可执行文件的完整路径),因为这将减少您对外部因素的依赖,并且这些也将帮助避免人们在
PATH
中拥有您需要的自己的命令版本时出现问题。对
run
调用进行一些错误检查和处理也可能有用。如果任何必要的 Ruby 库无法访问(由于权限或路径问题),那么您可能会收到脚本的投诉。
The
full_backup.rb
script you link to contains this:Notice that there is no full path on
mysqldump
. Cron jobs generally run with a very limitedPATH
in their environment and I'd guess thatmysqldump
isn't in that limitedPATH
. You can try setting your ownPATH
in your crontab:Or in your Ruby script:
Or specify the full path to
mysqldump
(and any other external executables) in your backup script.I'd go with one of the latter two options (i.e. specify
ENV['PATH']
in your script or use full paths to executables) as that will reduce your dependence on external factors and these will also help avoid issues with people having their own versions of commands that you need in theirPATH
.A bit of error checking and handling on the
run
call might also be of use.If any of the necessary Ruby libraries weren't accessible (either due to permissions or path issues) then you'd probably get complaints from the script.