0
votes

I Want to set a script and use a cronjob to take a backup of all the repositories.

FYI...

RVM Version: 1.20.13, Ruby Version: 1.9.3p429, Gem Version: 1.8.25, Bundler Version:1.3.5, Rake Version: 10.0.4, GitLab information Version: 5.3.0

I Tried the methods below, but they didn't work. Please help me to set the required cronjob. When I execute the commands manually they were working fine.

Method 1:

#!/bin/bash

cd /home/git/gitlab/

bundle exec rake gitlab:backup:create RAILS_ENV=production

Error:

bundle: command not found

Method 2:

#!/bin/sh

cd /home/git/gitlab/ 

bundle exec rake gitlab:backup:create RAILS_ENV=production

Error:

/bin/sh: bundle: command not found

Method 3:

10 10 * * * cd /home/git/gitlab && PATH=$PATH:$/home/git/.rvm/gems/ruby-1.9.3-p429/bin:/home/git/.rvm/gems/ruby-1.9.3-p429@global/bin:/home/git/.rvm/rubies/ruby-1.9.3-p429/bin:/home/git/.rvm/bin::/home/git/.rvm/rubies/ruby-1.9.3-p429/.irbrc bundle exec rake gitlab:backup:create RAILS_ENV=production CRON=1 >> /tmp/git_bck.log 2>&1

Error:

/home/git/.rvm/gems/ruby-1.9.3-p429@global/bin/ruby_noexec_wrapper:7:in `require': no such file to load -- rubygems (LoadError) from /home/git/.rvm/gems/ruby-1.9.3-p429@global/bin/ruby_noexec_wrapper:7

2
The main answer for stackoverflow.com/questions/5835675/… may be of some help. Good luck.shellter

2 Answers

1
votes

you need to do 2 things:

1) recreate the same environment you have in the command line. For this run env in the command line and after that run env in a cron and output to a shell, compare the 2 of them

2) source rvm in (look in your .bashrc or whatever rc your shell has).

These 2 things should allow you to run the script from the cron. You can place them in the beging of the script.

0
votes

Problem solved :

In .bashrc , added

PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting

export GIT_HOME=/home/git/git

export JAVA_HOME=/home/git/jdk

export PATH=$PATH:$GIT_HOME/bin:$JAVA_HOME/bin

source /home/git/.rvm/environments/default


In .bash_profile, added

PATH=$PATH:$HOME/bin

export PATH

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"


FYI..

cat /home/git/.rvm/environments/default

export PATH ; PATH="/home/git/.rvm/gems/ruby-1.9.3-p429/bin:/home/git/.rvm/gems/ruby-1.9.3-p429@global/bin:/home/git/.rvm/rubies/ruby-1.9.3-p429/bin:/home/git/.rvm/bin:$PATH"

export rvm_env_string ; rvm_env_string='ruby-1.9.3-p429'

export rvm_path ; rvm_path='/home/git/.rvm'

export rvm_ruby_string ; rvm_ruby_string='ruby-1.9.3-p429'

unset rvm_gemset_name

export RUBY_VERSION ; RUBY_VERSION='ruby-1.9.3-p429'

export GEM_HOME ; GEM_HOME='/home/git/.rvm/gems/ruby-1.9.3-p429'

export GEM_PATH ; GEM_PATH='/home/git/.rvm/gems/ruby-1.9.3-p429:/home/git/.rvm/gems/ruby-1.9.3-p429@global'

export MY_RUBY_HOME ; MY_RUBY_HOME='/home/git/.rvm/rubies/ruby-1.9.3-p429'

export IRBRC ; IRBRC='/home/git/.rvm/rubies/ruby-1.9.3-p429/.irbrc'

unset MAGLEV_HOME

unset RBXOPT


In crontab script :

cd /home/git/gitlab/

source $HOME/.bash_profile

source $HOME/.bashrc

bundle exec rake gitlab:backup:create RAILS_ENV=production