Subversion
Installing Subversion
If you do any type of development work, you'll probably want to use some type of version control, especially if you have multiple people working on the project or if you just want to take advantage of the easy way to deploy code.
$ sudo emerge -av subversion
Check that that apache2 USE flag is enabled before performing the emerge. After the emerge has completed, you can create a group for users who will have access to the repositories, including yourself. However, making yourself or any other users members of the apache group should be sufficient if you are wanting to use apache to leverage svn.
$ sudo groupadd svnusers $ sudo gpasswd -a <username> svnusers $ sudo gpasswd -a <username> apache
Create a home for subversion. In this example we'll use /var/svn/.
$ sudo mkdir /var/svn ; sudo mkdir /var/svn/conf
Create a repository. Substitute your repository's name in the place of reponame.
$ sudo svnadmin create --fs-type fsfs /var/svn/reponame/
Set permissions on the repository and subfolders.
$ sudo chown -R root:apache /var/svn/reponame/ $ sudo chmod -R g-w /var/svn/reponame/ $ sudo chmod -R g+rw /var/svn/reponame/db $ sudo chmod -R g+rw /var/svn/reponame/locks
If desired, edit the subversion server file and ensure the user and group are both set appropriately.
$ sudo nano -w /etc/conf.d/svnserve
When ready, start the server and add it to startup.
$ sudo /etc/init.d/svnserve start $ sudo rc-update add svnserve default
To get the web-based server going we will need to configure apache.
$ sudo nano -w /etc/conf.d/apache2
Make sure the following exist on the APACHE2_OPTS line:
-D SVN -D SVN_AUTHZ -D DAV -D DAV_FS
Now edit the apache svn config file
$ sudo nano -w /etc/apache2/modules.d/47_mod_dav_svn.conf
Here is an example configuration:
<Location /svn/>
DAV svn
# SVNPath /var/svn/''reponame''
SVNParentPath /var/svn
SVNListParentPath on
SVNAutoVersioning On
AuthType Basic
AuthName "Subversion repository"
AuthUserFile /var/svn/conf/svnusers
Require valid-user
SSLRequireSSL
</Location>
Add the svnusers group to the apache group.
$ sudo usermod -G svnusers -a apache
To put some basic security on the repository we'll use htpasswd2. Replace username with your intial user.
$ sudo htpasswd2 -c /var/svn/conf/svnusers username
Enter your desired password. Note the -c flag will overwrite this file if you use it again, so to add more users
$ sudo htpasswd2 /var/svn/conf/svnusers anotheruser
You may also need to change the ownership and permissions on the password file
$ sudo chown root:apache /var/svn/conf/svnusers $ sudo chmod 740 /var/svn/conf/svnusers
Restart apache to apply the settings.
$ sudo /etc/init.d/apache2 restart
Using subversion
You should now be able to view the repository you created at http://yourservername/svn/ after supplying your username and password. Next, navigate to the folder where your code is, and import the initial revision into the repository. Assuming the project code is owned by the apache user
$ sudo -u apache svn import . http://yourservername/svn/reponame/ -m 'Initial import'
You should get a challenge from apache to supply a password at this point, but press enter, and it will ask for a username. Supply the credentials you used for the htpasswd2 command above. To check out the code stored in the repository
$ sudo -u apache svn checkout http://yourservername/svn/reponame/ /path/of/project
Using the command line, you can check the status of a project.
$ sudo -u apache svn status
To add new files and folders to the next revision.
$ sudo -u apache svn add filename.ext
Likewise to remove files
$ sudo -u apache svn del filename.ext
To commit a new revision of the project to the repository
$ sudo -u apache svn commit -m "Useful message here" http://yourservername/svn/reponame/
To check out the latest revision
$ sudo -u apache svn update
A very handy cheat sheet for subversion commands is available [here].
Backing up repositories
Your subversion repositories can be backed up using the command
$ svnadmin dump /var/svn/repository | gzip > /path/to/repository.svn.gz
Simply sub in your repository name for repository in the above example.
Restoring repositories
If you are starting from scratch, create your repository using the example above and set the necessary permissions. When ready, extract the compressed repository backup file:
$ gunzip /path/to/repository.svn.gz
Use the following command to restore your repository.
$ svnadmin load /path/to/repository < /path/to/repository.svn