Dirk Bergmann

Developer, panographer. Does consultancy work from own company. Lives in Chiang Mai, Thailand.

Twitter

Chiang Mai

Hua Hin

Thailand Hotels

ListVote - List. Vote. Learn.

Partnerseek - Find Partners

Replicating a Subversion Repository to a Windows Target Server via Synchronization

To backup, replicate or mirror a repository is arguably one of the most important tasks working with Subversion. Of course a repository folder is completely self-contained and can be copied or ftped to a different location and read by svn without any problems as long as there is no writing or locking going on. Besides the simple copy there are several safer and more svn-specific options, three of which are discussed in this article. However, the suggested svnadmin hotcopy command like most svnadmin works only with paths, not URLs. So you have to enter (Windows):

C:>svnadmin hotcopy c:\myrepos \\MYBACKUPSERVER\C\myrepos_bak

This technique works fine on your local network where you have path access as it's fast and simple to use.

Since version 1.4 Subversion offers the svnsync utility which maintains read-only mirror of a subversion repository at a (remote) URL. It words by replaying revisions of the original (source/master) repository at a mirror (sink) repository.

The setup notes are meant for Unix machines and not easy to understand for newbies. Follow these steps to get it working on a Windows machine:

  1. Set up a sync user on the destination repository by editing the passwd file in the conf directory of the target repository:
    [users]
    **#harry = harryssecret

    sally = sallyssecret

    mysvnsyncuser = mystrongpassword **
  2. This "syncuser" you created must be allowed to change revprops of the destination repository used by svnsync to keep track of bookkeeping information. Therefore a pre-revprop-change hook script has to be created. You will find an example script in the /hooks/pre-revprop-change.tmpl file of your target repository. However, this script is a Unix shell script and will not work under Windows. You will get the following error if you don't have a script in the hooks folder that can be executed by Windows:

_svnsync: Repository has not been enabled to accept revision propchanges;
ask the administrator to create a pre-revprop-change hook

_ The simple solution is just to create a file named pre-revprop-change.bat containing the single line:
**@exit 0
**and save this file file in the /hooks directory of the target repository. 3. Then svnsync has to be initialized with the command:
**svnsync init svn://mytargetserver/mytargetrepository svn://mysourceserver/mysourcerepository
**(you can use any other URL such as file:, http:, svn+ssh:)
You will be prompted for the username and password you created for the mysvnsycuser above.
If all went well you will get the response:
**Copied properties for revision 0 ** 4. You can now sync with the command:
**svnsync sync svn://mytargetserver/mytargetrepository
**and all revisions to your source repository will be replayed to the destination repository. 5. In Windows you could set up a Scheduled Task to sync from time to time which is beyond the scope of this article. 6. Don't forget: NEVER commit to a synced repository without "svnsync" or you'll get the "have you committed to the destination without using svnsync?" error and you'll have to start over with the above process.

Hope it helps.

#

Jason J: Great article, the revision propchanges fix helped allot, thanks!

Slopjong: The file name for unix is just pre-revprop-change without any suffix.

Victor N: Right what I'm looked for. Thanks for this post.

Angel: Thank you very much! This was exactly what I was looking for.

Slopjongs weblog: Let SVN accept revision propchanges... The following message appears if you try to modify properties (e.g. the log message) while the propchanges hook is not enabled. Repository has not been enabled to accept revision propchanges; ask the administrator to create a pre-revprop-change hook ...