Synchronize old svn with all revision history to new repository
Posted by Bhushan Ahire | Posted in Subversion | Posted on 04-03-2008
0
First, create a SVN user for svnsync to use – let’s call this the ’svnsync user’. The easiest (and best) way to do this is edit the svnserve.conf and passwd files:
conf/svnserve.conf
# Uncomment this line.
password-db = passwd
conf/passwd
svnsync = secret
This gives read and write access to the ’svnsync user’. The svnsync program will authenticate with our repositories as this user via the svn:// protocol (i.e. via svnserve).
Next, we need to create a pre-revprop-change hook for the destination repository. The svnsync documentation has a detailed explanation. Create a hooks/pre-revprop-change file under your destination repository’s directory.
#!/bin/sh
USER="$3"
if [ "$USER" = "svnsync" ]; then exit 0; fi
echo "Only the svnsync user can change revprops" >&2
exit 1
Make it executable, and then initialize the sync:
chmod +x hooks/pre-revprop-change
svnsync init file:///var/svn/repositories/destination_repos svn://source.host/source_repos
Don’t worry, this only sets up the sync – there’s no actual data copying yet. Syncing your repository data may take a long time if you have a big source repository, so I suggest using nohup to run the code overnight (or something), or at least saving the output in a log. Either way, the command to start the sync is:
svnsync sync --username svnsync file:///var/svn/repositories/testsync/
You should start seeing svnsync committing in changes from your source repository. Instant gratification (well, almost)! Should your svnsync process get aborted or killed, you can remove the hanging lock by running:
svn propdel svn:sync-lock --revprop -r 0
Setting up ‘on-the-fly’ syncing
So now you have your source and destination repositories synced, but what happens when you start committing changes to your source repository? Nothing! That’s because svnsync is merely a passive syncing tool (meaning you have to run it to sync, instead of it knowing when to sync automatically).
There are two ways you can setup ‘real-time’ syncing:
- Use
cron(or a similar scheduler) on the destination repository server. Add something like this to yourcrontab:* * * * * /usr/local/bin/svnsync --non-interactive sync svn://source.host/source_reposThis basically runs svnsync on your destination repository server every minute to pull down any changes to your source repository.
- Add a post-commit hook to the source repository. I found this svnsync entry by Paul Querna that has a sample post-commit hook. If I recall correctly I tried it but it didn’t work for me, so I settled on using cron to sync up my repositories.
