How to backup (and restore) a SVN repository

Backup

First create a hotcopy somewhere where enough free space is available:

 mkdir /tmp/hotcopy
 svnadmin hotcopy /srv/svn/cluster2007/ /tmp/hotcopy

(this assumes the repository cluster2007 to be backed up)

Then dump the repository:

 svnadmin dump /tmp/hotcopy | \
 bzip2 -c > /raid/backup/n0-svn/cluster2007-`date --rfc-3339=seconds | tr ' ' 'T'`.bz2

That's all folks, well, except deleting the hotcopy directory

  rm -rf /tmp/hotcopy

restore

Make sure you have an empty repository:

  mkdir /newpath/cluster2007
  svnadmin create /newpatch/cluster2007

Then simply load the dump:

  bunzip2 -c /raid/backup/n0-svn/cluster2007-2007-08-20T14:10:56+02:00.bz2 | svnadmin load /newpath/cluster2007

That's all.

NB: svnadmin dump as well as svnadmin load support the -q flag to be quiet.

Example script

 #!/usr/bin/perl -w
 
 use strict;
 use warnings;
 use Date::Format;
 
 # small script to backup SVN repositories
 #
 # hacked together by Carsten Aulbert, 2007
 #
 # License: GPL (v2 or later)
 # Assumptions: 
 # * svnadmin, rm, tr, bzip2, date and mkdir installed an in path
 # * $tmp_dir has enough free space
 # 
 ########################
 # a few settings
 ########################
 # where to look for repositories
 my $SVN_dir    = '/srv/svn';
 
 # where to store the dumps (where they will be collected from file server)
 my $backup_dir = '/backup/svn-dump/';
 
 # temporary storage, need to have enough space for repository
 my $tmp_dir    = '/tmp/svnhotcopy';
 
 ########################
 # start the actoin
 ########################
 
 RunCommand ( "mkdir -p $backup_dir" );
 
 for my $repos_path ( <$SVN_dir/*> )
 {
     ( my $repos = $repos_path ) =~ s!^$SVN_dir/!!;
     print "Working on $repos\n";
     
     RunCommand ( "rm -rf $tmp_dir" );
     RunCommand ( "svnadmin hotcopy $repos_path $tmp_dir" );
 
     my $date = time2str ( '%Y-%m-%dT%H%M%S%z', time);
 
     RunCommand ( "svnadmin dump $tmp_dir -q | bzip2 -c > $backup_dir/$repos-$date.bz2" );
     RunCommand ( "rm -rf $tmp_dir" );
 
 
 sub RunCommand
 {
     my $cmd = shift;
 
     system ( $cmd );
     die "Running $cmd failed with ($!)" if $?;
 
 }

DocumentationForm edit

Title How to backup (and restore) a SVN repository
Description This page describes how to backup (and restore) a SVN repository
Tags backup restore svn repository
Category Admin
Topic revision: r4 - 10 Feb 2012, ArthurVarkentin
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki? Send feedback