SVN back-up and restore

To back-up my SVN repository, I have the following script:


#!/bin/bash
SVNDIR=/var/svn
DATE=`date +%d-%m-%Y`
TARNAME=svn_dump_$DATE.bz2
cd $SVNDIR
rm -f *.svndump
rm -f *.bz2
for repo in $(ls -d */)
do
filename=`basename $repo | cut -d\. -f1`
svnadmin dump $repo > $SVNDIR/$filename.svndump
done
tar -cvz -f $SVNDIR/$TARNAME *.svndump
cp $TARNAME /home/yo/svn_dump

Basically, it iterates thru all my repositories in SVNDIR and dumps them (the back up process itself) with svadmin dump.... After that it tars and compress the *.svndump files in one single file TARNAME and then copies it to its final destination /home/yo/svn_dump from where I grab the tar.bz2 files and burn them in a DVD or whatever.

I also have a cron job as follows:

0 0 * * 7 /home/yo/bin/scripts/svndump.sh >/dev/null 2>&1

which runs the script above once a week.

To restore a svn dump file I have to:
1) Untar the tar.bz2 back up file.
2) With the result I run: svnadmin load /path/to/reponame < filename.svndump
3) Set the correct permissions to the restored repositories. This is needed if you restore the back-up in a different path or computer.

That's pretty much what I do. My source code is safe in several different places (I'm a little bit paranoid, I know...)

Leave a Reply