Friday, October 4, 2013

Subversion Mirror Repository Using Svnsync


How to Set up a Subversion Mirror Repository Using Svnsync...


Starting subversion 1.4 you have a new tool called svnsync with which you can maintain mirror repositories quite easily. What I like about this is commit base synchronization.

Say you have your SVN on server'A' and you want to backup on server 'B'. Every time the developer makes a commit to main server 'A' ..it automatically gets commited to 'B'. Isn't that wonderful !!!

Time to say goodbye to shell scripts and cron jobs and welcome svnsync..

Create the svn repository and a user to sync commits on to remote server

Steps to follow:

Logon to remote server -->cd to repositories-->create a repository

How to create a repository?

svnadmin create test-repo

svn info repopath --> This is to verify that your repository is at version zero or else you will have problems setting up svnsync

Now create a user called 'syncuser' to do the sync. Remember only this user or any user you want to setup to do this sync can only do this operation.
I have created the user on GUI and it was simple

Now, we need to set up a hook to let svnsync change the properties.
You will create this in hooks folder
File name: pre-revprop-change

#!/bin/sh
USER="$3"
if [[ "$USER" = "syncuser" || "$USER" = "toolsuser" ]]; then exit 0; fi
echo "Only the sync user may commit new revisions as this is a read-only, mirror repository." >&2

exit 1

We should grant access to the user running svnsync on the main machine 'A' by copying its ssh key to .ssh/authorized_keys

Now move to server 'A' 

Steps to follow:

Step1:

svnsync init Dest-url source-url

Step2:

svnsync sync Dest url

step3:

Set up the hook in hooks folder
File Name: post-commit

#!/bin/sh
svnsync synchronize repopath --username =syncuser --password= pwd
exit 0

REPOS="$1"
REV="$2"

commit-email.pl "$REPOS" "$REV" commit-watchers@example.org

log-commit.py --repository "$REPOS" --revision "$REV"

Dont forget to gtrant 775 permission to the hooks files you have created or else it wont work :(

Thats it...you are all set 

you can always check if the repo on both sides on server is at same revision using svn info


Thanks
Bhargavi











Thursday, October 3, 2013

How to move a Project from one Subversion Repository to another?


         Moving a project from one SVN repository to another looks simple and once you start doing it you will see all kinds of issues. I spent hours reading multiple blogs on google to figure this out and nothing really helped me. I thought I have to share my experience and help anyone who is struggling to get this done..

Here is our project structure...
We have multiple projects setup under one respository called Test

Test
  project1
  project2
  project3

Project1
  Trunk
   Branches
    Tags
Branches
  B1
  B2
  B3

Lets say I want to move  project3 out of test repo to a new repository called 'internet'. Here is the procees you have to follow

This move is a 3 step process

1. Dump
2. Filter
3. Load

Dump is very simple and straigh forward. You will never get into issues

1.svnadmin dump <repopath>

Example :
svnadmin dump apps/tools/repositories/test > fulldump

Now that you took the dump of entire repository, filter it using svndumpfilter to include just the path of the project you wanted to move

2. svndumpfilter include PATH_PREFIX

Example:
svndumpfilter --drop-empty-revs --renumber-revs include trunk/project3 < fulldump > filtereddump

There is a high possibility of seeing an error at this point

Reason:
1. Renamed a file or folder and you are trying to move after the renaming is done
2. You might have created the files in branches and merged it back to trunk( Remember svn never makes a new copy it just have reference)

Invalid copy source path '/branches/folder1/folder2/ConsumerException.java'

When you see this error ... what it means is java file actual source was in branch ..so you have include that path in your filter to proceed with move
You have do this at root level.. which is including branch name and not the path of the file
I have 2 branches that got merged to trunk and i ended up adding both to make it work

now your svndumpfilter looks like this

svndumpfilter --drop-empty-revs --renumber-revs include branches/branch1 branches/branch2  trunk/project3 < fulldump >filtereddump

and fianlly once your filtering is done .. you could load that to a new repository

create a new repo
svnadmin create internet
Once the repository is created.. load the dump into it

3.  svnadmin load <repopath>
svnadmin load apps/tools/repositories/internet  < filtereddump

There are chances that load could fail with below error

svnadmin: E160013: File not found: transaction '8281-6e1', 

If you get to see this error, please create a branch in the new repository and you should be good to go

I hope this helps someone :)


Thanks
Bhargavi