Click to See Complete Forum and Search --> : HOWTO synchronize 2 different subversion repositories


spx2
01-07-2008, 05:57 AM
I have two different subversion repositories,one on google code hosting,
and one on a local machine.
The problem is lately,I trust my local repo more than googles repo,
so I figgured,I'd just make a sync from time to time from the google repo
to the local one,just to make sure nothing goes wrong and I have my
code intact :) (yes I have mild paranoia).
Ok,so we need some simple tools,like rsync and svn.
We won't go into the discussion of how you can set these up as there
are many articles that describe that.

How do we synchronize the two repos.
I've written a script wich does that and runs every hour in cron.
This is the script:

cd ~/perlhobby ;svn update;
cd ~/firepower_repo/google_code_repo;svn update;
rm -rf /tmp/repo_checkout;
svn export ~/perlhobby /tmp/repo_checkout;
rsync -avr /tmp/repo_checkout/ /home/spx2/firepower_repo/google_code_repo/
cd ~/firepower_repo/google_code_repo;
svn commit -m "";


~/perlhobby/ is the checkout of the repository on google.
~/firepower_repo/ is the checkout of the repository on some local machine.

we first make sure our checkout of perlhobby is updated,same thing
with firepower_repo.
we export the checkout /perlhobby/ to get rid of all the unwanted .svn
directories wich contain data specific to every repo and we don't want that.
then we synchronize the export with firepower_repo.
certainly the firepower_repo is just a late mirror of perlhobby(as the
script will run every hour).
then we commit the modifications we have made to firepower repo,
switch -m is for not opening an editor and asking for the log message so
we can automate all the process better.
that's about all there is to it.

spx2
01-15-2008, 10:31 AM
Optimized version of the script

cd ~/perlhobby ;svn update;
cd ~/firepower_repo/google_code_repo;svn update;
rsync -avr --exclude .svn --delete ~/perlhobby/ ~/firepower_repo/google_code_repo/
svn add *
cd ~/firepower_repo/google_code_repo;
svn commit -m "";


There is however a problem,if files are deleted in the original repository
they seem to not behave that way in this one.
Probably --delete on rsync will do the job,I'm gonna try that now.
EDIT:yes I've just tested,it works fine.