Tag: Subversion(svn)

Subversion – How to configure with Apache WebDAV or svnserve

Subversion – How to configure with Apache WebDAV or svnserve

1] What is Subversion?

Subversion is a beautiful free/open source tool (software) to manage changes made to your information. Subversion manages files and directories, and the changes made to them over time. This allows you to recover older versions of your data or examine the history of how your data changed. Subversion can operate across networks, which allows it to be used by people on different computers.

2] Different methods of accessing subversion (svn) repository ?

There are three different methods of accessing subversion repository…

a) Local filesystem or Network filesystem accessed by client directly
b) Apache HTTP using WebDAV module
c) svnserve tunneled over an SSH (svn + ssh)

For more informatio, please refer the article http://www.indiangnu.org/2006/different-methods-of-accessing-subversion-svn-repository/

3] Subversion architectue –

Subversion provides two backends to store the data in svn repository

a) FSFS – Fast and Secure File Systtem –

FSFS backend provides quite a bit more flexibility in terms of its supported deployment scenarios. More flexibility means you have to work a little harder to find ways to deploy it incorrectly. FSFS is the default backend

b) Berkeley DB File system –

Berkeley DB provides real transaction support—perhaps its most powerful feature. Another great feature of Berkeley DB is hot backups—the ability to backup the database environment without taking it “offline”. But Berkeley DB environments are not portable!!

root@arun:~# ls -l  /var/repos_base/myrepository/
total 28
drwxr-xr-x 2 arunsb www-data 4096 2008-12-27 15:30 conf
drwxr-xr-x 2 arunsb www-data 4096 2008-12-26 16:34 dav
drwxr-sr-x 5 arunsb www-data 4096 2008-12-27 15:27 db
-r–r–r– 1 arunsb www-data    2 2008-12-26 16:34 format
drwxr-xr-x 2 arunsb www-data 4096 2008-12-26 16:34 hooks
drwxr-xr-x 2 arunsb www-data 4096 2008-12-26 16:34 locks
-rw-r–r– 1 arunsb www-data  229 2008-12-26 16:34 README.txt
root@arun:~#

root@arun:~# cat /var/repos_base/myrepository/db/fs-type
fsfs
root@arun:~#

4] How Install Subversion –

Ubuntu –

root@arun:~# apt-get install  subversion  subversion-tools
5] How to configure Subversion with Apache HTTP and WebDAV module –

Step (1) First of all we need to create the subversion repository….

root@arun:~# svnadmin create /var/repos_base/myrepository
root@arun:~#

* Make sure to set/change owership/permission of svn repository for Apache webserver user (www-data is apache user)

root@arun:/var/repos_base# chown arunsb:www-data -R /var/repos_base/
root@arun:~# chmod  775 -R /var/repos_base/
root@arun:~#
root@arun:~# ls -l /var/repos_base/
-rwxrwxr-x 1 arunsb www-data   63 2008-12-03 15:50 common_userdb
drwxrwxr-x 7 arunsb www-data 4096 2008-12-03 15:48 myrepository
root@arun:~#

Step (2) Authentication – common user DB for all repositories –

Let us create a file “/var/repos_base/common_userdb” which will contain users information in file and add few users…

root@arun:/var/repos_base# htpasswd  -c /var/repos_base/common_userdb   arunsb
New password:
Re-type new password:
Adding password for user arunsb

root@arun:/var/repos_base# htpasswd  /var/repos_base/common_userdb  ravi
New password:
Re-type new password:
Adding password for user ravi

root@arun:/var/repos_base# htpasswd  /var/repos_base/common_userdb  santhosh
New password:
Re-type new password:
Adding password for user santhosh

root@arun:/var/repos_base# cat /var/repos_base/common_userdb
arunsb:dXxZU5vmHxFoc
ravi:gGEX.dsWcwqzc
santhosh:Jlzed1almY.SY
root@arun:/var/repos_base#

Step (3) Now install Apache , WebDav module for apache –

Ubuntu –

root@arun:~# apt-get install apache2  apache2.2-common  libapache2-svn

you need to enable to WebDAV svn module for apache using following command on Ubuntu…

root@arun:~# a2enmod dav   dav_svn
root@arun:~#

* Make sure that Apache is running ….

Step (4) Configure svn repository with apache –

root@arun:~# cat /etc/apache2/mods-available/dav_svn.conf
# dav_svn.conf – Subversion/Apache configuration

<Location /myrepository>

DAV svn

#You need either SVNPath and SVNParentPath, but not both.
#use SVNParentPath if you have multiple repositories under one directory

SVNPath /var/repos_base/myrepository
#SVNParentPath /var/repos_base

# Access control is done at 3 levels –
#(1) Apache authentication
#(2) Apache <Limit> and <LimitExcept>
#(3) mod_authz_svn is a svn-specific authorization module

AuthType Basic
AuthName “|| Welcome to Subversion Repository || ”
AuthUserFile /var/repos_base/common_userdb

#To enable authorization via mod_authz_svn
AuthzSVNAccessFile  /var/repos_base/myrepository/conf/authz
Require valid-user

#<LimitExcept GET PROPFIND OPTIONS REPORT>
#Require valid-user
#</LimitExcept>

</Location>

## Add entry for other svn repositories

root@arun:~#

* Once done restart the Apache server and try to access svn repository as …

root@arun:~# svn list http://server_name_or_IP/your_repository_name_mentioned_in_dav_svn.conf_file

please refer the article for more operation http://www.indiangnu.org/2006/different-methods-of-accessing-subversion-svn-repository/

6] How to configure Subversion with svnserve tunneled over an SSH (svn + ssh) –

Step (1) Make sure that subversion is installed and repository is created…

Start up script for svnserve is as shown below (ubuntu), please update this file with proper setting…

root@arun:~# cat /etc/init.d/svnserve
#!/bin/bash

# startup script for svn server!
## svnserve  –daemon  –listen-port   3690  –pid-file /var/run/svn.server

SVN_DAEMON=”/usr/bin/svnserve”
PID_FILE=”/var/run/svn-server.pid”
LOG_FILE=”/var/log/svnserve.log”
SVN_PORT=3690
SVN_ROOT=”/var/repos_base”
case “$1” in

start)
if [ -f  $PID_FILE ];then
check=$(cat $PID_FILE)
echo “Subversion service (svnserve) already running [pid = $check]”
else
echo “Starting the Subversion service (svnserve)..”
$SVN_DAEMON  –daemon –root $SVN_ROOT  –listen-port $SVN_PORT –pid-file $PID_FILE  > $LOG_FILE 2>&1
echo “log file is $LOG_FILE”
echo “…”
echo “Done.”
fi
;;

stop)
echo “killing Subversion service (svnserve)…”
if [ -f  $PID_FILE ];then
#killall svnserve
kill -9 $(cat $PID_FILE)
rm  $PID_FILE
echo “…”
echo “Done.”
else
echo “NOT running…”
fi
;;

status)
if [ -f  $PID_FILE ];then
echo “Subversion service (svnserve) -”
pid_of_svnserve=$(cat $PID_FILE)
echo -e “Running & pid is $pid_of_svnserve”
else
echo “Subversion service (svnserve) NOT running…”
fi
;;

*)
echo “Usage: $0  {start|stop|status}”
exit 1
esac
exit 0
#DONE
root@arun:~#

Step (2) svnserve  configuration –

root@arun:~# cat /var/repos_base/myrepository/conf/svnserve.conf
### This file controls the configuration of the svnserve daemon, if you

[general]
### Authenticated users.  Valid values are “write”, “read”,
### and “none”.  The sample settings below are the defaults.
### The password-db option controls the location of the password file
### The authz-db option controls the location of the authorization
### rules for path-based access control.

realm = || Welcome to Subversion Repository ||
anon-access = none
auth-access = write
authz-db = authz
password-db = passwd

root@arun:~#

Step (3) Authentication for svnserve –

root@arun:~# cat /var/repos_base/myrepository/conf/authz
# single user, to a group of users defined in a special [groups]
# section, or to anyone using the ‘*’ wildcard.  Each definition can
# grant read (‘r’) access, read-write (‘rw’) access, or no access (”)

[groups]
svn_admin = arunsb , ravi

# remember here svn name which you mentioned in “dav_svn.conf” file

[myrepository:/]
@svn_admin= rw

[myrepository:/branches]
@svn_admin = rw
santhosh = r

[myrepository:/trunk]
@svn_admin= rw
santhosh = rw

root@arun:~# cat /var/repos_base/myrepository/conf/passwd
### Below it contains one section labelled [users].
### The name and password for each user follow, one account per line.

[users]

arunsb = 1234
ravi   = 1234
santhosh = 12345
root@arun:~#

Step (4) Start svnserve with following command –

root@arun:~# /etc/init.d/svnserve
Usage: /etc/init.d/svnserve  {start|stop|status}
root@arun:~#
root@arun:~# /etc/init.d/svnserve  start
Starting the Subversion service (svnserve)..
log file is /var/log/svnserve.log

Done.
root@arun:~# /etc/init.d/svnserve  status
Subversion service (svnserve) –
Running & pid is 11346
root@arun:~#

root@arun:~# netstat -nlp |  grep svnserve
tcp        0      0 0.0.0.0:3690            0.0.0.0:*               LISTEN      11346/svnserve
root@arun:~#

** HELP ?

root@arun:~# svnserve  –help
usage: svnserve [options]

Valid options:
-d [–daemon]            : daemon mode
–listen-port arg        : listen port (for daemon mode)
–listen-host arg        : listen hostname or IP address (for daemon mode)
–foreground             : run in foreground (useful for debugging)
-h [–help]              : display this help
–version                : show program version information
-i [–inetd]             : inetd mode
-r [–root] arg          : root of directory to serve
-R [–read-only]         : force read only, overriding repository config file
-t [–tunnel]            : tunnel mode
–tunnel-user arg        : tunnel username (default is current uid’s name)
-T [–threads]           : use threads instead of fork
-X [–listen-once]       : listen once (useful for debugging)
–pid-file arg           : write server process ID to file arg

root@arun:~#

Troubleshooting –

arunsb@arun:~$ svn co svn://192.168.0.1/myrepository/trunk/  /tmp/12345
svn: Not authorized to open root of edit operation
arunsb@arun:~$

* please add “anon-access = none” to ‘svnserve.conf’ conf file of your repository…

root@arun:~# vi /var/repos_base/myrepository/conf/svnserve.conf

arunsb@arun:~$ svn co svn://192.168.0.1/myrepository/trunk/   /home/arunsb/working_svn
Authentication realm: <svn://192.168.0.1:3690> ” || Welcome to Subversion Repository ||”
Password for ‘arunsb’:
Checked out revision 2.
arunsb@arun:~$

Thank you,

Arun Bagul

Different methods of accessing subversion (svn) repository

Different methods of accessing subversion (svn) repository

Introduction –

There are three different methods of accessing subversion repository…

1] Local filesystem or Network filesystem accessed by client directly
2] Apache HTTP using WebDAV module
3] svnserve tunneled over an SSH (svn + ssh)

First of all I am creating base directory for svn as “/var/repos_base”

root@arun:~# mkdir /var/repos_base
root@arun:~# ls -ld  /var/repos_base
drwxr-xr-x 2 root root 4096 2006-12-26 16:32 /var/repos_base
root@arun:~#

How to get help ?

root@arun:~# svnadmin  help
root@arun:~# svn help
root@arun:~# svnlook  help
root@arun:~# svnsync  help
root@arun:~# svnversion  –help
root@arun:~# svnserve  –help

1] How to create svn repository ?

“svnadmin” command is used to perform adminitrative task in subversion. Like creating, taking dump, hotcopy, recovering & verifying subversion repository.

root@arun:~# svnadmin  create  /var/repos_base/myrepository

Here “/var/repos_base/myrepository” is the physical location of repository….

root@arun:~# ls -l /var/repos_base/myrepository/
total 28
drwxr-xr-x 2 root root 4096 2006-12-26 16:34 conf
drwxr-xr-x 2 root root 4096 2006-12-26 16:34 dav
drwxr-sr-x 5 root root 4096 2006-12-26 16:34 db
-r–r–r– 1 root root    2 2006-12-26 16:34 format
drwxr-xr-x 2 root root 4096 2006-12-26 16:34 hooks
drwxr-xr-x 2 root root 4096 2006-12-26 16:34 locks
-rw-r–r– 1 root root  229 2006-12-26 16:34 README.txt
root@arun:~#

2] How to create trunk , branches etc directories in svn repository ?

method (1) ~ Local filesystem

root@arun:~# svn  mkdir   file:///var/repos_base/myrepository/trunk/

Log message unchanged or not specified
a)bort, c)ontinue, e)dit
c

Committed revision 1.
root@arun:~# svn  mkdir   file:///var/repos_base/myrepository/branches

Log message unchanged or not specified
a)bort, c)ontinue, e)dit
c

Committed revision 2.
root@arun:~#

root@arun:~# svn  list   file:///var/repos_base/myrepository/
branches/
trunk/
root@arun:~#

method (2) ~ Apache HTTP using WebDAV module

arunsb@arun:~$ svn  mkdir    http://192.168.0.1/myrepository/trunk/

Log message unchanged or not specified
a)bort, c)ontinue, e)dit
c
Authentication realm: <http://192.168.0.1:80> || Welcome to Subversion Repository ||
Password for ‘arunsb’:

Committed revision 1.
arunsb@arun:~$ svn   mkdir    http://192.168.0.1/myrepository/branches/

Log message unchanged or not specified
a)bort, c)ontinue, e)dit
c

Committed revision 2.
arunsb@arun:~$ svn  list  http://192.168.0.1/myrepository/
branches/
trunk/
arunsb@arun:~$

method (3) ~ svnserve tunneled over an SSH (svn + ssh)

arunsb@arun:~$ svn mkdir  svn://192.168.0.1/myrepository/branches/

Log message unchanged or not specified
a)bort, c)ontinue, e)dit
c
Authentication realm: <svn://192.168.0.1:3690> ” || Welcome to Subversion Repository ||”
Password for ‘arunsb’:

Committed revision 1.
arunsb@arun:~$ svn mkdir  svn://192.168.0.1/myrepository/trunk/

Log message unchanged or not specified
a)bort, c)ontinue, e)dit
c

Committed revision 2.
arunsb@arun:~$ svn list  svn://192.168.0.1/myrepository/
branches/
trunk/
arunsb@arun:~$

3] How to import un-versioned data in svn ?

root@arun:~# ls -l  /root/source_code/
total 12
-rwxr-xr-x 1 root root    3 2006-12-26 20:01 arun.html
-rw-r–r– 1 root root 2119 2006-12-26 20:03 License
-rwxr-xr-x 1 root root   64 2006-12-26 20:01 my.pl
root@arun:~#

* I wanted to import this data….

method (1)

root@arun:~# svn import   /root/source_code/ file:///var/repos_base/myrepository/trunk/    -m “welcome to first import”
Adding         /root/source_code/my.pl
Adding         /root/source_code/License
Adding         /root/source_code/arun.html

Committed revision 3.
root@arun:~#

List the imported data from svn repository –

arunsb@arun:~$ svn list file:///var/repos_base/myrepository/trunk/
License
arun.html
my.pl
arunsb@arun:~$

method (2)

arunsb@arun:~$ svn import   /root/source_code/   http://192.168.0.1/myrepository/trunk/  -m “welcome to first import”
Authentication realm: <http://192.168.0.1:80> || Welcome to Subversion Repository ||
Password for ‘arunsb’:
Adding         /root/source_code/my.pl
Adding         /root/source_code/License
Adding         /root/source_code/arun.html

Committed revision 3.
arunsb@arun:~$

method (3)

arunsb@arun:~$ svn import   /root/source_code/   svn://192.168.0.1/myrepository/trunk/  -m “welcome to first import”
Authentication realm: <svn://192.168.0.1:3690> ” || Welcome to Subversion Repository ||”
Password for ‘arunsb’:
Adding         /root/source_code/my.pl
Adding         /root/source_code/License
Adding         /root/source_code/arun.html

Committed revision 3.
arunsb@arun:~$

4] How to check out the svn repository ?

method (1)

arunsb@arun:~$ svn checkout file:///var/repos_base/myrepository/trunk/  /home/arunsb/mysource_code/
A    /home/arunsb/mysource_code/my.pl
A    /home/arunsb/mysource_code/License
A    /home/arunsb/mysource_code/arun.html
Checked out revision 3.
arunsb@arun:~$

method (2)

arunsb@arun:~$ svn checkout   http://192.168.0.1/myrepository/trunk/   /home/arunsb/mysource_code/
Authentication realm: <http://192.168.0.1:80> || Welcome to Subversion Repository ||
Password for ‘arunsb’:
Checked out revision 2.
arunsb@arun:~$

method (3)

arunsb@arun:~$ svn co svn://192.168.0.1/myrepository/trunk/   /home/arunsb/mysource_code/
Authentication realm: <svn://192.168.0.1:3690> ” || Welcome to Subversion Repository ||”
Password for ‘arunsb’:
Checked out revision 2.
arunsb@arun:~$

* Now check checked out data…

arunsb@arun:~$ ls -l /home/arunsb/mysource_code/
total 12
-rwxr-xr-x 1 arunsb oinstall    3 2006-12-26 20:42 arun.html
-rw-r–r– 1 arunsb oinstall 2119 2006-12-26 20:42 License
-rwxr-xr-x 1 arunsb oinstall   64 2006-12-26 20:42 my.pl
arunsb@arun:~$

** Now go to “/home/arunsb/mysource_code/”

arunsb@arun:~/mysource_code$ cd  /home/arunsb/mysource_code/
arunsb@arun:~/mysource_code$ ls
arun.html  License  my.pl
arunsb@arun:~/mysource_code$

* How to get information about svn repository –

arunsb@arun:~/mysource_code$ svn info
Path: .
URL: file:///var/repos_base/myrepository/trunk
Repository Root: file:///var/repos_base/myrepository
Repository UUID: 361de285-9226-493b-aed7-a95619a457c0
Revision: 3
Node Kind: directory
Schedule: normal
Last Changed Author: root
Last Changed Rev: 3
Last Changed Date: 2006-12-26 20:38:14 +0530 (Fri, 26 Dec 2006)
arunsb@arun:~/mysource_code$

4] How to commit data ?

Now create  new file “new_file.php” in modify the file…

arunsb@arun:~/mysource_code$ touch  new_file.php
arunsb@arun:~/mysource_code$ ls
arun.html  License  my.pl  new_file.php
arunsb@arun:~/mysource_code$ vi new_file.php
arunsb@arun:~/mysource_code$ mkdir  new_dir
arunsb@arun:~/mysource_code$ ls
arun.html  License  my.pl  new_dir  new_file.php
arunsb@arun:~/mysource_code$

* Now check the status… ‘?’ means file or directory NOT in svn repository

arunsb@arun:~/mysource_code$ svn  status
?      new_dir
?      new_file.php
arunsb@arun:~/mysource_code$

* Now add  newly created files and directories…

arunsb@arun:~/mysource_code$ svn add  new_dir
A         new_dir
arunsb@arun:~/mysource_code$ svn add  new_file.php
A         new_file.php
arunsb@arun:~/mysource_code$

* Another method to add directory is…

arunsb@arun:~/mysource_code$ svn mkdir new_dir2
A         new_dir2
arunsb@arun:~/mysource_code$

* Now check the status… ‘A’ means data is modified

arunsb@arun:~/mysource_code$ svn  status
A      new_dir
A      new_dir2
A      new_file.php
arunsb@arun:~/mysource_code$

* commit modified to svn repository…

arunsb@arun:~/mysource_code$ svn commit  -m “committing  data”
Adding         new_dir
Adding         new_dir2
Adding         new_file.php
Transmitting file data .
Committed revision 4.
arunsb@arun:~/mysource_code$

5] How to check svn status (working copy) –

arunsb@arun:~/mysource_code$ svn status
arunsb@arun:~/mysource_code$

arunsb@arun:~/mysource_code$ svn  status
A      new_dir
A      new_dir2
A      new_file.php
arunsb@arun:~/mysource_code$

6] How to update svn working copy –

arunsb@arun:~/mysource_code$ svn update
At revision 4.
arunsb@arun:~/mysource_code$

* update working copy to specific revision….

arunsb@arun:~/mysource_code$ svn update -r20

7] How to check  svn log (working copy) –

arunsb@arun:~/mysource_code$ svn log
————————————————————————
r1 | arunsb | 2008-12-26 21:53:04 +0530 (Fri, 26 Dec 2006) | 1 line
————————————————————————
arunsb@arun:~/mysource_code$

Thank you,
Arun Bagul