VanLouin
asked on
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
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
ASKER
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.
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.
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/userna me/bin ; export PATH
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/userna
ASKER
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
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
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)?
ASKER
##! /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.
##########################
# 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
generated either)
/bin/gzip $dest1/SVN_Blackbox_Backup
cp $dest1/SVN_Blackbox_Backup
echo
echo //////////////////////////
echo / Backup of SVN for $today - COMPLETE /
echo //////////////////////////
echo
PS Thank you very much for your assistance it is much appreciated.
What is the backup file size when it stops?
ASKER
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
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
ASKER
Uncompressed File Size via CRON: 146029554
never gets passed this ?
Cheers,
Kevan
never gets passed this ?
Cheers,
Kevan
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
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
ASKER
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/scri pts$ 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/scri pts:/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_Dai ly_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
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/scri
-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/
# 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_Dai
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
.bash_history cron-env.txt .profile .sudo_as_admin_successful
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Forced accept.
Computer101
EE Admin
Computer101
EE Admin
I could see that you are using some commands that with command name and not the full path name to it.