Table of Contents

SVN (Subversion)

Information

SVN, like CVS and RCS, is a revision control application. I want to use this for web developing (for me and Brent), my perl/bash code, and anything else that makes sense to put into SVN… (maybe I'll stick /etc into there or something)

Installation

First we must install SVN.

  1. add the following to /etc/make.conf:
    .if ${.CURDIR:M*/devel/subversion*}
    WITH_PERL=yes
    WITH_MOD_DAV_SVN=yes
    WITH_APACHE2_APR=yes
    WITH_BERKELEYDB=db41
    WITH_SVNSERVE_WRAPPER=yes
    .endif
  2. add the following to /usr/local/etc/pkgtools.conf (in the MAKE_ARGS section):
       'devel/subversion*' => [
            'WITH_PERL=yes',
            'WITH_MOD_DAV_SVN=yes',
            'WITH_APACHE2_APR=yes',
            'WITH_BERKELEYDB=db41',
            'WITH_SVNSERVE_WRAPPER=yes',
       ],
  3. go into the ports subversion directory and run make:
    # cd /usr/ports/devel/subversion
    # make install clean

Configuration

There are two different methods one can use to run an SVN server:


The follow procedure is for the Apache method (it provides secure access when using https://):

  1. setup your repository:
    # mkdir /usr/local/svn
    # svnadmin create /usr/local/svn/web
    # chown -R www:www /usr/local/svn/web
  2. Create /usr/local/etc/apache22/extra/httpd-svn-authz.conf with the following content:
       <Location /svn>
        DAV svn
        SVNParentPath /usr/local/svn
    
        # Subversion repository ACL file
        AuthzSVNAccessFile /usr/local/www/apache22/auth/svn-access
    
        # prevents anonymous access
        Require valid-user
    
        # Apache Authorization configuration
        AuthType Basic
        AuthName "thoughtbit repositories"
        AuthUserFile /usr/local/www/apache22/auth/svn-auth
    
        # Rewrite all requests to https to ensure encrypted passwords
        RewriteEngine On
        RewriteCond %{HTTPS} !on
        RewriteRule ^/(.*) https://%{SERVER_NAME}%{REQUEST_URI} [R]
    </Location>   
  3. add the above httpd-svn-authz.conf to /usr/local/etc/apache22/httpd.conf:
    # Subversion repostories
    Include etc/apache22/extra/httpd-svn-authz.conf
  4. Since we are forcing our svn access to go over https:, we need to add our CustomLog directive to /usr/local/etc/apache22/extra/httpd-ssl.conf, right after the other CustomLog directive:
    <code> # log for subversion CustomLog /var/log/httpd-svn.log “%t %u %{SVN-ACTION}e” env=SVN-ACTION </code> - create the AuthUserFile (
    /usr/local/www/apache22/auth/svn-auth):
    <code> # cd /usr/local/www/apache22 # mkdir auth # chgrp www auth # chmod 2750 auth # cd auth # htpasswd -cm svn-auth john and for additional users: # htpasswd -m /usr/local/www/apache22/auth/svn-auth bob </code> - create the AuthzSVNAccessFile (
    /usr/local/www/apache22/auth/svn-access):
    <code> # svn access file # # created Aug 11, 2007 2:23am by john # gives access to the web repository from the root down [web:/] john = rw </code> - import your data: - first prepare the source:
    <code> $ mkdir thoughtbit $ cd thoughtbit $ mkdir trunk branches tags $ cp -R /your/source/code/* trunk/ $ cd .. </code> - and import:
    <code> $ svn import thoughtbit https://shalom/svn/web/thoughtbit -m “initial import” </code> - since this is based on my current “production” website, I'll create a
    tag to designate the release-1.0 snapshot:
    <code> $ svn copy https://shalom/svn/web/thoughtbit/trunk \ > https://shalom/svn/web/thoughtbit/tags/release-1.0 \ > -m “intial release-1.0 based on initial import of code” </code> <note tip> To copy repositories, run the following commands (where myrepos is a currently existing repository to be copied to the new “newrepos” repository):

    <code> $ svnadmin create newrepos $ svnadmin dump myrepos | svnadmin load newrepos </code> </note> ===== Backup via cron ===== It's probably a good idea to configuration automatic backups of the SVN repository. I am going to use the
    /usr/local/share/subversion/backup/hot-backup.py program to handle the backups (and only keeping the most recent backups on the filesystem), and cron to schedule this daily. <note note> I need to setup a backup user who has read access to the subversion directory, and run the cronjob as that user… </note> - create a backup location:
    <code> # cd # pwd # /root # mkdir -p backup/svn # mkdir -p backup/scripts </code> - we need to create the backup script: - <code># cd backup/scripts</code> - <code># vi svn-backup.sh</code> - paste the following into
    svn-backup.sh, and adjust accordingly:
    <code bash> #!/usr/local/bin/bash # # Subversion Repository Backup Script # # created 5:20am 12 Aug 2007 by John Friar # Subversion Repository Backup Location: BACKUPDIR=/root/backup/svn/ # The root directory (your repositor[y|ies] [is|are] inside this directory): REPOROOT=/usr/local/svn/ # List the repositor[y|ies] you want backed up: REPOLIST=“web” # Archive type (options: bz2, gz, zip): ARCHTYPE=“bz2” # The hot-backup.py python script location: HOTBACKUP=/usr/local/share/subversion/backup/hot-backup.py; # Python binary location: PYTHON=/usr/local/bin/python; for i in ${REPOLIST}; do ${PYTHON} ${HOTBACKUP} –archive-type=${ARCHTYPE} ${REPOROOT}${i} ${BACKUPDIR} done </code> - make the backup script executable:
    <code> # chmod 750 svn-backup.sh </code> - test the script:
    <code> # ./svn-backup.sh </code> - add the script to
    /etc/crontab'':
    <code bash> # # Backup Subversion repositories 45 6 * * * root /root/backup/scripts/svn-backup.sh </code> ===== Reference Links ===== * http://www.onlamp.com/pub/a/bsd/2005/05/12/FreeBSD_Basics.html - guide to installing/configuring SVN on FreeBSD * http://svnbook.red-bean.com/ - the free SVN book * http://svnbook.red-bean.com/nightly/en/svn.serverconfig.httpd.html * http://zoneit.free.fr/esvn/ - a slick GUI client for SVN * http://gentoo-wiki.com/HOWTO_Apache2_with_subversion_SVN_and_DAV * http://svn.collab.net/repos/svn/trunk/INSTALL * http://httpd.apache.org/docs-2.0/misc/tutorials.html * http://svnbook.red-bean.com/nightly/en/svn.reposadmin.maint.html#svn.reposadmin.maint.backup - repository backup information ==