ubuntu svn server

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

A, SVN installation
1 installation package
$ sudo apt-get install subversion

2 add SVN management user and group subversion
$ sudo adduser svnuser
$ sudo addgroup subversion
$ sudo addgroup svnuser subversion

3 to create the project directory
$ sudo mkdir /home/svn
$ cd /home/svn
$ sudo mkdir fitness
$ sudo chown -R root:subversion fitness
$ sudo chmod -R g+rws fitness

4 create an SVN file storage
$ sudo svnadmin create /home/svn/fitness

5 access modes and project introduction:
$ svn co file:///home/svn/fitness
$ svn co file://localhost/home/svn/fitness
* Be careful:
If you are not sure the name of the host, you must use three slashes (///), but if you specify the host name, you must use two backslashes(//).
The following command is used to import the project into SVN document warehouse:
$ svn import -m "New import" /home/svn/fitness file:///home/svnuser/src/fitness
Be sure to mark the import information

6 access settings
Modify the /home/svn/fitness directory:
svnserve.conf , passwd , Authz three files, the most front-end spaces are not permitted
Edit the svnserve.conf file, the following two lines uncomment
password-db = password
authz-db = authz

//Add that
# [general]
anon-access = read
auth-access = write
password-db = passwd
Where anon-access and auth-access are anonymous and user permissions, the default to the anonymous user read-only permissions, but if you want to hide

User access, just put the read into none can achieve the purpose of.

Edit the /home/svnuser/etc/passwd as follows:
mirze = 123456
test1 = 123456
test2 = 123456
Edit the /home/svnuser/etc/authz as follows
admin = mirze,test1
test = test2
Here the three user mirze, test1, test2 password is 123456
The mirze and test1 belong to the Admin Group, have read and write permissions, test2 belongs to the test group only read access

7 start the SVN service
svnserve -d -r /home/svn
-d said svnserver to "protect" process mode
-r specifies the root file system (root directory repository), so that the client can not enter the full path, you can access the repository
Such as: SVN://

The SVN installation is completed.
LAN access methods:
For example: svn checkout svn:// --username mirze --password 123456 /var/www/fitness

If the DB insufficient privileges sudo Chmod -r 777 DB to the authority.

Two, HTTP:// [apache]
1 installation package [subversion] installed
$ sudo apt-get install libapache2-svn

Create a version of the warehouse:
sudo svnadmin create /Directory.
Directory must exist, this is a saved version of warehouse place, different versions of the repository to create different folder, for example:
sudo svnadmin create /home/svn/project
/home/svn/project had this directory what are not, then execute the following command to see, some more files and folders, we need to operate the conf folder, a file, a folder called passwd, used to store a user name and password.
Then the version repository directory authorization to the Apache read and write:
sudo chown -R www-data:www-data /Directory.
Then came the open Apache configuration file:
sudo gedit /etc/apache2/mods-available/dav_svn.conf

Add the following content:
<Location /project>
DAV svn
SVNPath /home/svn/project
AuthType Basic
AuthName "myproject subversion repository"
AuthUserFile /home/svn/project/conf/passwd
Require valid-user

Location is an access address, such as the above address, access time is

There are two lines are commented out, to ensure that each time the user name and password.
The last step is to create a user access, suggested username password file stored in the warehouse under the current version of conf folder, this version of warehouse many no too.
Because the existing passwd file under the conf folder, so directly add user:
sudo htpasswd -c /home/svn/project/conf/passwd test
Then enter the password two times, the Laoyang user will be created.
Open the file /home/svn/project/conf/passwd, will be open to form such as follows the form of the text:
test:WEd.83H.gealA //The back is the encrypted password.
Create later, again need add this user to other versions of the repository, directly to a copy can be passed.
You can restart Apache.
sudo /etc/init.d/apache2 restart


Three, synchronous update [hook]

Synchronous program ideas: users submit the program to the SVN, the SVN trigger hooks, processed in different hooks, here used is post-commit, using post-commit to code detection to the SVN server local hard disk directory, and then through the Rsync synchronization to the remote WEB server.

Points of knowledge:
1, SVN hooks
# Start-commit submitted before the triggering transaction
# Pre-commit submit completed before the triggering transaction
# Transaction triggering post-commit submit completed
# Pre-revprop-change version attribute modification before the triggering transaction
# Post-revprop-change version of properties of the modified trigger affairs
Through the above name written script can achieve a variety of functions, very powerful.
2, The use of specific parameters of synchronous Rsync commands
3, Having a base language programming ability of bash Python Perl can be achieved.

Post-commit specific implementation details
Post-commit script

Edit the file: sudo vim /home/svn/fitness/hooks/post-commit

Note: edit finished post-commit, execution: sudo chmod 755 post-commit


export LANG=zh_CN.UTF-8
sudo /usr/bin/svn update /var/www/www --username mirze --password 123456


#Set variable
export LANG=en_US.UTF-8

#update the code from the SVN
$SVN update $WEB --username user --password password
#If the previous command completed successfully, to continue the following
if [ $? == 0 ]
echo "" >> $LOG
echo `date` >> $LOG
echo "##############################" >> $LOG
chown -R nobody:nobody /home/test_nokia/
#Synchronization code from the SVN server to the WEB server, notes:by the key
$RSYNC -vaztpH --timeout=90 --exclude-from=/home/svn/exclude.list $WEB root@$WEBIP:/www>> $LOG

The above is the specific post-commit program
Matters needing attention:
1, To define a variable, is mainly used path command. Because of considering the security problem of SVN, no calling system variables, if the manual is not a problem, but SVN cannot perform the automatic execution will.
2, We must first manual checkout out a copy of SVN update before, and there must be added by the user and password if only manual will be updated automatically, but did not.
3, With the previous command, judgment, if update was out of the question, the program did not withdraw from the case will continue to synchronization code to the WEB server, this will cause a problem with the code
4, Remember to set the user, because Rsync can synchronize file attributes, and our WEB server is generally not a root user, the user is not correct will cause the WEB programs that don't work.
5, Suggest the best log, mistakes can quickly.
6, Finally, the most critical data synchronization, the relevant parameters of Rsync must be clear, this is not to say. Pay attention to the following scene:
The environment here is the SVN server and the WEB server is open
The SVN server is defined as the source server WEB server to the destination server
Scene one, if the destination WEB server for the synthesis of mixed, as only one WEB static resource, submitted by the user, automatically generated in a directory of WEB - delete, this parameter is not recommended to use
The above procedure is such, is the realization of the source server to the destination server update and add, but not delete operation, the contents of the WEB server will be more to the source SVN server
Scene two, achieve the mirror, i.e. WEB server and SVN server as data source, change SVN any change in WEB the same, need – delete parameters
Scene three, does not need synchronization some subdirectories, there may be some directory is temporary garbage directory cache, or special directory (but not the style or typesetting) to use the exclude parameter
Note: the use of the parameters do not have to write an absolute path, as long as the directory name AA represents the file aa/ represents a directory, the disadvantage is that if there are multiple sub directory is the same name as the name would not be synchronized
Recommended - exclude-from=/home/svn/exclude.list in the form of documents can easily add and delete


Using SVN hooks can also write a lot of programs to control SVN code before being submitted to check whether a write log, whether there is tab, there will be replaced by spaces, are not allowed to upload files, is there more than limit the size of the file and so on.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Justin at December 09, 2013 - 10:19 AM