Home > MiniITX > Automatically backing-up SVN to a server

Automatically backing-up SVN to a server

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

Workshed MiniITX

  1. Neil
    July 30th, 2008 at 11:09 | #1

    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.

  2. August 6th, 2008 at 21:46 | #2

    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…

  3. November 12th, 2008 at 11:25 | #3

    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!

  4. November 12th, 2008 at 20:01 | #4

    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…

  5. January 25th, 2009 at 00:57 | #5

    LUvfTj hi! nice site!

  1. No trackbacks yet.