One Bad Pixel
All your pixel are belong to us.

Cleaning/Migrating your svn repo 101.

I wanted to take a moment and outline a procedure that is immensly useful to anyone who does work with subversion. I use subversion to manage my websites and keep a synced copy wherever I choose to work on my websites. I won’t go thru the specifics of setting up a repository and connecting to it, (maybe in a later article), but I will go thru how to forcefully cleanup a repository (or migrate it to another server).

In my scenario, I had used subversion to check in a new application to my website, Gallery2, to be precise. I hadnt really been paying attention when I committed it, but found it was ABSOLUTELY HUGE. Way more then I wanted to keep in my repo for just something I was expirementing with, and it was very difficult to delete since it was so large.

I searched for the “svn obliterate” which to my dismay, doesnt actually exist, but has been requested of the svn developers more than once. FYI: svn obliterate as requested to the developers would destroy a file and all revision history for said file.

So I was left with figuring out how to clean up my subversion repository and dump all the stuff I didnt want in it anymore. The process is quite easy after you figure it out, and VERY useful. I have written this assuming you have shell access to the system with the svn repository.. Forgive me if this is not your case.

Step 1: First, we need to take a full dump of your existing repository. This is great for backup, migration, and cleanup purposes. You will need to know the repository location on your server.

user@server:~$ svnadmin dump ~/location/of/repo | svndumpfilter exclude onebadpixel_com/html/unwanted/stuff >>~/repo.dmp

This dumps the repository to stdout, which can then be piped in to svndumpfilter. If you want the entire repo as is, such as a migration of your repo, just use:

user@server:~$ svnadmin dump ~/location/of/repo >> ~/repo.dmp

Now, repo.dmp contains your entire repo. Note: If your repo is HUGE, this file will be huge and take a long time to generate. Remember, the repo contains every file and every revision.

svndumpfilter has 2 possible arguments, exclude and include. If you only want to dump/migrate a specific part of the repo, use include. If you want to get rid of parts of the repo, use exclude. The dump will contain the filtered repo if you piped the output into svndumpfilter.

If you dump your repo and then decide you forgot to filter some branch or folder out that you didn’t want, you can always refilter it like so…

user@server:~$ cat ~/repo.dmp | svndumpfilter exclude onebadpixel_com/html/more/unwanted/stuff >>~/repo2.dmp

Step 2: (optional) Now that we have dumped your repo, we are ready to delete it so we can re-create it with the new data. If you are migrating to a new server, or if you are cautious like me, you can just make a new one with a different name, or the same name on a different server.

user@server:~$ rm -rf ~/location/of/repo

Step 3: Then, we need to create the repo that will be the destination for this dump. I assume that you followed step 2, or are creating this on a new server.

user@server:~$ svnadmin create --fs-type fsfs ~/location/of/repo

Note: It is recommended to use –fstype fsfs as this is now the default for newer versions of svn. It used to be BRB, but this is depreciated. Use fsfs for compatibility.

Step 4: If you are migrating to a new server, you need to copy your dump file to the new server. That is outside the scope of this article, but you could use sftp or ftp or nfs or … you get it.
Anyways, now we need to load the dump into our new repo.

user@server:~$ svnadmin load ~/location/of/repo <~/repo.dmp

Congratulations. You have just cleaned up or migrated your repo.. If you want to test it, you could always check it out to a test location, or whatever.

user@server:~$ mkdir ~/test
user@server:~$ cd ~/test
user@server:~$ svn checkout svn+ssh://svnuser@serveraddress/location/of/repo


One Response for “Cleaning/Migrating your svn repo 101.”

  1. Mason Says:

    Very helpful post. Thanks!

Leave a comment!