Wednesday, 26 September 2012

How to configure svn in rhel 6.3 / centos 6.3


-->
Apache Subversion (often abbreviated SVN, after the command name svn) is a software versioning and revision control system distributed under an open source license. Developers use Subversion to maintain current and historical versions of files such as source code, web pages, and documentation. Its goal is to be a mostly compatible successor to the widely used Concurrent Versions System (CVS).

[root@station1 ~]# yum install mod_dav_svn subversion
[root@station1 ~]# vim /etc/httpd/conf.d/subversion.conf
41 <Location /svn>
42 DAV svn
43 SVNParentPath /var/www/svn
44 AuthType Basic
45 AuthName "Subversion repositories"
46 AuthUserFile /etc/svn-auth-users
47 Require valid-user
48 </Location>
[root@station1 ~]# htpasswd -cm /etc/svn-auth-users ranjith
New password:
Re-type new password:
Adding password for user ranjith
[root@station1 ~]# mkdir /var/www/svn
[root@station1 ~]# cd /var/www/svn/
[root@station1 svn]# svnadmin create testrepo
[root@station1 svn]# chown -R apache.apache testrepo
[root@station1 svn]# chcon -R -t httpd_sys_content_t /var/www/svn/testrepo
[root@station1 svn]# chcon -R -t httpd_sys_rw_content_t /var/www/svn/testrepo
[root@station1 ~]# service httpd restart

Goto http://station1.ranjihat.com/svn/testrepo address and you should see something like following, write username and password:




Configure repository
To disable anonymous access and enable access control add following rows to testrepo/conf/svnserve.conf file:

[root@station1 ~]# vim /var/www/svn/testrepo/conf/svnserve.conf
12 anon-access = none
27 authz-db = authz

Create trunk, branches and tags structure under testrepo

Create “template” directories with following command:

[root@station1 ~]# mkdir -p /tmp/svn-structure-template/{trunk,branches,tags}

Then import template to project repository using “svn import” command:

[root@station1 ~]# svn import -m 'Initial import' /tmp/svn-structure-template/ http://station1.ranjihat.com/svn/testrepo/

Authentication realm: <http://station1.ranjihat.com:80> Subversion repositories
Password for 'root':
Authentication realm: <http://station1.ranjihat.com:80> Subversion repositories
Username: ranjith
Password for 'ranjith':
Adding /tmp/svn-structure-template/trunk
Adding /tmp/svn-structure-template/branches
Adding /tmp/svn-structure-template/tags
-----------------------------------------------------------------------
ATTENTION! Your password for authentication realm:
<http://station1.ranjihat.com:80> Subversion repositories
can only be stored to disk unencrypted! You are advised to configure
your system so that Subversion can store passwords encrypted, if
possible. See the documentation for details.
You can avoid future appearances of this warning by setting the value
of the 'store-plaintext-passwords' option to either 'yes' or 'no' in
'/root/.subversion/servers'.
-----------------------------------------------------------------------
Store password unencrypted (yes/no)? yes
Committed revision 1.

Now refresh the webpage.


Backup (dump) SVN (Subversion) repository


[root@station1 ~]# mkdir /backups
[root@station1 ~]# svnadmin dump /var/www/svn/testrepo > /backups/testrepo.dump
* Dumped revision 0.
* Dumped revision 1.

[root@station1 ~]# gzip -9 /backups/testrepo.dump
[root@station1 ~]# ls /backups/testrepo.dump.gz
/backups/testrepo.dump.gz
[root@station1 ~]# rm -rf /var/www/svn/testrepo/
[root@station1 ~]# gunzip /backups/testrepo.dump
[root@station1 ~]# ls /backups/testrepo.dump
/backups/testrepo.dump
[root@station1 ~]# svnadmin create /var/www/svn/testrepo
[root@station1 ~]# chown -R apache:apache /var/www/svn/testrepo
[root@station1 ~]# chcon -R -t httpd_sys_content_t /var/www/svn/testrepo
[root@station1 ~]# chcon -R -t httpd_sys_rw_content_t /var/www/svn/testrepo
[root@station1 ~]# svnadmin load /var/www/svn/testrepo < /backups/testrepo.dump
<<< Started new transaction, based on original revision 1
* adding path : branches ... done.
* adding path : tags ... done.
* adding path : trunk ... done.
------- Committed revision 1 >>>
[root@station1 ~]# ls /var/www/svn/testrepo/
conf db format hooks locks README.txt 


Automatic SVN (Subversion) Repository Backups



[root@station1 ~]# crontab -e
@daily svnadmin dump /var/www/svn/testrepo | gzip -9 > /backups/testrepo-$(date +"%Y-%m-%d-%T").dump.gz
[root@station1 ~]# service crond restart
[root@station1 ~]# crontab -l
@daily svnadmin dump /var/www/svn/testrepo | gzip -9 > /backups/testrepo-$(date +"%Y-%m-%d-%T").dump.gz


3 comments:

  1. awesome post .......... thanks

    ReplyDelete
  2. Nice post. The only thing I had to change was getting full context:
    chcon -h system_u:object_r:httpd_sys_content_t /var/svn/repo
    chcon -R -h apache:object_r:httpd_sys_content_t /var/svn/repo/*
    chcon -h system_u:object_r:httpd_sys_rw_content_t /var/svn/repo
    chcon -R -h apache:object_r:httpd_sys_rw_content_t /var/svn/repo/*

    Oh... and I also had to make sure that svn had write permissions:
    chown -R 775 /var/svn/

    ReplyDelete
  3. chcon -h system_u:object_r:httpd_sys_content_t /var/svn/newrep/
    chcon -R -h apache:object_r:httpd_sys_content_t /var/svn/newrep/
    you can find more info here ..
    Install svn server on centos 6
    thanks..

    ReplyDelete