Assembla SVN With Local Backup

I recently moved my personal source control setup from a local SourceGear Vault server to a free, hosted SVN service from Assembla.  I wanted to have access to my source code while travelling without having to keep the server running at home, and Assembla provides users with up to 1GB of space and unlimited users absolutely free for private SVN hosting.

I wasn't looking to import my entire Vault database over to SVN, so manually creating new projects in Assembla was just fine.  I setup 3 different repositories:  one for personal projects, one for code related to sessions I give, and one scratch space that I can use to test things out and delete without issue.

My main concern in going to a hosted solution is ensuring I have a current backup of my repositories should something go wrong.  Assembla provides a manual backup option via their website, but I wanted something automated.  After some searching, I learned of the svncync command.  This command allows you to mirror a SVN repository from one machine to another.  Using this I was able to come up with a pretty automated solution that should work to sync up any two SVN repositories.

Preparing VisualSVN

I created the same three repositories described above on a local machine running VisualSVN that is backed up nightly via Windows Home Server.  VisualSVN  needs to have a specific hook set up with no content in order for svnsync to work.  To do this, right-click on the repository, and select All Tasks –> Manage Hooks.

5-21-2012 3-29-14 PM

On the Hooks tab, select the Pre-revision property change hook and click Edit.

 5-21-2012 3-30-54 PM

In the dialog that pops up, just click OK, and then click OK on the previous dialog.

5-21-2012 3-31-10 PM

This process creates an empty file named pre-revprop-change.cmd in the repository's hooks directory.

Setup Sync

To setup sync between the local VisualSVN server and remote repository, the local repository needs to be configured for sync.  To do this, run the following command, replacing the repository names and locations:

svnsync init file:///c:/repositories/myrepository/ https://subversion.assembla.com/svn/myrepository/

With VisualSVN setup, we can pull in the current state of the remote repository as follows:

svnsync sync file:///c:/repositories/myrepository

Set the UUID

Andy Pook mentioned this tidbit in the comments below.  If you want to be able to seamlessly switch between the main and synced repositories, the UUIDs of each repository need to be the same.  This can be accomplished pretty easily.  First, get the UUID of the remote repository using the svn info command:

svn info https://subversion.assembla.com/svn/myrepository

The output will contain a line that looks like this:

Repository UUID: 48c27914-95eb-48c8-b9f6-abc9d842ae0f

That's the UUID of the remote repository.  To set it to the synced repository, use the svnadmin setuuid command:

svnadmin setuuid c:\repositories\myrepository 48c27914-95eb-48c8-b9f6-abc9d842ae0f

Of course, change the names, locations, and UUID to reflect your configuration.  With this set up, you can now switch to the synced repository on the fly should something happen to the remote setup.

Automating the Backup

To automate this, I created a simple batch file that uses the svnsync command and runs nightly as a scheduled task to sync all three repositories with the local SVN server.  Here's what the batch file looks like:

"C:\Program Files (x86)\VisualSVN Server\bin\svnsync" sync file:///c:/repositories/Sessions
"C:\Program Files (x86)\VisualSVN Server\bin\svnsync" sync file:///c:/repositories/Personal
"C:\Program Files (x86)\VisualSVN Server\bin\svnsync" sync file:///c:/repositories/Scratch

I now have nightly backups of my hosted SVN repositories with very little effort.  This might be one of those things that everybody knows, but it's new to me. Enjoy!