Recovering from a Missing SVN Revision

Version ControlWhile Subversion can be a stable workhorse as a centralized source control repository, it can be a challenge to fix it if one of the revision files has gone awry.  In this example, we’ll go through recovering from a crashed Windows SVN server, where one or more of the revision files might have been lost during the restore operation.

First, install the latest version of SVN on the new machine.  Now that the Subversion software has been adopted under the umbrella of the Apache Foundation, the most reliable distributions are developed by Collab.  Download the 32-bit or 64-bit client, which actually also includes the server binaries.  Although a new “Subversion Edge” component exists that is integrated with Apache and Cloud Repository, it adds unnecessary overhead unless your development environment requires that technology.  Install the Subversion software to the server.

Next, copy the old repository to a given folder on the server.  This folder will be targeted by the Subversion service.  Navigate to the new Subversion binaries folder and find svnserver.exe.  Create a new service with the following command, replacing the paths as applicable:

sc create svnserve binpath= "\"C:\[PATH TO SUBVERSION BINARIES]\svnserve.exe\" --service -r C:\[PATH TO REPOSITORY]" displayname= "Subversion Server" depend= Tcpip start= auto

This should add a new service to the Windows.  Start the service using the Windows Control Panel Services manager.  In addition, be sure to modify the firewall to allow the inbound SVN port 3690.  At this point, the repository should be accessible from another PC.  Attempt to connect and make sure that the repository files can be viewed.  If the new SVN server has a different IP or NetBIOS name, update the repositories by using the “Relocate” command.

If everything works at this point, further action does not need to be taken.  On the other hand, if one or more of the SVN files was lost from a disk crash, certain functionality such as Revision Logs might not work.  Revision logs might also be lost if upgrading from an older version of SVN, since older versions of SVN could randomly corrupt or duplicate revisions.

To find if the SVN repository is in good shape, run the command:

svnadmin verify [PATH TO REPOSITORY]

If the message shows that a certain revision is missing, it is still possible to recover the repository if that revision did not have important changes.

First, create two export dumps of the repository, one including all files before the corrupted revision, and one of all changes afterwards.  Assuming the corrupted revisions were 187 and 188, and the youngest repository revision was 1805, the following syntax would be used:

svnadmin dump [PATH TO REPOSITORY] -r 1:186 > c:\svn186.x
svnadmin dump [PATH TO REPOSITORY] -r 189:1805 --incremental --deltas > c:\svn1805.x

Any additional splices of the repository should also contain the “incremental” and “deltas” flags.  Next, rename the repository folder to something else, and create a new repository in its place:

svnadmin create [PATH TO REPOSITORY]

Restore the hooks and conf files from the previous repository folder by overwriting the files in the new folder, and then run an SVN load command on the initial set of revisions:

svnadmin load [PATH TO REPOSITORY] < c:\svn186.x

In order for the revision numbers to match up, commit two dummy revisions to the system for the two missing revisions in our example. First start the Subversion service, and then run the following command:

svnmucc propset dummy_prop 0 -m "increases revision" svn://[SVN SERVER NAME]/ --username xxxx --password xxxx,W
svnmucc propset dummy_prop 0 -m "increases revision" svn://[SVN SERVER NAME]/ --username xxxx --password xxxx,W

Finally, stop the Subversion service, and load the final slice of revisions:

svnadmin load [PATH TO REPOSITORY] < c:\svn1805.x

Start the Subversion service, and the operation should be complete. Although the recovery process is not easy or particularly straightforward, these techniques will help restore a Subversion repository to working condition if one or more of the revision files have gone missing.

Written by Andrew Palczewski

About the Author
Andrew Palczewski is CEO of apHarmony, a Chicago software development company. He holds a Master's degree in Computer Engineering from the University of Illinois at Urbana-Champaign and has over ten years' experience in managing development of software projects.

RSS Twitter LinkedIn Facebook Email

Leave a Reply

Your email address will not be published. Required fields are marked *