Moving Subversion Repository Across Machines

I recently moved my development server from a linux box to my primary machine, an iMac. I wanted to move my subversion repository while maintaining the file histories for everything inside. Worrying that it was going to be a huge issue, I was happy to discover it was completely simple:

On the existing repository machine, run:

svnadmin dump /path/to/repository > repository-name.dmp

Transfer your dump file to the new machine and then, create a repository. Once subversion is running and you have your repository created, import the dump file:

svnadmin load /path/to/repository-name< /path/to/repository-name.dmp

You’re done!

Setting up Subversion on Mac OS X 10.5

I recently began working exclusively on an iMac so I decided to setup a subversion server locally and as my new machine would simply replace my local development machine, which is a Fedora Core 6 pc.

You’ll need to setup at least one repository. I’m going to need multiple repositories that I can use for different clients so I have a bit of extra admin work ahead of me. You can setup as many repositories as you need, but no matter what you’ll need at least one. Here create the folders…

# mkdir /svn
# mkdir /svn/repos

Then we need to tell subversion to make our first repository.

# svnadmin create /svn/repos/myproject

First, I need to setup a config file for svnserve.

# vi /svn/repos/conf/svnserve.conf

Then, look for variations of the following code and edit it as necessary. By default any anonymous user can access the code so to disable that you must include anon-access = none, just commenting the value out will not prevent anonymous access.

anon-access = none
password-db = passwdfile
realm = My SVN Repository
auth-access = write

The password-db is just a path to a file containing usernames and passwords. You’ll create this file especially for SVN. I create each file inside of the repository conf directory. So, save your changes and then we’ll create said user file.

# vi passwdfile

Enter in something like:

[users]
username = password

Anyway, you’ll need to start the svn server.

# svnserve -d --listen-port=3690

One side note – svnserve just runs and doesn’t have a way to stop besides killing the process. If you make changes to the svnserve.conf or user file you’ll need to restart svnserve.

# killall svnserve

Then, go ahead and test (best to do so on a different machine).

# svn co --username=myusername svn://mydomain/svn/repos/myproject

The system should then ask you for your password. Go ahead and run some tests.

CVS to Subversion Transfer

Most of my projects all use Subversion now, as everyone knows it’s the recommended little brother of CVS. However, for everything that doesn’t have a home in SVN with a client, I was storing in CVS I had running on my local dev machine.

Not wanting to loose any of my files or their histories, I wanted to find a way to transfer everything into subversion. At the recent ZendCon I heard about cvs2svn and I tried it out. It was very easy to install (required Python, which was easy for me to installed through Yum), and it was easy to run – at least for me as I was just pulling everything over.

Now I’ve got everything in subversion and I was able to maintain the file histories for everything.

Subversion Post-Commit Email

I was setting up an installation of subversion for a client (and I will be for myself soon here – it’s about time to move from CVS) and I needed to enable it to send an email to folks each time a commit was made. This tidbit assumes that you’ve already installed SVN on a linux machine.

First, you need to visit your hooks dir (created when you create a new repository (which is done using svnadmin)).

# cd /path/to/repo/hooks

You need to download a copy of the commit email perl script, which you can get from here.

# wget http://svn.collab.net/repos/svn/trunk/tools/hook-scripts/commit-email.pl.in

Then, rename it to .pl. You’ll need to rename the special file that SVN uses to activate the email. This file is post-commit.tmpl and you’ll need to rename it to post-commit.

# mv commit-email.pl.in commit-email.pl
# cp post-commit.tmpl post-commit

Next you need to edit the post-commit file so that it sends your email out. At the bottom of the file, add the following:

/path/to/repo/hooks/commit-email.pl "$REPOS" "$REV" --from svn@example.com "me@example.com" "you@example.com"

Then just save the file. Now you’re ready to test. You can either make a commit or run the below command. First call the post-commit, then provide the path to a repository to watch, then provide the revision number you want to run a test on. If you’ve just imported code and don’t have any other revisions, just provide the number 1 – but beware the possibility of a really long email.

# ./post-commit /path/to/repo 40

Things should be working fine by this point, but I ran into a problem. I saw the error message Global symbol "@SVN_BINDIR" requires explicit package. In that case, just go into the commit-email and change the @SVN_BINDIR variable on line 46 to the full path of svnlook.