Archive

Archive for the ‘CVS’ Category

Managing multiple repositories in one subversion server

In my last post I have discussion how to setup a svnserver and create repository.Lets say the devolpers team in your company are working on different projects at the same time.So they need different repositories for different project.In this topic I will show you how to set up multiple repositories in single subvesrion server.

Scenario:-Lets say we have created a repository named repository for a project named project1 and repository name is also project1.Lets say the svn server has hostname svnserver and has user svn. So we can start the svn as

$ svnserve -d -r /project1

Now later project 2 and project 3 wanted to use subversion.These projects are unrelated to the project1 and therefore needs their own repository. So we have to setup multiple repositories.

How to Do?

I would recommend to backup the project1 repository before stepping further and then follow the steps mentioned below.

1.Create a new folder called repositories

$ ssh svn@svnserver
$ mkdir repositories
$ cd repositories

2.Inside the repositories folder create the repositories need for other projects.

$ svnadmin create roject2
$ svnadmin create project3

Now we should have a directory tree structure like below:


+---repositories
|   +---project2
|   |   +---conf
|   |   +---dav
|   |   +---db
|   |   +---hooks
|   |   \---locks
|   \---project3
|       +---conf
|       +---dav
|       +---db
|       +---hooks
|       \---locks
\---project1
    +---conf
    +---dav
    +---db
    +---hooks
    \---locks

Now all we need to do is move the project1 repository alongside the newer ones. For that we have to stop all instances of svnserve first, and of course notifying everyone working on the project1 project — but the move really will only take a few seconds.

Moving the old repository and restarting the server

$ killall svnserve
$ mv project1 repositories/project1
$ svnserve -d -r /home/svn/repositories

Inetd mode

If you’re using svnserve in inetd mode, most of the above applies directly — you simply adjust the svnserve configuration file in the obvious way to reflect the new repository root.

Repository URLs

The new repository URLs are:

  • svn://svnserver/project1
  • svn://svnserver/project2
  • svn://svnserver/project3

Note that the old URL for the project1 project was svn://svnserver/. This means that anyone with a project1 working copy will have to svn switch it.

$ svn switch --relocate svn://svnserver svn://svnserver/project1

Few TIPS:-

There may be a few scripts kicking around which need to be changed to reflect the new layout:

  • the repository backup script
  • any personal build scripts

Nothing should be hard, but with a very little forwarded planning you’ll see no loss of service. Once you’ve adjusted (if necessary) your backup script, I’d suggest now would be a good time to rehearse the recover-from-backup procedure.

Advertisements

Setting up subversion on unix/linux machine

Subversion is a free/open-source version control system.That is, Subversion manages files and directories, and the changes made to them, over time. It is also known as time machine as you can revert back to any older verion of your data at any time.It has a very pivotal role in code development as it has many features like

1.It keeps track of copy move and delete of fils.

2.It comits the full project ,not the singlefile with commit logs like who comitted.

3.It works across network and all the users can keep their data in a centralized space

4.If some one losts his file or if there is any probem in local computer no need to worry as you can export all your commited work from subvesion.

5.It maintains revision of code in each commit so that you can revert back to your prevous versoin of code reffering to the revision and log.

6.It not only keeps track of your files ,it also keeps track of directories also.

And many more……

The above features I have discussed are basically to make you understand how subverion can help.To know the technical feuture you can refer subersion feature page here.

Setting up subvesion(single instance):-

step-1:Install subversion

You can download your copy of subversion as per your linux/unix distribution from here.

If you want to install from souce you can get the installation guide from here.

As I am using fedora distro I will install using yum

root@host# yum install subversion

Step -2 :Create a folder where your repository will stay.

root@host# $mkdir /repository

step-3:Use svnadmin command to create repo structure

Then we will issue the svnadmin command that creates the structure within this directory that allows us to use it as a repository for files

 root@host# $svnadmin create /repository

This should create a directory structure that looks similar to the following:

root@host# ls -al /repository
total 36
drwxrwxrwx   7 root root 4096 2006-05-19 17:18 .
drwxrwxrwx  14 root root 4096 2006-05-19 17:18 ..
drwxrwxrwx   2 root root 4096 2006-05-19 17:18 conf
drwxrwxrwx   2 root root 4096 2006-05-19 17:18 dav
drwxrwxrwx   2 root root 4096 2006-05-19 17:18 db
-rwxrwxrwx   1 root root    2 2006-05-19 17:18 format
drwxrwxrwx   2 root root 4096 2006-05-19 17:18 hooks
drwxrwxrwx   2 root root 4096 2006-05-19 17:18 locks
-rwxrwxrwx   1 root root  379 2006-05-19 17:18 README.txt

Now that we have a single repository created, we need to allow remote access to it so that users can import their files.

Step-5:- configure svnserve.conf

Go inside conf directory and open svnserve.conf . By deafult guest accounts are allowed write access.To remove the access you need to search for “anon-access”.comment the line by putting a “# ” in the begning.

Step-6:-assign password to the users

In svnserve.conf search for the line containing “password-db = passwd” and uncomment it if commented.Then save svnserve.conf and open the conf/passwd file.You will find a section like below

[users]
# harry = harryssecret
# sally = sallyssecret

Below these lines put your username and password like

 kirti = parida

where kirti is the username and parida is the password.save the passwd file and exit.

Step-7:- start the subversion server

To start the subversion server execute the following command from your shell

root@host# svnserve -d -r /repository 

That’s it Your sub version server is up and ready.You can access it by the following link

svn://YOUR-IP-ADDRESS/repository

Special Discussions:

1.If you need to access SVN remotely, by default it runs on port TCP port 3690, so you need to make sure it is open in your firewall.

2.To give different access to different users you can edit the svnserve.conf file and under the general section you can write your rules like below

 [general]

kirti = write
srikant = read

Where kirti and srikant are users and write or read is their permissions
3.Start Subversion at Startup in quick way:-

In linux to manually start any program edit your /etc/rc.d/rc.local and add that program and the options you want to run on startup.So it will start after all thesystem services started.We can follw that way to start our subversion server .
Step-1:Edit your /etc/rc.d/rc.local file and put something like this in the end

 /usr/local/bin/svnserve -d -r /repository

Done…The next time you will start the server you will get the svn up and running withiut the need to start maually.
It works for sure. But this method have disadvanteges like

a. you can’t manually stop this program at any time just typing /etc/init.d/program stop, or by special Red Hat script – service: service program stop.

b. You can’t activate/deactivate such a program by system tools like chkconfig or setup Red Hat utility. This program will not run correctly according to system ‘run level’.

This method of running program at startup have exactly one advantage – it’s simple

4.Start subversion as a service.

On some systems (like Debian GNU/Linux) this requires us to write an init script so that the server starts up every time the system is rebooted. We would do this by creating a file called svnserve in the /etc/init.d directory, and then editing it to look like the following example file:

#! /bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/svnserve
NAME=svnserve
DESC="SVN Repository Server Daemon"
test -x $DAEMON || exit 0
OPTIONS="-d -r /cvs/src"
# Get lsb functions
#. /lib/lsb/init-functions
. /etc/default/rcS
start() {
       echo "Starting $DESC... "
       #       echo "Starting $DESC: "
       if ! start-stop-daemon --start --quiet --oknodo --exec $DAEMON -- $OPTIONS
>/dev/null 2>&1; then
               status=$?
               echo $status
               return $status
       fi
       log_end_msg 0
       return 0
}
case "$1" in
 start)
       start
       ;;
 stop)
       echo "Stopping $DESC: "
       start-stop-daemon --stop --quiet --oknodo --exec $DAEMON
       echo $?
       ;;
 restart|force-reload)
       $0 stop
       sleep 1
       start
       #echo "$NAME."
       ;;
 *)
       N=/etc/init.d/$NAME
       echo "Usage: $N {start|stop|restart|force-reload}" >&2
       exit 1
       ;;
esac
exit 0

Once this file is created and edited to look like the above script, we need to chmod the script to be executable and also set it to startup at boot time:

root@host# chmod +x /etc/init.d/svnserve
root@host# update-rc.d svnserve defaults

Now simply start the service by issuing the following command:

root@host# /etc/init.d/svnserve start
Starting SVN Repository Server Daemon...

We should now be able to connect to the Subversion repository remotely so that we can import files

5.Access subversion using http protocol.

Some times the administers do not want to forward extra port like 3690 used by svn.For that we can access apache through http protocol suing the WebDAV module. From a basic Apache installation, getting WebDAV to work is fairly simple. First, you need to make sure that mod_dav and mod_dav_svn are being loaded in the configuration file for Apache:

LoadModule      dav_module        modules/mod_dav.so
LoadModule      dav_svn_module    modules/mod_dav_svn.so

Note: In Debian GNU/Linux, the mod_dav is automatically loaded and a part of the Apache2 web server. One simply needs to install the mod_dev_svn module with apt:

root@host# apt-get install libapache2-svn

This will install and automatically configure the module for the Apache2 web server Next we will need to set up a Location directive to point to the repository. In our case, if we want the repository to be referenced with the URL http://IP-ADDRESS/repository, and the repository is located in /repository, you could use the following location directive in the apache2.conf file:

<Location /repository>
  DAV svn
  SVNPath /repository
  AuthType None
</Location>

Afterwards, simply restart eh Apache2 webserver:

root@host# /etc/init.d/apache2 restart

This will allow us to access the repository remotely with the Subversion client via the webdav protocol. We simply would substitute the svn:// access method with http://.

Note:- Each additional repository that is setup and configured needs its own location directive in the Apache2 configuration file.

Categories: CVS Tags: , , , , ,