Subversion for SysAdmins PDF Print E-mail
Written by David Torre   

Using your Repositories

By now, you should have a bare-bones Subversion server, accessible via a WebDAV-enabled Apache server. Although we created the mock “oracle-ERP” repository in the previous section, we'll now direct our attention to a slightly more IT-specific example-- checking in an Linux web server's entire /etc/httpd directory into its own repository.

Start off by creating a new repository, named “web1-etc.” This may be done either by following the directions from the previous section, or using a the provided mkrepo.sh shell script:

#!/bin/sh
if ! [ $1 ]
then
echo "Usage: mkrepo.sh repo-name"
else
svnadmin create /var/www/svnroot/$1
chown -R apache.apache /var/www/svnroot/$1/*
<location>
DAV svn
SVNPath /var/www/svnroot/$1
AuthType Basic
AuthName "$1"
AuthUserFile /var/www/svnroot/svn-accounts
Require valid-user
AuthzSVNAccessFile /var/www/svnroot/svn-acl
" >> /etc/httpd/conf.d/subversion.conf
service httpd graceful
We now need to set permissions for the new repository in /var/www/svnroot/svn-acl:
#
# Group "team-it"has read-write access to the web1-etc repository.
# All others have no access
#
[web1-etc:/]
@team-it = rw
Now that we have a repository set aside for the server “web1,” let's check-in our Apache directory to the newly created repository:
[root@server /]# cd /
[root@server /]# svn co http://svn.your-domain.com/web1-etc /
Authentication realm:  SVN Repository Authentication
Password for 'root': [Just hit enter]
Authentication realm:  SVN Repository Authentication
Username: dave
Password for 'dave': [enter your password]
Authentication realm:  SVN Repository Authentication
Checked out revision 0.

Now that we have a working version checked-out, we can need to tell SVN which files and folders we want to keep track of. Although you may theoretically check-in all of /etc (or most of / for that matter), we'll restrict our repository to /etc/httpd and all subdirectories. Our first step is to add /etc, but without all the other unnecessary subdirectories. This is done by passing the -N flag to the “add” command:
[root@server /]# svn add -N /etc
A         /etc
We now may preceed to adding the Apache configuration directory:
[root@server /]# svn add /etc/httpd/
A         /etc/httpd
A         /etc/httpd/logs
A         /etc/httpd/run
A         /etc/httpd/conf.d
A         /etc/httpd/conf.d/viewvc.conf
A         /etc/httpd/conf.d/subversion.conf
A         /etc/httpd/conf.d/README
A         /etc/httpd/conf.d/welcome.conf
A         /etc/httpd/conf
A         /etc/httpd/conf/httpd.conf
A         /etc/httpd/conf/magic
A         /etc/httpd/modules
[root@server /]#
Thus far, we've created a repository to hold our Apache configuration, checked out the latest revision (basically revision 0, with nothing in it), and told SVN which files and folders we want to include in the repository. From this point forward, we can start “checking in” our configurations at regular intervals. This is done with a basic “commit” or “ci” command:
[root@server /]#  cd /
[root@server /]# svn ci -m "Initial check-in by Dave..."
Adding         etc
Adding         etc/httpd
Adding         etc/httpd/conf
Adding         etc/httpd/conf/httpd.conf
Adding         etc/httpd/conf/magic
Adding         etc/httpd/conf.d
Adding         etc/httpd/conf.d/README
Adding         etc/httpd/conf.d/subversion.conf
Adding         etc/httpd/conf.d/viewvc.conf
Adding         etc/httpd/conf.d/welcome.conf
Adding         etc/httpd/logs
Adding         etc/httpd/modules
Adding         etc/httpd/run
Transmitting file data .........
Committed revision 1.
It's important to note that newly introduced files will not be added to your working copy of the repository by default. If you create a new Apache sub-config file (such as /etc/httpd/conf.d/some-new-module-config.conf) you'll need to explicitly add this file using “svn add [filename]” Alternatively, you may cron a re-add of everything in /etc/httpd perhaps once per day using something similar to:
svn status /etc/httpd | grep ^\? | cut -c8- | xargs svn add
From here on out, you may wish to check-in your Apache directory at schedule intervals, perhaps via cron:
00,30 * * * * svn ci -m “Regular scheduled check-in at: `date`”
Your Apache configuration, as well as all previous revisions, are kept at a repository which may be viewed or checked out at any time.


 
Copyright © 2006-2008 Atomic Fission