Subversion Backup Script works Manually but not via Cron

I can run the following script from command line and complete backup of subversion works.

If I add it to crontab it starts to create the file but stops backing up after a few minutes...? wierd.

Any ideas:

Partial Script Below:

#############
today=$(date +"%d%m%y")                 #Get Todays Date
backup_path="/svn/"                     #Subversion Repository Location
dest="/home/devone"                     #Backup File Location (DC2 Share)


###################
# Pre-Backup Prep #
###################
# find /home/backups -mtime +3 -exec /bin/rm -f {} \; #Delete Old Files > 3d

##############################################################################
# Backup Subversion Repository to /home/backups (CIFS Share on InteliscanDC2 #
##############################################################################
svnadmin dump $backup_path > $dest/SVN_Backup_$today

VanLouinAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

omarfaridCommented:
Generally, crontab jobs need some env variables setting. Also, when refering to commands, please use full path names since the env var PATH is not set.

I could see that you are using some commands that with command name and not the full path name to it.

0
VanLouinAuthor Commented:
Hello Omarfarid,

Thanks for the reply. The crontab entry has the full path to the script location should
this not suffice given that when I run ./Blackbox_Backups from the script directry
the backup works perfectly ?

How would I set environment variables if tat is the case.

Best Regards,
Vanlouin

PS Thanks again for taking the time to look.

0
omarfaridCommented:
When you login to the server then your login shell will set some env variables for you and will look for .profile in your home dir if it is sh or ksh, or .login if it is csh, or .bash_profile if bash.

One of those env variables is PATH. But when you run a crontab job this env variable and others are not set. So if you use commands which work from your command prompt when logged in, it will not work till you either set PATH in the script itself, or use the full path name to the command.

e.g.

I can see that you are using commands like date, svnadmin, etc, which the crontab does not know where to find them.

You may set env variables like

PATH=/usr/bin:/home/username/bin ; export PATH
0
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

VanLouinAuthor Commented:
Hello Omarfarid,

I've put in the full paths and the job runs but as per original problem stops
part the way through the creation of the backup file. Is there a Memory
useage environment variable, a limit that is being reached during the exection of
the backup script ? it stops at exactly the same position every time.
Yet when run manually it works fine.

Best Regards,
Kevan
0
omarfaridCommented:
Can you post the script that run as crontab job and error messages (if any. errors / messages are mailed to the user for crontab jobs)?
0
VanLouinAuthor Commented:
##! /bin/bash

###################################################
# Purpose: Backup of SVN and management of said Backups #
# Date Created: 21-JAN-08                          #
# By: K.Somerville                                #
###################################################

#############
# Variables #
#############
today=$(date +"%d%m%y")             #Get Todays Date
backup_source="/svn/"                  #Subversion Repository Location
dest1="/home/devone"                  #Staging Location (Local-NoCompress)
dest2="/home/backups"                  #Final location (IntelliscanDC2)

###################
# Pre-Backup Prep #
###################
clear                        #Clear Screen - Display Message
echo
echo ///////////////////////////////////////
echo / Backup of SVN for $today - STARTED  /
echo ///////////////////////////////////////
echo

find $dest1/SVN_* -mtime +1 -exec /bin/rm -f {} \; #Delete Old Files

###############################################################################
# Backup Subversion Repository to /home/backups (CIFS Share on InteliscanDC2) #
###############################################################################
/usr/bin/svnadmin dump $backup_source > $dest1/SVN_Blackbox_Backup_$today <--- KS Actually Runs this then stops at the same file size everytime. (No lac of space on disk that I can see. No errors
generated either)
/bin/gzip $dest1/SVN_Blackbox_Backup_$today
cp $dest1/SVN_Blackbox_Backup_$today.gz $dest2
echo
echo ///////////////////////////////////////
echo / Backup of SVN for $today - COMPLETE /
echo ///////////////////////////////////////
echo

PS Thank you very much for your assistance it is much appreciated.
0
omarfaridCommented:
What is the backup file size when it stops?
0
VanLouinAuthor Commented:
Compressed Size is.
Manually: 1611554111
Via Cron: 3602963

Uncompressed:
Manually: 4,595,208,192
Don't have to hand will let you shortly if you require it....

Thanks Kevan

0
VanLouinAuthor Commented:
Uncompressed File Size via CRON: 146029554
never gets passed this ?

Cheers,
Kevan
0
omarfaridCommented:
When you run the script manually, do you run it as root, or some other user?

And when you run it as crontab job, do you run it under the same user?

can you show what is in your ~/.bash_profile
0
VanLouinAuthor Commented:
Is there anyway to force the crontab to run with another profile i.e. with the environment settings that
are used when the command is run from the command line ?

Both the original and New scripts (highlited below) are run as root from the crontab (also shown below)

DIRECTORY LISTING:
devone@blackbox:/home/scripts$ ls -l
-rwsr-sr-x 1 root root 1796 2008-02-19 18:02 Blackbox_Backups <-- This is original
-rwxr-xr-x 1 root root 1950 2008-02-20 14:05 Blackbox_Daily_Backup <-- This is New
-rwxr-xr-x 1 root root 1568 2008-02-20 10:35 Incoming_Copy

CRONTAB FILE:
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/home/scripts:/home/devone

# m h dom mon dow user  command
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.$
47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.$
52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.$
20 14   * * *   root    /home/scripts/Blackbox_Daily_Backup

I couldn't find the Bash_profle am I perhaps looking in the wrong location ? Please see output below.
devone@blackbox:~$ ls -a
.              .bash_logout  devone-env.txt  .ssh                       SVN_Blackbox_Backup_190208
..             .bashrc       .nano_history   .subversion                SVN_Blackbox_Backup_190208.gz
.bash_history  cron-env.txt  .profile        .sudo_as_admin_successful
0
omarfaridCommented:
You can always source the .profile:

. /path/to/.profile (please not the dot at the beginning)

Why you are using ## in

##! /bin/bash

You may refer to man page of bash:

http://www.gnu.org/software/bash/manual/bashref.html
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Computer101Commented:
Forced accept.

Computer101
EE Admin
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.