Wednesday, February 07, 2007

Backups of Subversion repositories

Here's the scenario: you are running a Subversion server and like all serious geeks, you want it backed up. This here post will show you how I do it for Windows and *nix _simultaneously_. I'm making the following assumptions:

Path typeWindows*nix
the subversion repositories are locatedd:\svnrepo/home/svn
the backup root folderd:\backups/home/backups
the subversion CLI(in the path)(in the path)

The first script performs not only a hotcopy backup of a repository (provided as the first parameter), but also first erases whatever backup might have been there (with a special provision for the very first time around) and creates a "dump" of the repository's contents, along with a final clean-up to save space. The reason we are keeping a dump over the contents of the db folder is that you can then "restore" your backup with a different version of Subversion. (trust me, I've lived through a catastrophic failure of a Subversion server and the dump format stays the same across versions while whatever's in the db folder doesn't necessarily)
@echo off
mkdir d:\backups\Subversion\%1\_backup
rmdir d:\backups\Subversion\%1 /s /q
svnadmin.exe hotcopy d:/SvnRepo/%1/ d:/backups/Subversion/%1/
svnadmin.exe dump d:/backups/Subversion/%1/ > d:/backups/Subversion/%1.svndump
rmdir d:\backups\Subversion\%1\db /s /q
mkdir -p /home/backups/svn/$1/_backup
rm -rf /home/backups/svn/$1
svnadmin hotcopy /home/svn/$1/ /home/backups/svn/$1/
svnadmin dump /home/backups/svn/$1/ > /home/backups/svn/$1.svndump
rm -rf /home/backups/svn/$1/db

The second script iterates through all the repositories in a root folder and calls the first script (which, BTW, is located in the backup root folder) for each one.
@echo off
cd \svnrepo
for /D %%d in (*) do d:\Backups\BackupAndDump %%d
cd /home/svn
for d in *; do /home/backups/backupanddump $d; done

Well, that's enough for tonight. I'm sure all you Linux gurus out there are pointing and laughing at my noob-skills.

No comments: