Subversion – Backing Up Repository

Subversion Subversion (SVN) is a version control system initiated in 2000 by CollabNet Inc. It is used to maintain current and historical versions of files such as source code, web pages, and documentation. Its goal is to be a mostly-compatible successor to the widely used Concurrent Versions System (CVS). Subversion is well-known in the open source community and is used on many open source projects.

Subversion was started in 2000 as an effort to write a free version control system which operated much like CVS but with fixed bugs and misfeatures in CVS. By 2001, Subversion was sufficiently developed to be capable of hosting its own source code. More information, including this above paragraph, is here.

Personally, I have been using it – rather extensively – for the past few years to maintain over two dozen projects. About a year ago paid a rather heavy price for not backing up my repository [it only had one project at that time – but a very important one] but since then, have been performing daily backup of my repository using the following BASH script:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#! /bin/bash
 
# svn_backup.sh
# BASH script to perform periodic [daily] backup of subversion repository
# To be run using a cron job
#
# First written: Gowtham; Thu, 08 Jul 2009 16:25:15 -0400
# Last modified: Gowtham; Thu, 08 Jul 2009 16:25:15 -0400
 
export TODAY=`date +"%u"`
cd ${HOME}/backup/svn/
 
# If, there already exists a backup file, then remove it
if [ -e ${TODAY}_svnrepo.dump.bz2 ];
then
  rm -f ${TODAY}_svnrepo.dump.bz2
fi
 
# Use 'svnadmin' with dump option
# My subversion repository is located at ${HOME}/svn_repo
svnadmin dump ${HOME}/svn_repo > ${TODAY}_svnrepo.dump 2>&1
 
# Compress the dump
bzip2 ${TODAY}_svnrepo.dump


Update / 2010.11.17

When I had to change the location of my repository and as such needed to load the backed-up dump file into the repository, I ran into the following error:


Dump stream contains a malformed header (with no ‘:’) at ‘* Dumped revision 0.’

In order to take care of this error, I modified the above script – so that the dump file is clean and ready to be imported as is.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#! /bin/bash
 
# svn_backup.sh
# BASH script to perform periodic [daily] backup of subversion repository
# To be run using a cron job
#
# First written: Gowtham; Thu, 08 Jul 2009 16:25:15 -0400
# Last modified: Gowtham; Wed, 17 Nov 2010 23:11:13 -0500
 
export TODAY=`date +"%u"`
cd /scratch/$USER/backup/svn/
 
# If, there already exists a backup file, then remove it
if [ -e ${TODAY}_svnrepo.dump.bz2 ];
then
  rm -f ${TODAY}_svnrepo.dump.bz2
fi
 
# Use 'svnadmin' with dump option
# My subversion repository is located at /scratch/$USER/svn_repo
svnadmin dump /scratch/$USER/svn_repo > svnrepo.dump 2>&1
sleep 5
 
# Fix for the following error message
# Dump stream contains a malformed header (with no ':') at '* Dumped revision 0.'
grep --binary-files=text -v '^* Dumped revision' svnrepo.dump > svnrepo_1.dump
mv svnrepo_1.dump ${TODAY}_svnrepo.dump
 
# Compress the dump
bzip2 ${TODAY}_svnrepo.dump

One Reply to “Subversion – Backing Up Repository”

Comments are closed.