SVN 常用命令

OS : Ubuntu20.04

安装工具:

sudo apt update  
sudo apt install subversion  

 创建仓库:

mkdir -p /srv/svn/myrepo
svnadmin create /srv/svn/myrepo

配置svn仓库:

conf/svnserve.conf  配置为如下:

➜ conf cat svnserve.conf | grep -v "#"

[general]
anon-access = none
auth-access = write
password-db = passwd
authz-db = authz

[sasl]

设置用户和密码:

conf/passwd 中添加用户信息:

➜  conf cat passwd | grep -v "#"

[users]  
user1 = password1  
user2 = password2  
user3 = password3

conf/authz 中配置权限(文件结构如下):

tree myrepo
myrepo
├── test1
│   ├── test1-1
│   └── test1-2
└── test2
➜  conf cat authz
### This file is an example authorization file for svnserve.
### Its format is identical to that of mod_authz_svn authorization
### files.
### As shown below each section defines authorizations for the path and
### (optional) repository specified by the section name.
### The authorizations follow. An authorization line can refer to:
###  - a single user,
###  - a group of users defined in a special [groups] section,
###  - an alias defined in a special [aliases] section,
###  - all authenticated users, using the '$authenticated' token,
###  - only anonymous users, using the '$anonymous' token,
###  - anyone, using the '*' wildcard.
###
### A match can be inverted by prefixing the rule with '~'. Rules can
### grant read ('r') access, read-write ('rw') access, or no access
### ('').

[aliases]
# joe = /C=XZ/ST=Dessert/L=Snake City/O=Snake Oil, Ltd./OU=Research Institute/CN=Joe Average

[groups]
# harry_and_sally = harry,sally
# harry_sally_and_joe = harry,sally,&joe
# ------------------------------------------ 定义组
# ----------------------------------按用户角色分配 user_own
= user2, user3 admin_own = user1 # [/foo/bar] # harry = rw # &joe = r # * = # [repository:/baz/fuz] # @harry_and_sally = rw # * = r # ------------------------------------- 分配权限 [myrepo:/] #-------------------------------给用户组分配只读权限,给管理员组分配读写权限 @user_own = r @admin_own = rw
# --------------------------------配置为用户组可读写 [myrepo:
/test1/test1-1] @user_own = rw

# -----------------------------------取消用户组的读写权限,保留管理员组的读写权限 [myrepo:
/test2] @user_own =

配置回调钩子,使svn log属性可修改

➜  myrepo cat hooks/pre-revprop-change
#!/bin/sh

# PRE-REVPROP-CHANGE HOOK
#
# The pre-revprop-change hook is invoked before a revision property
# is added, modified or deleted.  Subversion runs this hook by invoking
# a program (script, executable, binary, etc.) named 'pre-revprop-change'
# (for which this file is a template), with the following ordered
# arguments:
#
#   [1] REPOS-PATH   (the path to this repository)
#   [2] REV          (the revision being tweaked)
#   [3] USER         (the username of the person tweaking the property)
#   [4] PROPNAME     (the property being set on the revision)
#   [5] ACTION       (the property is being 'A'dded, 'M'odified, or 'D'eleted)
#
#   [STDIN] PROPVAL  ** the new property value is passed via STDIN.
#
# If the hook program exits with success, the propchange happens; but
# if it exits with failure (non-zero), the propchange doesn't happen.
# The hook program can use the 'svnlook' utility to examine the
# existing value of the revision property.
#
# WARNING: unlike other hooks, this hook MUST exist for revision
# properties to be changed.  If the hook does not exist, Subversion
# will behave as if the hook were present, but failed.  The reason
# for this is that revision properties are UNVERSIONED, meaning that
# a successful propchange is destructive;  the old value is gone
# forever.  We recommend the hook back up the old value somewhere.
#
# The default working directory for the invocation is undefined, so
# the program should set one explicitly if it cares.
#
# On a Unix system, the normal procedure is to have 'pre-revprop-change'
# invoke other programs to do the real work, though it may do the
# work itself too.
#
# Note that 'pre-revprop-change' must be executable by the user(s) who will
# invoke it (typically the user httpd runs as), and that user must
# have filesystem-level permission to access the repository.
#
# On a Windows system, you should name the hook program
# 'pre-revprop-change.bat' or 'pre-revprop-change.exe',
# but the basic idea is the same.
#
# The hook program runs in an empty environment, unless the server is
# explicitly configured otherwise.  For example, a common problem is for
# the PATH environment variable to not be set to its usual value, so
# that subprograms fail to launch unless invoked via absolute path.
# If you're having unexpected problems with a hook program, the
# culprit may be unusual (or missing) environment variables.
#
# CAUTION:
# For security reasons, you MUST always properly quote arguments when
# you use them, as those arguments could contain whitespace or other
# problematic characters. Additionally, you should delimit the list
# of options with "--" before passing the arguments, so malicious
# clients cannot bootleg unexpected options to the commands your
# script aims to execute.
# For similar reasons, you should also add a trailing @ to URLs which
# are passed to SVN commands accepting URLs with peg revisions.
#
# Here is an example hook script, for a Unix /bin/sh interpreter.
# For more examples and pre-written hooks, see those in
# /usr/share/subversion/hook-scripts, and in the repository at
# http://svn.apache.org/repos/asf/subversion/trunk/tools/hook-scripts/ and
# http://svn.apache.org/repos/asf/subversion/trunk/contrib/hook-scripts/


REPOS="$1"
REV="$2"
USER="$3"
PROPNAME="$4"
ACTION="$5"

if [ "$ACTION" = "M" -a "$PROPNAME" = "svn:log" ]; then exit 0; fi

echo "Changing revision properties other than svn:log is prohibited" >&2
exit 1

启动 SVN 服务(同时保持log):

svnserve -d -r /srv/svn --log-file /var/log/svnserve.log

外部访问 SVN 仓库:

svn ls svn://<serverip>/myrepo

 二、SVN 仓库迁移

在源服务器上创建转储文件
cd /srv/svn/
svnadmin dump /srv/svn/myrepo > myrepo.dump
将转储文件复制到目标服务器
在目标服务器上创建新的仓库
svnadmin create /srv/svn/newrepo  
在目标服务器上加载转储文件
svnadmin load /srv/svn/newrepo < /path/to/destination/myrepo.dump  

修改配置文件(如果需要)

在新的仓库中,你可能需要调整配置文件,例如 svnserve.conf 和 passwd 文件,以便于用户权限的管理。如按上述步骤调整即可

在目标服务器上启动 SVN 服务器

svnserve -d -r /srv/svn

验证历史记录

svn log svn://target_server/newrepo  
posted @ 2024-12-31 10:15  丶Future  阅读(139)  评论(0)    收藏  举报