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.
The
full_backup.rbscript you link to contains this:Notice that there is no full path on
mysqldump. Cron jobs generally run with a very limitedPATHin their environment and I’d guess thatmysqldumpisn’t in that limitedPATH. You can try setting your ownPATHin 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
runcall 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.