Discussion:
Problem using "svnadmin dump" in a cron job
Robert Dailey
2008-07-20 17:28:24 UTC
Permalink
Hi,

I'm currently using crontab to setup a backup script that runs at
various intervals to backup my subversion repository. First, it
performs an "svnadmin dump" as user 'root' in Ubuntu Server 8.04.
Next, it utilizes the '7z' program to compress the dump file. I'm
having an issue right now where the dump process will just cease to
continue at any given random location in the dump process. For
example, it might go all the way up to revision 26 and then stop
there, instead of performing the dump for all revisions in the
repository. The revision that the dump stops at seems to be random.

Below is my crontab file for user 'root', which I access by executing:
su -c "crontab -e"
------------------------------------------------------------------
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 * * * script -c "/var/svn/scripts/backup" -f "/tmp/svnbackup.log"
------------------------------------------------------------------

And this is my "/var/svn/scripts/backup" bash script file:
------------------------------------------------------------------
#!/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."
------------------------------------------------------------------

And finally, below is the contents of the "/tmp/svnbackup.log" file.
Notice how it stops at revision 26 for no reason at all: No error, no
warning, nothing...
------------------------------------------------------------------
Script started on Sun Jul 20 12:17:01 2008
Starting dump process...
* Dumped revision 0.
* Dumped revision 1.
* Dumped revision 2.
* Dumped revision 3.
* Dumped revision 4.
* Dumped revision 5.
* Dumped revision 6.
* Dumped revision 7.
* Dumped revision 8.
* Dumped revision 9.
* Dumped revision 10.
* Dumped revision 11.
* Dumped revision 12.
* Dumped revision 13.
* Dumped revision 14.
* Dumped revision 15.
* Dumped revision 16.
* Dumped revision 17.
* Dumped revision 18.
* Dumped revision 19.
* Dumped revision 20.
* Dumped revision 21.
* Dumped revision 22.
* Dumped revision 23.
* Dumped revision 24.
* Dumped revision 25.
* Dumped revision 26.
------------------------------------------------------------------
Ryan Schmidt
2008-07-21 02:21:18 UTC
Permalink
Post by Robert Dailey
I'm currently using crontab to setup a backup script that runs at
various intervals to backup my subversion repository. First, it
performs an "svnadmin dump" as user 'root' in Ubuntu Server 8.04.
Next, it utilizes the '7z' program to compress the dump file. I'm
having an issue right now where the dump process will just cease to
continue at any given random location in the dump process. For
example, it might go all the way up to revision 26 and then stop
there, instead of performing the dump for all revisions in the
repository. The revision that the dump stops at seems to be random.
su -c "crontab -e"
------------------------------------------------------------------
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 * * * script -c "/var/svn/scripts/backup" -f "/tmp/
svnbackup.log"
------------------------------------------------------------------
------------------------------------------------------------------
#!/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
You should log the stderr output too, not just the stdout output.
This way when an error occurs you should know why.

svnadmin dump /var/svn/repo/personal > ${filepath}.tmp_dump 2>&1
Post by Robert Dailey
echo "Dump process finished"
if [ "$?" != "0" ]; then
echo "Failed to generate dump file"
Usually you would print errors to stderr, not stdout.

echo "Failed to generate dump file" 1>&2
Post by Robert Dailey
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"
Same here.

echo "Failed to compress the dump file" 1>&2
Post by Robert Dailey
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."
------------------------------------------------------------------
And finally, below is the contents of the "/tmp/svnbackup.log" file.
Notice how it stops at revision 26 for no reason at all: No error, no
warning, nothing...
------------------------------------------------------------------
Script started on Sun Jul 20 12:17:01 2008
Starting dump process...
* Dumped revision 0.
* Dumped revision 1.
* Dumped revision 2.
* Dumped revision 3.
* Dumped revision 4.
* Dumped revision 5.
* Dumped revision 6.
* Dumped revision 7.
* Dumped revision 8.
* Dumped revision 9.
* Dumped revision 10.
* Dumped revision 11.
* Dumped revision 12.
* Dumped revision 13.
* Dumped revision 14.
* Dumped revision 15.
* Dumped revision 16.
* Dumped revision 17.
* Dumped revision 18.
* Dumped revision 19.
* Dumped revision 20.
* Dumped revision 21.
* Dumped revision 22.
* Dumped revision 23.
* Dumped revision 24.
* Dumped revision 25.
* Dumped revision 26.
------------------------------------------------------------------
Robert Dailey
2008-07-21 03:09:32 UTC
Permalink
On Sun, Jul 20, 2008 at 9:21 PM, Ryan Schmidt
Post by Robert Dailey
I'm currently using crontab to setup a backup script that runs at
various intervals to backup my subversion repository. First, it
performs an "svnadmin dump" as user 'root' in Ubuntu Server 8.04.
Next, it utilizes the '7z' program to compress the dump file. I'm
having an issue right now where the dump process will just cease to
continue at any given random location in the dump process. For
example, it might go all the way up to revision 26 and then stop
there, instead of performing the dump for all revisions in the
repository. The revision that the dump stops at seems to be random.
<snip>
You should log the stderr output too, not just the stdout output. This way
when an error occurs you should know why.
svnadmin dump /var/svn/repo/personal > ${filepath}.tmp_dump 2>&1
Post by Robert Dailey
echo "Dump process finished"
if [ "$?" != "0" ]; then
echo "Failed to generate dump file"
Usually you would print errors to stderr, not stdout.
echo "Failed to generate dump file" 1>&2
Post by Robert Dailey
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"
Same here.
echo "Failed to compress the dump file" 1>&2
Post by Robert Dailey
<snip>
Thanks for your help.

I'm still new to linux & bash scripting, so please do forgive any poor
scripts you see. I'll definitely make use of your suggestions, though.
The 1>&2 syntax makes no sense, so I'll have to read about it after I
write this.

I'll try the suggestions you offered and see if I can figure out why
it is failing. Thanks again.
Ryan Schmidt
2008-07-21 03:23:11 UTC
Permalink
Post by Robert Dailey
Post by Robert Dailey
I'm currently using crontab to setup a backup script that runs at
various intervals to backup my subversion repository. First, it
performs an "svnadmin dump" as user 'root' in Ubuntu Server 8.04.
Next, it utilizes the '7z' program to compress the dump file. I'm
having an issue right now where the dump process will just cease to
continue at any given random location in the dump process. For
example, it might go all the way up to revision 26 and then stop
there, instead of performing the dump for all revisions in the
repository. The revision that the dump stops at seems to be random.
<snip>
You should log the stderr output too, not just the stdout output. This way
when an error occurs you should know why.
svnadmin dump /var/svn/repo/personal > ${filepath}.tmp_dump 2>&1
Post by Robert Dailey
echo "Dump process finished"
if [ "$?" != "0" ]; then
echo "Failed to generate dump file"
Usually you would print errors to stderr, not stdout.
echo "Failed to generate dump file" 1>&2
Thanks for your help.
I'm still new to linux & bash scripting, so please do forgive any poor
scripts you see. I'll definitely make use of your suggestions, though.
The 1>&2 syntax makes no sense, so I'll have to read about it after I
write this.
"echo" sends its output to stdout. "1>&2" means "take what would be
output to file descriptor 1 (stdout) and instead send it to the
address of file descriptor 2 (stderr)".
Post by Robert Dailey
I'll try the suggestions you offered and see if I can figure out why
it is failing. Thanks again.
Loading...