Need help setting up cron

Robert Dailey rcdailey at gmail.com
Sun Jul 20 15:49:00 UTC 2008


On Fri, Jul 18, 2008 at 3:52 AM, Luca Ferrari <fluca1978 at infinito.it> wrote:
> On Thursday 17 July 2008 Robert Dailey's cat, walking on the keyboard, wrote:
>> I found out that my script was broken. After fixing it, however, I
>> noticed that my directories were being created, but it didn't seem to
>> be doing anything else. Note that this script is performing a backup
>> and then compressing files. This process can take up to 30 minutes or
>> maybe more. The first thing the script is supposed to do is create a
>> subversion repository dump file which is about 600MB in size. 20
>> minutes after the script was executed, I noticed my dump file was
>> created but it was 0 bytes in size. It's almost as if the script was
>> prematurely interrupted and wasn't given enough time to finish.
>
> I had similar problems with backup scripts and cron, especially when involving
> ssh tasks. If the script runs fine from an interactive shell and does not
> from cron, try setting the environment variables as for your interactive
> shell. In the crontab palce an entry like:
> ENV=/home/myself/.profile
>
> and log your backup output to a file to see if it is working and where it is
> stopping:
>
> 30 12 * * * root /my/script/file > /tmp/debug.log
>
> Hope this helps,
> Luca

I did as you instructed Luca, however adding ENV=... didn't help at
all, for some reason. Here's what I did:

1) Made my script output to a log as you instructed. The log shows
that the script is completely being executed from top to bottom,
however for some reason the "svnadmin dump" command is being
interrupted. It only creates a dump file that is 0 bytes in size.
2) Since it still wasn't working, I managed to go to /etc/crontab and
copy out the 2 variables it defined at the top of the file and place
them in my user-specific crontab file. I access root's crontab via the
following command: su -c "crontab -e"
3) After adding in these variables, I find that my "svnadmin dump"
command now outputs about 207MB of data, however that isn't the full
size of what it should be. The dump file should be approximately
600MB.

I'm out of ideas so far, so any other help would be appreciated. I
can't understand at all why "svnadmin dump" works fine from the
command line, but running it from cron causes it to be interrupted.

Below is my crontab file for user 'root':

ENV=/home/robert/.profile
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h  dom mon dow   command
41 10 * * * /var/svn/scripts/backup > /tmp/svnbackup.log




And this is my /var/svn/scripts/backup script (For those interested in it):

#!/bin/bash

# Backup the 'personal' repository.
filename=$(date +%Y-%m-%d)

# Create destination directory first
dst_dir="/var/svn/backup"
if [ ! -e $dst_dir ]; then
    mkdir -p $dst_dir
    echo "Created ${dst_dir}"
fi

filepath=${dst_dir}/${filename}

# Create the dump file
echo "Starting dump process..."
svnadmin dump /var/svn/repo/personal > ${filepath}.tmp_dump
echo "Dump process finished"
if [ "$?" != "0" ]; then
    echo "Failed to generate dump file"
    exit 1
fi

# Attempt to compress the dump file
echo "Beginning to compress dump file..."
7z a -mx=9 -ms=on ${filepath}.7z ${filepath}.tmp_dump
echo "Dump file now compressed"
if [ "$?" != "0" ]; then
    echo "Failed to compress the dump file"
    exit 1
fi

# Remove old tmp_dump file, but only if the
# compression was successful.
#echo "Deleting uncompressed dump file..."
#rm ${filepath}.tmp_dump

echo "Backup process completed."




More information about the ubuntu-users mailing list