Creating a backup SVN repository

This is a brief guide on how to setup a backup SVN repository using svnsync. I will assume that subversion is already installed and the master repository is located in the machine called remote.com and in the directory /home/ruser/master_repos directory.

1. Create the mirror repository mirror_repos/ using svnadmin command

[user@mycomp] svnadmin create mirror_repos

2. Go to hooks/ subdirectory in the newly created repository

[user@mycomp] cd mirror_repos/hooks

You should see several *.tmpl files. One of these files is pre-revprop-change.tmpl. Copy it to pre-revprop-change, that is, without the .tmpl extension

[user@mycomp] cp pre-revprop-change.tmpl pre-revprop-change

Open this file using any text editor. Change it to the following:

USER="$2"

if [ "$USER" = "username" ]; then exit 0; fi

echo "Only username can change revprops" >&2
exit 1

Change “username” to the actual user name. Save the file and exit. Make sure it is also executable.

[user@mycomp] chmod 755 pre-revprop-change

3. Initialize the mirror repository using the svnsync init command

[user@mycomp] svnsync init DEST_URL SOURCE_URL
Copied properties for revision 0

In this example, DEST_URL is file:///home/user/mirror_repos and SOURCE_URL is svn+ssh://ruser@remote.com/home/ruser/master_repos

This initialize the mirror repository and it is now ready to be populated.

4. Start synchronizing. Use svnsync sync command to do it:

[user@mycomp] svnsync sync file:///home/user/mirror_repos
ruser@remote.com's password: xxxxxx
Committed revision 1.
Copied properties for revision 1.
Transmitting file data ........
Committed revision 2.
Copied properties for revision 2.
Transmitting file data ....
:

In case you want to commit back to the master repository, you can do it by issuing the command svn switch –relocate FROM_URL TO_URL before committing the changes. To do this, you also need to have the same UUID between the mirror and master repository.

Get the UUID from the master repository and copy it to the mirror repository. In the system where the master repository is running, run svnadmin dump

[ruser@remote] svnadmin dump -r0 /home/ruser/master_repos | head -n 3 > saved-uuid

Load it in the mirror repository

[user@mycomp] svnadmin load --force-uuid /home/user/mirror_repos < saved-uuid

The mirror and master repositories should now have the same UUID.

That’s it!

You may also like...

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.