Friday, February 08, 2008

SVN backup using SVN::Mirror

I do have a number of subversion repositories that I like to backup once every hour. The tool I'm using for that is the perl package SVN::Mirror. I didn't document the usage of this tool for myself yet and I feel it is time to correct that.

The tool itself is available on CPAN and on Gentoo you can install it via Portage:

gentoo # emerge dev-perl/SVN-Mirror

This delivers the tool /usr/bin/svm that holds all the functionality to replicate Subversion repositories.

I always had strange locking issues with this perl script so I added a small section for the occasional unlocking:

--- /usr/bin/svm        2007-06-21 15:17:55.000000000 +0200
+++ /usr/bin/svm-expanded       2008-01-07 14:59:54.000000000 +0100
@@ -82,6 +82,17 @@
        m/connection timed out/;
+sub unlock {
+    my $path = shift;
+    my $what = shift;
+    my $pool = SVN::Pool->new_default;
+    my $m = SVN::Mirror->new(target_path => $path, target => $repospath,
+                            pool => $pool, auth => $auth,
+                            get_source => 1);
+    $m->unlock($what);
 sub sync {
     my $path = shift;

To backup a repository you will first have to initialize a new repository using svm:

gentoo # export SVMREPOS=/var/svn/backup/libpardus
gentoo # svm init /

Updating the repository to the newest state is not much more complex:

gentoo # export SVMREPOS=/var/svn/backup/libpardus
gentoo # svm sync /

If you use the unlocking patch provided above this makes:

gentoo # export SVMREPOS=/var/svn/backup/libpardus
gentoo # svm unlock / force
gentoo # svm sync /

I package these few lines into a small shell script and add it to cron so I get a regular update on all the repositories. Just in case Sourceforge ever dies (which I hope it does not).

No comments:

Post a Comment