Author |
Topic: How to Install SVN Server on Ubuntu 16.04 LTS |
|
Linux member offline |
|
posts: |
120 |
joined: |
01/24/2011 |
from: |
San Jose, CA |
|
|
|
|
|
How to Install SVN Server on Ubuntu 16.04 LTS |
Introduction Subversion is an open source (written in C) version control system. It helps you keep track of a collection of files and folders. Any time you change, add or delete a file or folder that you manage with Subversion, you commit these changes to your Subversion repository, which creates a new revision in your repository reflecting these changes. You can always go back, look at and get the contents of previous revisions.
Prerequisites Apache web server
|
|
|
|
|
|
|
Linux member offline |
|
posts: |
120 |
joined: |
01/24/2011 |
from: |
San Jose, CA |
|
|
|
|
|
Install Subversion |
First, the subversion packages and their dependencies:
$ sudo apt-get install subversion libapache2-mod-svn libapache2-svn libsvn-dev
Check the version
$ svn --version
svn, version 1.9.3 (r1718519)
compiled Aug 10 2017, 16:59:15 on x86_64-pc-linux-gnu
Copyright (C) 2015 The Apache Software Foundation.
|
|
|
|
|
|
|
Linux member offline |
|
posts: |
120 |
joined: |
01/24/2011 |
from: |
San Jose, CA |
|
|
|
|
|
Create SVN repository and users |
Repository xyz:
$ sudo mkdir -p /var/lib/svn/
$ sudo svnadmin create /var/lib/svn/xyz <-- create repository named 'xyz'
$ sudo chown -R www-data:www-data /var/lib/svn <-- change owner
$ sudo chmod -R 775 /var/lib/svn
Users
$ sudo htpasswd -cm /etc/apache2/dav_svn.passwd admin <-- admin
$ sudo htpasswd -m /etc/apache2/dav_svn.passwd user1 <-- user1
$ sudo htpasswd -m /etc/apache2/dav_svn.passwd user2 <-- user2
|
|
|
|
|
|
|
Linux member offline |
|
posts: |
120 |
joined: |
01/24/2011 |
from: |
San Jose, CA |
|
|
|
|
|
Configure Apache with Subversion |
First enable the required Apache modules
$ sudo a2enmod dav
$ sudo a2enmod dav_svn
$ sudo nano /etc/apache2/mods-enabled/dav_svn.conf
<Location /svn>
DAV svn
SVNParentPath /var/lib/svn
AuthType Basic
AuthName "Subversion Repository"
AuthUserFile /etc/apache2/dav_svn.passwd
Require valid-user
</Location>
Restart Apache
$ sudo systemctl restart apache2
or
$ sudo service apache2 restart
Now you should be able to access from browser by:
http://10.11.12.13/svn/xyz/
|
|
|
|
|
|
|
Linux member offline |
|
posts: |
120 |
joined: |
01/24/2011 |
from: |
San Jose, CA |
|
|
|
|
|
SVN default structure |
Conventionally, every Subversion project has trunk, tags, and branches directories directly under the repository's root directory.
| /svn/xyz
| -- [+] trunk
| ------- [+] projects
| ----------- [+] project#1
| ----------- [+] project#2
| -- [+] branches
| ------- [+] 1.0
| ----------- [+] projects
| --------------- [+] project#1
| --------------- [+] project#2
| ------- [+] 1.1
| ----------- [+] projects
| --------------- [+] project#1
| --------------- [+] project#2
| ------- [+] 2.0
| ----------- [+] projects
| --------------- [+] project#1
| --------------- [+] project#2
| -- [+] tags
| ------- [+] 1.0.0
| ----------- [+] projects
| --------------- [+] project#1
| --------------- [+] project#2
| ------- [+] 1.0.1
| ----------- [+] projects
| --------------- [+] project#1
| --------------- [+] project#2
| ------- [+] 1.1.0
| ----------- [+] projects
| --------------- [+] project#1
| --------------- [+] project#2
| ------- [+] 1.1.1
| ----------- [+] projects
| --------------- [+] project#1
| --------------- [+] project#2
| ------- [+] 2.0.0
| ----------- [+] projects
| --------------- [+] project#1
| --------------- [+] project#2
The trunk is a directory where all the main development happens and is usually checked out by the developers to work on the project. The branches directory is used when you want to pursue different routes of development. The tags directory is used to store snapshots of the project for production release.
Populate the reposiory with the above empty structure:
$ sudo mkdir /tmp/svn-template
$ sudo mkdir /tmp/svn-template/trunk
$ sudo mkdir /tmp/svn-template/branches
$ sudo mkdir /tmp/svn-template/tags
$ sudo svn import -m 'Create trunk, branches, tags directory structure' /tmp/svn-template/ http://localhost/svn/xyz --username=admin
Then the 'projects' container:
$ sudo mkdir /tmp/svn-template/trunk/projects
$ sudo svn import -m 'Create projects directory under trunk' /tmp/svn-template/trunk http://localhost/svn/xyz/trunk --username=admin
Finally a specific project (a mvn project stored under /opt/maven/hello-one):
$ sudo mkdir /tmp/svn-template/trunk/projects/hello-one
$ sudo cp -R /opt/maven/hello-one /tmp/svn-template/trunk/projects/
$ sudo svn import -m 'Create project directory' /tmp/svn-template/trunk/projects/ http://localhost/svn/xyz/trunk/projects/ --username=admin
|
|
|
|
|
|
|
Linux member offline |
|
posts: |
120 |
joined: |
01/24/2011 |
from: |
San Jose, CA |
|
|
|
|
|
How to undo SVN IMPORT |
Instead of importing:
sudo svn import -m 'Initial Upload' /tmp/svn-container/ http://localhost/svn/xyz/trunk/projects/ --username=admin
I did:
sudo svn import -m 'Initial Upload' /tmp/svn-container/project-name/ http://localhost/svn/xyz/trunk/projects/ --username=admin
As you can see, the version (let say 26) after import is messed up by missing the project folder "project-name" which should hold all files and sub-directories inside itself.
Here is how to undo this version:
$ cd /tmp
$ sudo svnadmin dump /var/lib/svn/xyz/ --revision 0:25 > dump.db <-- assume that the messed-up version is 26
$ sudo mv /var/lib/svn/xyz /var/lib/svn/xyzbk
$ sudo svnadmin create /var/lib/svn/xyz <-- create repository named 'xyz' again
$ sudo chown -R www-data:www-data /var/lib/svn <-- change owner for http://localhost/svn
$ sudo chmod -R 775 /var/lib/svn
$ sudo svnadmin load /var/lib/svn/xyz < dump.db <-- load back all versions until the last one
$ sudo rm -R dump.db
$ sudo rm -R /var/lib/svn/xyzbk
|
|
|
|
|
|
|