Skip to content

Migrating and backing up subversion repositories

I keep my everything related to my research in a Subversion repository for easy versioning. Originally, the repository was located at a remote server in MIT (to which I have access thanks to SMA). Recently, though, accessing this through the NUS network has become really slow. There’s nothing more painful while doing work than waiting for a svn commit command. So I decided to move my repo to my local (NUS) desktop and have incremental backups on a NUS server. There were a number of ways to do this, and I’m just putting down my approach here for future reference.

On the remote server, get a dump of the repository and copy it to the local machine:

[anshul@remoteMIT]$ svnadmin dump REPOS/research > research.repo.dump
[anshul@remoteMIT]$ scp research.repo.dump anshul@localNUS:~/REPOS/

On the local server, I simply created an empty repo and loaded the dump file:

[anshul@localNUS]$ svnadmin create research
[anshul@localNUS]$ svnadmin load research < research.repo.dump

You can (technically) also copy over the repository directly but that might lead to problems if there is a commit during the migration, and I wasn’t too sure if direct copying would break because I was moving from an AFS filesystem to a ext3 one.

Now for every working copy (laptop, NUS desktop, home desktop) one needs to switch the location:

[anshul@localNUS]$ svn switch --relocate svn+ssh://anshul@remoteMIT/home/anshul/REPOS/research \
file:///home/anshul/REPOS/research .
[anshul@powerbookG4]$ svn switch --relocate svn+ssh://anshul@remoteMIT/home/anshul/REPOS/research \
svn+ssh://anshul@localNUS:/home/anshul/REPOS/research .

That pretty much takes care of the migration. For backups, I used the post-commit hook script mechanism provided by svn. First, make sure the most current dump file exists in a particular location (same dumpfile that was created earlier). Then, I simply created the following file and saved it in REPOS/research/hooks/post-commit:

#!/bin/bash

REPOS="$1"
REV="$2"
DUMPFILE="/path/to/research.dump"
svnadmin dump "$REPOS" -r "$REV" --incremental >> $DUMPFILE

This incrementally dumps every new revision into the dumpfile. Now, it’s simple enough to add a cronjob that periodically backs up the dumpfile either on a local disk or a remote server. I’ve set up a remote backup cronjob at 9 AM every day (statistically, the time I’m least likely commit changes); funny stuff can happen if I’m making a commit (and therefore changing the dump file) and backing it up at the same time.

This issue can be avoided if you put the backup command at the end of the hook script, but my repository is quite large (1.6 gigs as of now) and takes an appreciable time to backup, so I chose not to do that.

Post a Comment

Your email is never published nor shared.