Automatically backing-up SVN to a server

Category : MiniITX · by Jul 7th, 2008

As I have a rather large amount of webspace I decided it would be a good idea to backup the subversion repository to it. This provides good redundancy for a SVN/computer problem!

To achieve this i created the following script for my Debian server:

#!/bin/sh
#
#  Description:SVN backup script
#
# The DATE-parameter tells date in format YYYY.MM.DD.
DATE=`date +20%y.%m.%d`

# The TIME-parameter tells time in format HHMMSS.
TIME=`date +%H%M%S`

# The BACKUPDIR-parameter specifices where we want to save our backups
BACKUPDIR=/backup_directory

# REPOS SVN
REPOS=/Repository_location
REPOS_OUTPUT=output_name_”$DATE”_”$TIME”

svnadmin dump $REPOS > $BACKUPDIR/$REPOS_OUTPUT.dump
tar cvzf $BACKUPDIR/$REPOS_OUTPUT.tgz $BACKUPDIR/$REPOS_OUTPUT.dump

HOST=’ftp.address.co.uk’
USER=username
PASSWD=password

FILE=$REPOS_OUTPUT.tgz
cd $BACKUPDIR
echo pwd
ftp -n -v $HOST << EOT
user $USER $PASSWD
put $FILE
quit
EOT

rm $BACKUPDIR/$REPOS_OUTPUT.tgz
rm $BACKUPDIR/$REPOS_OUTPUT.dump

exit 0

SHARE :

(5) comments

Neil
10 years ago · Reply

I have a similar script that emails a backup of my local SVN repository to my hotmail account, since they have so much storage these days:

rm $BACKUPDIR/svndump.bz2
date > $BACKUPDIR/svndumplog
svnadmin dump $REPOSDIR 2>> $BACKUPDIR/svndumplog | bzip2 > $BACKUPDIR/svndump.bz2
email -q -s “SVN Backup `date`, size: `du $BACKUPDIR/svndump.bz2 -h | grep ‘^[^[:space:]]*’ -o`” -a $BACKUPDIR/svndump.bz2 -r smtp.isp.example.com -n “SVN Backup” -f “example1@example.com” example2@example.com < $BACKUPDIR/svndumplog

Most of that is just getting fancy with the email title. I send it both to my normal account and to my hotmail, hence the two addresses. It’s in a cron-job that runs something like once a week. The nice thing about doing it via email is it’s easy to see if the job is working consistently by looking at the dates.

Workshed
10 years ago · Reply

Thats really quite a cunning idea!
Having seen a recent slashdot article I was getting curious about using rsync to backup just the differences between backups and keeping archives but given the amount of webspace i’ve got floating around i’m not sure i can be bothered…

Jon
10 years ago · Reply

I’d create a CRC of the repository (or some other way of tracking what’s changed) and then only back up if your repository has been altered once a week or something. Not so much of a problem if you’re frequently changing it, but would save duplication.

I keep thinking I ought to do something similar for my own repositories!

Workshed
10 years ago · Reply

Thats a good idea Jon but the repositories arent really big enough for me to be bothered about that as yet. The time may well come though…

vatslav
10 years ago · Reply

LUvfTj hi! nice site!

Leave a Reply

Your email address will not be published. Required fields are marked *