SVN - The Previous-Generation Version Control System

Apache Subversion (SVN or svn for short) is an open source version control system. Compared to RCS and CVS, it adopts a branch management system, and its design goal was to replace CVS. More and more version control services on the internet have migrated from CVS to Subversion.

Single Repository vs. Multiple Repositories

If your projects are related and might need to share data, it’s recommended to use a single svn repository — code can easily be copied and moved between two projects, and the operation history is preserved. [1]

If projects are completely unrelated and could never need to share data, it’s better to create several independent, completely separate repositories, for easier security management.

Configuring a Single Repository SVN

Creating the SVN repository directory

Create the directory: mkdir -p ../repository

Create the svn repository: svnadmin create ../repository

Under ../repository you’ll see files such as conf, db, format, hooks, locks, README.txt, etc., indicating an SVN repository has been created.

Modifying the main configuration

vi ../repository/conf/svnserve.conf

Change the contents to:

[general]

anon-access = none

auth-access = write

Configuring which svn users are allowed access

vi ../repository/conf/pwd

The file format is as follows:

[users]

=

=

Here, [users] is required. Below it, list the users who should have access to svn, one user per line.

Example:

[users]

alan = password

king = hello

Configuring svn user access permissions

vi ../repository/conf/authz

User groups:

[groups]

group_a = user1,user2 group_b = user3,user4

Repository directory:

[/directory]

@group = permission

user = permission

Prefix a group name with @; * means all users.

Permissions can be w, r, wr, or empty; empty means no permissions at all.

Example:

[groups]
harry_and_sally = harry,sally
harry_sally_and_joe = harry,sally,&joe
[/] #表示版本库根目录
harry = rw
[/目录] #表示版本库根目录下的目录
@harry_and_sally = rw

Note: changes to the user configuration file take effect immediately, without needing to restart svn. Usernames appearing in the permissions configuration file must already be defined in the user configuration file. Changes to the permissions configuration file also take effect immediately, without needing to restart svn

Starting a single-repository svn

svnserve -d -r ../repository

-d means run in daemon mode (in the background); the startup path points to the repository’s location, so on the SVN client you can access it directly via svn://ip-address.

Configuring a Multi-Repository SVN

Unlike a single-repository svn, a multi-repository svn requires creating multiple repositories, and each repository’s configuration file needs to be modified individually. Most of the configuration is the same as for a single-repository svn, so it won’t be repeated here — what needs attention is configuring svn user access permissions and the startup method.

Configuring multi-repository svn user access permissions

vi ../repository*/conf/authz #each repository needs to be configured individually

User groups:

[groups]

group_a = user1,user2

group_b = user3,user4

Repository directory:

[repository:/directory]

@group = permission

user = permission

Prefix a group name with @; * means all users.

Permissions can be w, r, wr, or empty; empty means no permissions at all.

Example:

[groups]
harry_and_sally = harry,sally
harry_sally_and_joe = harry,sally,&joe
[repository*:/] #表示版本库根目录
harry = rw
[repository*:/目录] #表示版本库根目录下的目录
@harry_and_sally = rw

Starting a multi-repository svn

svnserve -d -r ../

-d means run in daemon mode (in the background); the startup path should not point to a repository, but to the level above all repositories — on the SVN client you need to access svn://ip-address/repository to reach a specific repository

Backup and Restore

Backup

svnadmin dump ../repository > *.dump

or

svnadmin hotcopy ../repository > PATH

Restore

svnadmin load ../repository < *.dump

Mirroring

svn does not support distributed development, so keeping an svn repository on a single server is not safe

# 创建版本库
svnadmin create PATH
# 创建钩子
cp PATH/hooks/pre-revprop-change.tmpl PATH/hooks/pre-revprop-change
# 编辑pre-revprop-change钩子,将最后一行的 `exit 1` 改为 `exit 0`
vi waukeen/hooks/pre-revprop-change
# 给予钩子运行权限
chmod +x PATH/hooks/pre-revprop-change
# 为与另一个版本库的同步初始化目标版本库
svnsync init file:///PATH svn://SOURCE_URL
# 进行同步
svnsync sync file:///PATH

References