At work we use subversion to manage our code, we also use Trac to manage bugs which has handy hooks into subversion. Unfortunately they are on different (internal) servers.
This is quick What I DidTM to get the live svn server (taipan) to sync with the Trac server (apu)
taipan: svn server (Debian 3.0 woody)
apu: svn mirror (Debian 3.1 sarge)
taipan svn root: /export/codestore/svn_repositories/
apu svn root: /export/codestore/
1) Create svn user on apu.
useradd -m -d /home/svn -s /bin/bash svn && passwd svn
2) change ownership so that apu’s svn store is owned by svn and the group is that of the apache server
apu:/export# chown -R svn.www-data /export/codestore/
3) Create ssh key
apu:~# su – svnsync
svn@apu:~$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/svn/.ssh/id_rsa):
Created directory ‘/home/svn/.ssh’.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/svn/.ssh/id_rsa.
Your public key has been saved in /home/svn/.ssh/id_rsa.pub.
The key fingerprint is:
7c:46:b0:92:f5:8c:cc:b5:d9:de:b3:d4:70:43:4f:07 svnsync@apu
4) On my server the svn user has no login shell, ‘fix’ this:
taipan:/export/codestore# cat /etc/passwd | grep svn
svn:x:101:101::/home/svn/:/bin/false
Use vipw to change this to:
taipan:/export/codestore# cat /etc/passwd | grep svn
svn:x:101:101::/home/svn/:/bin/bash
5) Copy apu’s svn ssh key over to taipan
svnsync@apu:~$ cat .ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEA9PNmQULAXqFE+xMe/5Kj2qBAwMa6tFpKAata3T5Lc2X+x/hOjub0mkrS83LsLXljfSiSu3/iqpngYlygaqE7mpSQc7arVDRfxUbG7wytUaEAv2sh8hYMEf4PU/uSj/kEEf16VjZuSmhBY8V5lQUTUVkVal0L90UiZdtyVK9QgqM= svnsync@apu
In my case copy and paste between Putty windows so that:
svn@taipan:/home/svn/.ssh$ cat authorized_keys
sh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEAvB50YGvrWb/V308a00LDcu8AuWnHkz4UM9tKJXawqmKJ1m3naKLpubImSn3Fz36thdTqYajRrynL6GhZ/xFv2XaoViExIM+p0gvKBJzq40W35VtBYSIHv4uJTIrNq8ZZPMdEwCZCW+YRi3d5FZLDxkY1c7ZhLxdT7IQKdTjdDm8= svn@apu
6) test it:
svn@apu:~$ ssh taipan
Linux taipan 2.4.18-bf2.4 #1 Son Apr 14 09:53:28 CEST 2002 i686 unknownPlay nicely kids
==============================================================
Last login: Tue Sep 13 22:48:32 2005 from 10.0.1.120
svn@taipan:~$
Bingo.
7) Sync the codestores:
svn@apu:~/bin$ pwd
/home/svn/binsvn@apu:~/bin$ cat mirror.sh
#!/bin/sh
pgrep rsync
if [ $? -eq 1 ]; then
rsync -ae ssh –delete taipan:/export/codestore/svn_repositories/ /export/codestore
else
echo “rsync already running….exiting”
exit 1
fisvn@apu:~/bin$ chmod 0755 mirror.sh
svn@apu:~/bin$ ./mirror.sh
./mirror.sh: rsync: command not found
LOL, maybe I should install rsync
svn@apu:~/bin$ su –
Password:
apu:~# apt-get install rsync
Reading Package Lists… Done
Building Dependency Tree… Done
The following NEW packages will be installed:
rsync
0 packages upgraded, 1 newly installed, 0 to remove and 150 not upgraded.
Need to get 203kB of archives. After unpacking 373kB will be used.
Get:1 ftp://ftp.uk.debian.org stable/main rsync 2.6.4-6 [203kB]
Fetched 203kB in 1s (167kB/s)
Selecting previously deselected package rsync.
(Reading database … 20339 files and directories currently installed.)
Unpacking rsync (from …/rsync_2.6.4-6_i386.deb) …
Setting up rsync (2.6.4-6) …
rsync daemon not enabled in /etc/default/rsync
(30 seconds have elapsed)
apu:~# logout
svn@apu:~/bin$ ./mirror.sh &svn@apu:~/bin$ ps -ax
28521 ttyp0 S 0:00 /bin/sh ./mirror.sh
28523 ttyp0 S 0:02 rsync -ae ssh –delete taipan:/export/codestore/svn_repositories/ /export/codestore
28524 ttyp0 R 2:41 ssh taipan rsync –server –sender -logDtpr . /export/codestore/svn_repositories/
28525 ttyp0 S 0:47 rsync -ae ssh –delete taipan:/export/codestore/svn_repositories/ /export/codestore
and wait a while. Once you’re happy it’s copied over then you need to cron it for future syncs.
Every 10 mins:
svn@apu:~$ crontab -e
*/10 * * * * /home/svn/bin/mirror.sh
Works for me!
Leave a Reply