Directory
- Introduction
- Install
- SVN startup mode
-
- Method 1: Single database svnserve method
- Method 2: Multi-repository svnserve method
- SVN creates a repository
-
- 1.svn service configuration file svnserve.conf
- 2. Username and password file passwd
- 3. Permission configuration file
- 4. Multi-library operation
- SVN checkout operation
- SVN resolves conflicts
- SVN commit operation
- SVN version rollback
- SVN View historical information
-
- 1.svn log
- 2.svn diff
- 3.svncat
- 4.svn list
- SVN branch
- SVN tag
- authentication realm
- Cyrus SASL authentication
- Implementing Repository Hooks
- password generator
- Related Links
Introduction
svn can check out a single file, but git does not have this feature. Most companies use svn servers for document management, binary images, executable files and other publishing purposes.
Mainly refer to the book https://svnbook.red-bean.com/.
Installation
#Installation sudo apt install subversion #Check whether it is installed svn --version
SVN startup mode
#Manually create a new repository directory sudo mkdir -p /data/svn #Use svn command to create a repository svnadmin create /data/svn/company #Use the command svnserve to start the service svnserve -d -r /data/svn/company --listen-port 3690 #-r: The configuration method determines the repository access method #--listen-port: Specify the SVN listening port. Without this parameter, SVN listens to 3690 by default. #Due to the different configuration methods of -r, there are two different access methods when SVN is started.
Method 1: Single database svnserve method
-r is specified directly to the repository (called single-repository svnserve mode)
svnserve -d -r /data/svn/company
In this case, one svnserve can only work for one repository.
The configuration of repository permissions in the authz configuration file should be written as follows:
[groups] admin=user1 dev=user2 [/] @admin=rw user2=r
Use a URL similar to this: svn://192.168.0.1/ to access the runoob repository
Method 2: Multi-repository svnserve method
Specify the parent directory of the repository
svnserve -d -r /data/svn
In this case, one svnserve can work for multiple repositories
The configuration of repository permissions in the authz configuration file should be written as follows:
[groups] admin=user1 dev=user2 [runoob:/] @admin=rw user2=r [runoob01:/] @admin=rw user2=r
If you also use [/] at this time, it means the root directory of all libraries. Similarly, [/src] means the src directory under the root directory of all libraries.
Use a URL similar to this: svn://192.168.0.1/company to access the company repository.
SVN creates a repository
Use the svn command to create the repository:
svnadmin create /data/svn/company tree /data/svn/company/conf/ /data/svn/company/conf/ ├── authz ├── hooks-env.tmpl ├── passwd └── svnserve.conf
1.svn service configuration file svnserve.conf
This file only consists of a [general] configuration section. This file has been copied and can be viewed and read.
The main options are explained below:
[general] anon-access=none auth-access=write password-db=passwd authz-db = authz realm = tiku
### This file controls the configuration of the svnserve daemon, if you ### use it to allow access to this repository. (If you only allow ### access through http: and/or file: URLs, then this file is ### irrelevant.) ### Visit http://subversion.apache.org/ for more information. [general] ### The anon-access and auth-access options control access to the ### repository for unauthenticated (a.k.a. anonymous) users and ### authenticated users, respectively. ### Valid values are "write", "read", and "none". ### Setting the value to "none" prohibits both reading and writing; ### "read" allows read-only access, and "write" allows complete ### read/write access to the repository. ### The sample settings below are the defaults and specify that anonymous ### users have read-only access to the repository, while authenticated ### users have read and write access to the repository. anon-access=none auth-access=write ### The password-db option controls the location of the password ### database file. Unless you specify a path starting with a /, ### the file's location is relative to the directory containing ### this configuration file. ### If SASL is enabled (see below), this file will NOT be used. ### Uncomment the line below to use the default password file. password-db=passwd ### The authz-db option controls the location of the authorization ### rules for path-based access control. Unless you specify a path ### starting with a /, the file's location is relative to the ### directory containing this file. The specified path may be a ### repository relative URL (^/) or an absolute file:// URL to a text ### file in a Subversion repository. If you don't specify an authz-db, ### no path-based access control is done. ### Uncomment the line below to use the default authorization file. authz-db = authz ### The groups-db option controls the location of the file with the ### group definitions and allows maintaining groups separately from the ### authorization rules. The groups-db file is of the same format as the ### authz-db file and should contain a single [groups] section with the ### group definitions. If the option is enabled, the authz-db file cannot ### contain a [groups] section. Unless you specify a path starting with ### a /, the file's location is relative to the directory containing this ### file. The specified path may be a repository relative URL (^/) or an ### absolute file:// URL to a text file in a Subversion repository. ### This option is not being used by default. # groups-db = groups ### This option specifies the authentication realm of the repository. ### If two repositories have the same authentication realm, they should ### have the same password database, and vice versa. The default realm ### is repository's uuid. realm = jw ### The force-username-case option causes svnserve to case-normalize ### usernames before comparing them against the authorization rules in the ### authz-db file configured above. Valid values are "upper" (to upper- ### case the usernames), "lower" (to lowercase the usernames), and ### "none" (to compare usernames as-is without case conversion, which ### is the default behavior). # force-username-case = none ### The hooks-env options specifies a path to the hook script environment ### configuration file. This option overrides the per-repository default ### and can be used to configure the hook script environment for multiple ### repositories in a single file, if an absolute path is specified. ### Unless you specify an absolute path, the file's location is relative ### to the directory containing this file. # hooks-env = hooks-env [sasl] ### This option specifies whether you want to use the Cyrus SASL ### library for authentication. Default is false. ### Enabling this option requires svnserve to have been built with Cyrus ### SASL support; to check, run 'svnserve --version' and look for a line ### reading 'Cyrus SASL authentication is available.' use-sasl = false ### These options specify the desired strength of the security layer ### that you want SASL to provide. 0 means no encryption, 1 means ### integrity-checking only, values larger than 1 are correlated ### to the effective key length for encryption (e.g. 128 means 128-bit ### encryption). The values below are the defaults. # min-encryption = 0 # max-encryption = 256
2. Username and password file passwd
The username and password file is specified by the configuration item password-db of svnserve.conf and defaults to passwd in the conf directory. This file consists of only a [users] configuration section.
### This file is an example password file for svnserve. ### Its format is similar to that of svnserve.conf. As shown in the ### example below it contains one section labeled [users]. ### The name and password for each user follow, one account per line. [users] #harry = harryssecret username=123456
3. Permission configuration file
The permission configuration file is specified by the configuration item authz-db of svnserve.conf, and the default is authz in the conf directory. The configuration file consists of a [groups] configuration section and several repository path permission sections.
The configuration line format in the [groups] configuration section is as follows:
<user group> = <user list>
The segment name format of the repository path permission segment is as follows:
[<repository name>:<path>]
example
[groups] g_admin = admin, thinker [admintools:/] @g_admin = rw * = [test:/home/thinker] thinker = rw * = r
In the repository directory /data/svn/company/conf
, the default content is:
### 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 admin=username # [/foo/bar] # harry = rw #&joe = r # * = # [repository:/baz/fuz] # @harry_and_sally = rw # * = r [company:/] @admin = rw $authenticated=rw
4. Multi-library operation
svnserve -d -r /data/svn #address svn://106.15.109.116/company
SVN checkout operation
svn checkout svn://106.15.109.116/company --username=username
SVN conflict resolution
svn update svn update -r6 #edit svn commit -m "change HelloWorld.html second"
SVN commit operation
svn status svn add readme svn status svn commit -m "SVN readme." #edit svn commit
SVN version rollback
#edit svn status svn revert readme.md #Table of contents svn revert -R trunk
But what if we want to restore an already committed version.
To eliminate an old version, we must undo all changes in the old version and commit a new version. This operation is called reverse merge.
First, find the current version of the repository, which is now version 22. We want to undo back to the previous version, such as version 21.
svn merge -r 22:21 readme
SVN View historical information
1.svn log
Used to display the svn version author, date, path, etc.
#View information between two specific versions svn log -r 6:8 #View the version modification information of a certain file svn log trunk/HelloWorld.html #If you want to get directory information, add -v #If you want to display directory information limited to N records, use svn log -l N -v
2.svn diff
Used to display row-level details for a specific modification.
- Check local modifications
- Compare working copy to repository
- Compare repository to repository
#If you use svn diff without any parameters, it will compare your working file with the "original" copy cached in .svn svn diff #Compare working copy and repository svn diff -r 3 rule.txt #Compare version library with version library svn diff -r 2:3 rule.txt
3.svn cat
Gets a file at a specific version displayed on the current screen.
#If you just want to check a past version and don't want to see their differences, you can use svn cat svn cat -r version number rule.txt
4.svn list
Display files that exist in a directory or a certain version
#svn list You can view the files in the directory without downloading the files to the local directory: svn list svn://106.15.109.116/company
SVN branch
#Create a new branch svn copy trunk/ branches/my_branch #Submit the new branch to the repository svn commit -m "add my_branch" #Go to my_branch branch for development cd branches/my_branch/ #Switch to trunk, execute svn update, and then merge the my_branch branch into trunk svn merge ../branches/my_branch/ #Submit the merged trunk to the repository. svn commit -m "add index.html"
SVN tag
#Create tags svn copy trunk/ tags/v1.0 #submit tag svn commit -m "tags v1.0"
authentication realm
### This option specifies the authentication realm of the repository. ### If two repositories have the same authentication realm, they should ### have the same password database, and vice versa. The default realm ### is repository's uuid. # realm = My First Repository
If you want to share the password library file, the authentication realm must be the same
Cyrus SASL authentication
It takes too much time, so I won’t use it for the time being.
svn.conf in the directory where SASL plug-ins are located /usr/lib/sasl2/ /etc/sasl2/ /usr/lib/sasl2 /usr/lib/x86_64-linux-gnu/sasl2
pwcheck_method: auxprop auxprop_plugin: sasldb sasldb_path: /etc/my_sasldb mech_list: DIGEST-MD5
saslpasswd2 -c -f /etc/my_sasldb -u realm username
Implementing Repository Hooks
To implement submission, you must listen to comments
hooks/pre-commit
REPOS="$1" TXN="$2" # Make sure that the log message contains some text. SVNLOOK=/usr/bin/svnlook LOGMSG=`$SVNLOOK log -t $TXN $REPOS | wc -m` #echo $LOGMSG > /data/svn/company/hooks/test.txt #One Chinese character corresponds to 8 characters if [ "$LOGMSG" -lt 16 ];then echo "\\ Submission failed: Enter at least 2 Chinese characters or 16 English letters and numbers" 1> & amp;2 exit 1 fi # Exit on all errors. set -e # All checks passed, so allow the commit. exit 0
Password Generator
Due to the built-in authentication method, users cannot change their passwords. Please ask the administrator when adding users. The administrator can use the password generator to generate multiple passwords at one time.
sudo apt install pwgen pwgen
Related links
SVN tutorial
SVN official website
Github SVN source code
Building SVN service on Linux server
sasl certification