Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm using backup_fu to backup my database. In the crontab, you have this command:

* * * * * cd /var/www/amplify/current && RAILS_ENV=production /usr/bin/env rake backup

Yes, I know a backup a minute is intense, but I'm just doing it to test. I will change the interval once I get it working.

  • However, running it in cron doesn't it backup. When I check my Amazon S3 account, I don't see a .tar.gz file.
  • When I SSH in, and I paste the command exactly, it backs up and I see the .tar.gz in Amazon S3.

Note:

  • I'm using RVM. However, as shown in this thread, if I cd into the directory, the proper ruby selection happens.
  • I'm on CentOS: Linux version 2.6.18-194.8.1.el5.028stab070.5 (root@rhel5-build-x64) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-46)) #1 SMP Fri Sep 17 19:10:36 MSD 2010
  • I checked /var/log/cron and it seems that it runs: Feb 27 00:20:01 amplify crond[1667]: (ramon) CMD (cd /var/www/amplify/current && RAILS_ENV=production /usr/bin/env /usr/bin/rake backup)

Any help is appreciated, thanks!

share|improve this question
add comment

5 Answers

Setting PATH in your crontab isn't very portable I suggest you do something like this:

~ $ rvm env --path                                                                                                                                  
/Users/james/.rvm/environments/ruby-1.9.3-p392

What in that file:

~ $ cat `rvm env --path`                                                                                                                            
export PATH ; PATH="/Users/james/.rvm/gems/ruby-1.9...

So we can do this:

~ $ crontab -e
0 * * * * source /Users/james/.rvm/environments/ruby-1.9.3-p392 && command
# or 
0 * * * * rvm use 1.9.3@myenv && source `rvm env --path` && command
share|improve this answer
add comment
up vote 2 down vote accepted

It seems that this ended up becoming an RVM issue, and not a server one. I apologize. Thanks for your answers; they've helped me figure it out.

The final one that worked was:

cd /var/www/amplify/current && source /home/ramon/.rvm/environments/ree-1.8.7-2010.02@rails3 && RAILS_ENV=production /home/ramon/.rvm/gems/ree-1.8.7-2010.02@rails3/bin/rake backup &>/home/ramon/backup.log

The key was to use source /home/ramon/.rvm/environments/ree-1.8.7-2010.02@rails3.

When I asked Wayne Seguin about cd'ing into the directory and autoloading .rvmrc, he said it'll only work if:

  • RVM is loaded properly as a function (type rvm | head -1)
  • The .rvmrc has been trusted previously

So it seems that in cron, RVM isn't loaded properly as a function, since I've "trusted" the .rvmrc before.

share|improve this answer
add comment

This:

/usr/bin/env rake backup

depends on the PATH containing the location of rake. It's the same as simply having

rake backup

The environment for cron is different than that for your interactive session. Change the line in your crontab to point directly to the rake executable:

* * * * * cd /var/www/amplify/current && RAILS_ENV=production /path/to/rake backup

or set your crontab's PATH (within the crontab) to include it:

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/path/to/where/rake/is
share|improve this answer
add comment

Put your cronjob into separate script and call it in crontab.

cd /var/www/amplify/current && RAILS_ENV=production /usr/bin/env rake backup
share|improve this answer
add comment

Have you checked the mail for the account running the cron job, output from the command should appear there and may contain clues as to the problem.

Capture the output of the command to a file add &>/path/to/logfile to the end of the command to find out what is happening.

share|improve this answer
    
Thanks. With this I was able, to pinpoint the problem to RVM, it seems. I'm still investigating further and will update you. –  Ramon Tayag Feb 27 '11 at 18:30
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.