Clone Remote Subversion Repositories With svnsync
By jcscoobyrs on Thu, 04/10/2008 - 20:51Have you ever needed to easily create a backup/clone of a remote Subversion repository? It sure would be simple if it were local because you could just create a filesystem copy and go about your business. What makes the story worse is when you don't have physical access to the server where the repository is located. This problem usually means filing issues, making support calls, talking to operations or whatever steps you have to take to get the powers that be to create a dump file, or an archive of the filesystem, and post it somewhere to download it. Sometimes this is not a big deal but for others, it can be quite difficult. Well, Subversion actually ships with a nifty little utility to give you the ability to backup/clone any remote repository that you can read.
svnsync became part of the standard Subversion distribution back when 1.4 was released. Designed to easily create and automate the management of mirror repositories, svnsync became a staple for those wanting easy, automatic and readily-available off-site backup. Using svnsync, you could populate all repository changes, as they occur, to a fully-configured Subversion server at a different location ready for a failure. With svnsync, companies were able to make Subversion failover a non-issue. But our focus on svnsync today is for a different purpose.
If you look closely at svnsync's usage patterns, it operates on urls. This means there is no requirement reason that you have to have physical access to the repository to run svnsync against it. Reading this should make a light bulb go off in your head because, "Yes", that means you can run svnsync to create a duplicate of any remote repository to which you have read access. No more filing internal tickets to get your repository clone. No more having to work through your hosting company's support lines to get a duplicate so you can test some new Subversion log parsing tool. The reasons behind needing/wanting a clone of a repository are endless. For a simple list of steps to utilize this information, please look below:
* Create your local repository: svnadmin create PATH
* Create an empty pre-revprop-change hook script: echo "#!/bin/bash" > PATH/hooks/pre-revprop-change
* Make the pre-revprop-change hook script executable: chmod +x PATH/hooks/pre-revprop-change
* Initialize svnsync: svnsync init file:⁄⁄⁄PATH URL_TO_REPO_ROOT_TO_CLONE
* Synchronize: svnsync sync DEST_URL
(Note: "DEST_URL" is the url to the Subversion repository you created in step 1.)
It's that simple. While I know I'm not the first to come up with this usage scenario for svnsync, I do find it quite fascinating and can only imagine how many times it would had saved me time in the past had I only remembered to use it. Now when you need a "dump file" and you do not have physical access to the Subversion server to create one yourself, use the steps above to create a repository clone locally and create your own dump file.
- (Updated 04/07/2009: Updated the syntax to reflect the new svnsync usage pattern.)
- (Updated 04/14/2009: Updated typo.)













