Running a rake task from cron on a shared webhost (joyent)

I’ve created a cron task via my webhost’s (a joyent shared accelerator)
cron control panel. The control panel has a “run now” button, when I hit
this button the thing works, I get my nice backup file created in /db,
all fine. Thing is when I leave the job to run over night, all it
creates is an empty db backup file!

Here’s the the crontab line…

11 3 * * * cd /users/home/foo/domains/foo.com/web &&
RAILS_ENV=production /usr/local/bin/rake db:mysql:backup #foo nightly
backup

What gives?

2009/8/31 bingo bob [email protected]:

11 3 * * * cd /users/home/foo/domains/foo.com/web &&
RAILS_ENV=production /usr/local/bin/rake db:mysql:backup #foo nightly
backup

Could be an issue with not being logged in? Permissions or path or
something?

Colin

Maybe, just unsure what. Annoying as it’s stopping me doing lots of rake
stuff on a schedule.

I mean I know there are solutions to run background tasks in the app but
I didn’t really want the memory overhead for now and this seems like a
quick win. If “only” I could get it working!

Any ideas what else I could try anyone?

Are you not able to see the output of the cron job? The output should
be logged somewhere or sent in an email - that depends on your hosting
environment.

If you can’t find that, you could move your command to a shell script
that is referenced by the crontab.
You can add code in that script to inspect the environment and/or
capture the output of your rake command in your own log file.
But you could use a little more information to help track down the
problem.

On Aug 31, 6:13 am, bingo bob [email protected]

Thanks to all.

I got this working in the end - the problem was with my rake
db:mysql:backup, it specfied the path to the mysqldump command, and I
don’t know why but when cron ran the command it failed due to this path
(when the rake task was run directly from the command line it worked
out). I ran “which mysqldump” and then specified that path explicitly in
the rake task - and all is good!

All is fine (I think).

But now on to stage two, all I’ve done so far with my single rake task
run from cron is create the backup file nightly. I now need to manage
these backups (cull the oldest and make a copy on another machine).

I figure I can use this command for the cull (or something like it)…

/usr/bin/find PATHTORAILSAPP/db/*.gz -mtime +14 -exec rm {} ;

and a nightly scp command to copy the files off the machine to another
machine.

Thing is, should I write rake tasks to do this stuff (how easy is that)
or should I run the commands from cron?

Any and all tips appreciated. I’ve done the first bit, so at least I’ve
got backups happening nightly (phew)!

Am 02.09.2009 um 10:27 schrieb bingo bob:

I
don’t know why but when cron ran the command it failed due to this
path

cron on linux doesn’t preserve environment variables, nor does it read
global ones (/etc/profile.d and others), i.e. if you need some, you
have to set them up yourself. Further information in ‘man crontab’
http://linux.die.net/man/5/crontab

Best regards,

Felix

2009/8/31 bingo bob [email protected]:


As you snipped everything and the message seems to have become
de-threaded no-one except possibly me will know what this message is
about.

Colin

Felix Schäfer wrote:

Am 02.09.2009 um 10:27 schrieb bingo bob:

I
don’t know why but when cron ran the command it failed due to this
path

cron on linux doesn’t preserve environment variables, nor does it read
global ones (/etc/profile.d and others), i.e. if you need some, you
have to set them up yourself. Further information in ‘man crontab’
http://linux.die.net/man/5/crontab

Best regards,

Felix

Ok well that makes sense then - noted.

Any tips on the backup side of things?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs