SVN backup

After a long period I’ve decided to start posting things here again

This time, they will be only small probably useful scripts, which you can use the same way I do

At the moment I’m moving to a new dedicated server, and want to ensure that my backup procedures are up running and work as I would expect them

A few months ago I’ve exploded my svn repository from a single one to one per project, so I had to create a script which back them all up

#!/bin/sh
DATE=`/bin/date +%y%m%d`
SVNDIR="" # this is the folder where all your repos are
BACKUPDIR="" # this is the folder where your backup tree will be created
echo "Backing up SVN repositories"
for repo in `ls -1 $SVNDIR`
do
  echo "Processing $repo repo..."
  mkdir -p $BACKUPDIR/$repo/revs
  LASTBACKUP=`ls -1 $BACKUPDIR/$repo/revs/svn-*.tgz|cut -d\- -f2|cut -d\. -f1|sort -n|tail -1`
  if [ "$LASTBACKUP" == "" ]; then
  	LASTBACKUP=-1
  else
  	LASTBACKUP=$(echo $LASTBACKUP | sed 's/0*//')
  fi
  ((LASTBACKUP++))
  LASTREVISION=$(svnlook youngest $SVNDIR/$repo)
  if [ $LASTBACKUP -le $LASTREVISION ]; then
  echo "Backing up $repo from $LASTBACKUP till $LASTREVISION "
  cd $BACKUPDIR/$repo/revs
  for r in $(seq -f "%05g" $LASTBACKUP $LASTREVISION); do
  	svnadmin dump $SVNDIR/$repo --revision $r --incremental > svn-$r.dump
  	tar -czf svn-$r.tgz svn-$r.dump
  	rm -f svn-$r.dump
  done
  fi
  echo "Backing up $repo configuration "
  cd $SVNDIR/$repo
  tar -czf $BACKUPDIR/$repo/svnconfig-$DATE.tgz conf hooks
done

Leave a Reply