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!
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:
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:
So it seems that in cron, RVM isn't loaded properly as a function, since I've "trusted" the .rvmrc before.
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.This:
depends on the
PATH
containing the location ofrake
. It's the same as simply havingThe environment for
cron
is different than that for your interactive session. Change the line in your crontab to point directly to therake
executable:or set your crontab's
PATH
(within the crontab) to include it:Setting
PATH
in your crontab isn't very portable I suggest you do something like this:What in that file:
So we can do this:
Put your cronjob into separate script and call it in crontab.