Sometimes it is necessary to move a subversion repository. In this case, it was because I wanted to consolidate a few subversion repositories into one directory on a dedicated hard drive.
Moving a subversion repository usually consists of two steps:
- Moving the repository
- Updating the working copy to reflect the repository move
This post will handle both steps.
Move the repository
Instead of actually moving the repository as one would expect, we’re going to backup our existing repository, import out backup into a newly created one. First we’ll list the commands, then break down what we’re doing.
svnadmin dump /path/to/old-repository > ~/repo.dmp svnadmin create /path/to/new-repository (Update file/directory permissions) (Update repository permissions) svnadmin load repository-name < ~/repo.dmp
- L1: We dump the repository into a backup file.
- L2: Create a new repository.
- L3: Update file / directory permissions (by using some combination of chown, chgrp and chmod)
- L4: Update repository permissions (by editing files like /path/to/new-repository/conf/passwd and /path/to/new-repository/conf/svnserve.conf)
- L5: Extract the backup into the new repository.
Update the working copy
Once we’ve moved our repository, we now need to update the working copy so that commits and updates will reference our new repository.
cd /path/to/working-copy svn info svn switch --relocate svn://hostname/path/to/old-repository svn://hostname/path/to/new-repository svn info
- L1: We change to the path of the working copy.
- L2: Display the path to the old repository through the svn info command.
- L3: Switch the working copy’s repository.
- L4: Display the path the the working copy’s repository (verify that the switch worked) through the svn info command.
Now that we’re done moving the repository, we want to verify the move and clean up. To verify the move, we can just check the output of the svn info command. To further verify, we can run svn update to ensure that nothing is updated.
We will probably also want to remove both the old repository and the backup file. A simple rm -r for the repository and rm for the backup file is fine.
Lastly, its possible that you would want to use a trimmed down set one of these steps. For example, if you didn’t care about keeping the version history and just wanted to move the repository location, you could skip steps 1 and 5 in the first section. Also, if you didn’t care about moving the working directory but just wanted to make a complete copy of the repository including the version history, you could complete the whole second section.