How to Mirror a Subversion Repository

Here are three ways to create a full mirror of a Subversion repository:

1. Treat the repository like any other filesystem and recursively copy it to the mirror location.
2. Use svnadmin dump and svnadmin load.
3. Use svnadmin hotcopy.

There are important differences between these three strategies.
Treating the Repository as a Filesystem

You can of course:

cp -R PATH_TO_REPOS PATH_TO_MIRROR

This is a bad idea if the repository is in use – you’re copying a moving target – so you’ll have to take down the Subversion server while making the mirror. If you’re prepared to accept this downtime, netcat, nc, combined with tar is a neat way to recursively copy a directory across a network connection using TCP/IP.

# On the destination "mirror" machine
nc -l -p 2345 | tar xv
# On the source machine
tar c PATH_TO_REPOS > /dev/tcp/DOTTED.IP.OF.MIRROR/2345

Here, 2345 has been chosen as a suitable port for the data transfer.

Using Svnadmin Dump and Load

Perhaps the most obvious way to mirror a Subversion repository is to combine svnadmin dump with svadmin load.

svnadmin dump PATH_TO_REPOS | svnadmin load PATH_TO_MIRROR

Run on its own, svnadmin dump is designed to create a portable repository dump. The resulting dumpfile can be loaded into a new Subversion repository – even if the new repository is using a different database backend, or even a different revision of Subversion. Svnadmin dump will happily run on a live repository (no need to take the server down).

In short, combining svnadmin dump with svnadmin load is probably more powerful than we need if we just want to mirror our repository to a new location. Svnadmin dump – on its own – is the best way to fully backup a repository, since the dumpfile it creates is portable (as described above). If we replicate a repository by piping svnadmin dump to svnadmin load, we lose the dumpfile in the pipeline and do far more work than we need to.

Actually, it’s the computer which does the work – we just type a command and let it run. As a rough guideline, I have worked on a repository which occupies about 10Gb on disk, contains ~50K files and maybe a hundred branches. To dump and load this repository takes about 4 hours. A recursive copy completes in a few minutes.

One more point: svnadmin dump does not dump your repository configuration files and hook scripts. If your backup strategy is based around these commands, you will need separate arrangements for backing up hook scripts and configuration files.
Using Svnadmin Hotcopy

The third option combines the best features of the previous two. Using svnadmin hotcopy doesn’t require any server downtime, completes in minutes, and replicates server configuration and hook scripts.

svnadmin hotcopy PATH_TO_REPOS PATH_TO_MIRROR

The command is disconcertingly silent – no indication of progress, no verbose option. As is usual in UNIX-world, however, no news is good news. I just ran:

du -sh PATH_TO_REPOS PATH_TO_MIRROR

to confirm the hotcopy was running and to check on its progress.

Install SVN with Web Access on Ubuntu

For future reference, I have copied the article from How To Geek website.

This article covers installing subversion with the apache module so that it can be easily accessed from other systems on a public network. If you want a more secure svn server, you could use svnserve+ssh, which isn’t covered in this article.

To install subversion, open a terminal and run the following command:

[pre]
sudo apt-get install subversion libapache2-svn
[/pre]

We’re going to create the subversion repository in /svn, although you should choose a location that has a good amount of space.

[pre]
sudo svnadmin create /svn
[/pre]

Next we’ll need to edit the configuration file for the subversion webdav module. You can use a different editor if you’d like.

[pre]
sudo gedit /etc/apache2/mods-enabled/dav_svn.conf
[/pre]

The Location element in the configuration file dictates the root directory where subversion will be acessible from, for instance: http://www.server.com/svn

[pre]

[/pre]

The DAV line needs to be uncommented to enable the dav module

[pre]
# Uncomment this to enable the repository,
DAV svn
[/pre]

The SVNPath line should be set to the same place your created the repository with the svnadmin command.

[pre]
# Set this to the path to your repository
SVNPath /svn
[/pre]

The next section will let you turn on authentication. This is just basic authentication, so don’t consider it extremely secure. The password file will be located where the AuthUserFile setting sets it to� probably best to leave it at the default.

[pre]
# Uncomment the following 3 lines to enable Basic Authentication
AuthType Basic
AuthName “Subversion Repository”
AuthUserFile /etc/apache2/dav_svn.passwd
[/pre]

To create a user on the repository use, the following command:

[pre]
sudo htpasswd2 -cm /etc/apache2/dav_svn.passwd
[/pre]

Note that you should only use the -c option the FIRST time that you create a user. After that you will only want to use the -m option, which specifies MD5 encryption of the password, but doesn�t recreate the file.

Example:

[pre]
sudo htpasswd2 -cm /etc/apache2/dav_svn.passwd firedog
New password:
Re-type new password:
Adding password for user firedog
[/pre]

Restart apache by running the following command:

[pre]
sudo /etc/init.d/apache2 restart
[/pre]

Now if you go in your browser to http://www.server.com/svn, you should see that the repository is enabled for anonymous read access, but commit access will require a username.

[img=317]

If you want to force all users to authenticate even for read access, add the following line right below the AuthUserFile line from above. Restart apache after changing this line.

[pre]
Require valid-user
[/pre]

Now if you refresh your browser, you’ll be prompted for your credentials:

[img=316]
You now have a working subversion server!

I have followed the above tutorial and installed SVN server on my home Ubuntu computer without problems. Hopefully this article can help someone else who needs help.