Bullying one-World charging series [SVN centralized version management system]

Source: Internet
Author: User
Tags svn client svn update rsync version control system tortoisesvn

SVN centralized version management system

--Bullying One World rechargeable series

One, SVN server


1. What is SVN

SVN (Subversion) is a platform-based, open-source version control system. Manage various data changes over time. SVN backs up and records every change in each file, so that we can restore the files of any point in time to an older version of the one you want.


2. SVN and Git

SVN is a centralized management, there is a central repository, all developers in the local development of all the code used by the repository, the commit code must also be submitted to the central repository.

The SVN version control system flow is as follows:

1. Create or copy a branch from the trunk on the Central Library.

2. From the Central Library checkout this branch code.

3. Add your own code files, modify the existing code, or delete the code files.

4.commit code, assuming someone commits the code on just the branch, you'll be prompted for the code to expire, and you'll have to get the code up before you commit. Up code if there is a conflict, you need to resolve the conflict before committing.


Disadvantages:

If you are unable to connect to the central repository, you cannot submit code, add code to version control, view the historical version of the Code, and the version change process. Because the code base is centrally managed, you need to make a backup of the storage for the central repository. SVN backup to back up all code data and all changed version records.


Git

Distributed versioning, developed by Linus, is tightly coupled with all the natural git and Linux file systems so that you have to use Cygwin on Windows to make it work perfectly.

What does Git call a distributed version control system? Let's start with the mode of work.

There's no central repository in git, but for the development team's code share, we usually build a remote git repository. But unlike SVN, the developer also contains a full git repository, in a way that local warehouses and remote warehouses are equivalent in identity, without the master and slave points.

If your project is a closed-source project, or if you are used to the centralized management model of the past, then you can work in git like SVN, but there may be some steps in the process.

1) You create a git repository locally and add it to the remote Git repository.

2) You add or delete files locally, then commit, and of course the Conmmit action is committed to the local git repository. (It is actually submitted to the GIT directory in the objects directory)

3) Push the branch of the local git repository to the branch of the remote Git repository, if the remote Git repository has already been push by someone else, then the remote git library will not allow your push, you need to pull first, then if there is conflict, handle the conflict, Commit to the local git repository after the push to the remote git library.


Advantages:

You can also do versioning (similar to a standalone repository) locally without linking to a remote git server.


3. SVN Server run mode

1) Standalone server access

Access address such as: Svn://svn.xxx.com/sadoc;

2) with HTTP services such as Apache

Access address such as: Http://svn.xxx.com/sadoc;

A. Install APACHE+SVN separately

B, Csvn (APACHE+SVN) is a separate integrated software, with the Web interface management of SVN software.

3) Local direct access (how to access the SVN server locally)

Access address: File://application/svndata/sadoc;


4, the installation of SVN

For SVN installation, there is no special requirement, so you can install it directly from Yum.

[Email protected] ~]# uname-rm2.6.32-573.el6.x86_64 x86_64[[email protected] ~]# Rpm-qa subversionsubversion-1.6.11-15.el6_7.x86_64 if not: Yum install-y subversion


5. Configure SVN

To be able to manage SVN uniformly, we created the data and passwd folders separately

[Email protected] ~]# mkdir-p/home/svndata[[email protected] ~]# mkdir-p/home/svnpasswd

Start SVN service

[[email protected] conf]# svnserve -d -r / home/svndata/[[email protected] conf]# ps -ef|grep svnroot      22266     1  0 17:27 ?         00:00:00 svnserve -d -r /home/svndata/root     22268  22241  0 17:27 pts/6    00:00:00 grep svn[[email  protected] conf]# netstat -lntup|grep svntcp         0      0 0.0.0.0:3690                 0.0.0.0:*                    LISTEN       22266/svnserve 

Build the project repository, the project can create multiple, here just create a demo,

Svnadmin Create/home/svndata/sadoc (not available mkdir, because it requires SVN to initialize a lot of things) can be added--fs-type arg to specify the file format.

Modifying a configuration file

[[Email protected] conf]# diff svnserve.conf svnserve.conf.bak 12,13c12,13< anon-access = none#--> Disable Anonymous access < auth-access = Write #--? turn on Write permission---> # anon-access = read> # auth-access = write20c20< password-db =/home/svnpasswd  /PASSWD # Change directory to central management directory---> # password-db = passwd27c27< authz-db =/home/svnpasswd/authz # change directory to central managed directory---> # Authz-db = Authz

Create user

[[email protected] ~]# cp passwd authz /home/svnpasswd/[[email protected]  ~]# cd /home/svnpasswd/[[email protected] ~]# chmod 700 *[[email  protected] svnpasswd]# vi passwd ### 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 labelled [users].### the name and password  for each user follow, one account per line. [users]# harry = harryssecret# sally = sallyssecretqishi = qishi123     #--> Add a user linzhiling = linzhiling    #--> and add another * * You need to restart SVN when changing svnserve.conf, and you do not need to restart SVN when changing Authz and passwd.

Empowering

[[Email protected] svnpasswd]# VI Authz # # # # This file was an example authorization file for svnserve.### ====== intermediate comment slightly ======= ===### Grant Read (' R ') access, read-write (' RW ') access, or no Accesssagroup = Qishi,linzhiling[sadoc:/]qishi = RW #添加的用户 Must exist in the passwd. linzhiling = R@sagroup = R #添加的组要先创建.


Permission format:

User group format:

[Groups], where one user group can contain one or more users, separated by commas between users.

Repository directory format:

[< Repository >:/project/catalog]

@< user Group > = < permissions >

< user name > = < permissions >

Inside, the box number can be written in several ways:

[/], which indicates the root directory and the following, the root directory is specified at svnserve startup, and we specify as/home/svndata,[/] is the permission that is set for all repository settings.

[repos:/] means setting permissions for the repository repos;

[Repos:/sadoc] means setting permissions on Sadoc items in the repository repos;

[Repos:/sadoc/qishi] means setting permissions on the Qishi directory of Sadoc items in the repository repos;

The permissions topic allows users groups, users, or *, user groups to be preceded by @,* to represent all users.

Permissions can be W, R, WR, and NULL, which means no permissions.


6. Reboot after configuration

[Email protected] ~]# pkill svnserve[[email protected] ~]# svnserve-d-r/home/svndata/


Two, SVN client software


SVN under Windows

1, under Windows SVN: https://sourceforge.net/projects/tortoisesvn/files/1.9.3/Application/ tortoisesvn-1.9.3.27038-x64-svn-1.9.3.msi/download?accel_key=61%3a1459244639%3ahttps%253a//tortoisesvn.net/ Downloads.html%3a4b3a10d0%2434eeb3e5542aaed1d228cff451468585f45b0026&click_id= C32ead50-f592-11e5-bb77-0200ac1d1d9c-1&source=accel

2. Install SVN

Windows next next.

3. Configure the link svn

1) Create a directory

2) right mouse button Select directory, click to select "SVN checkout (k) ..."

3) Fill in the following information on the popup dialog box, complete the SVN link and complete the download of the vault to local.

Svn://xxx.xxx.xxx.xxx/sadoc

User:qishi

Password:qishi123

4) Use:%appdata%\subversion\auth can view three sub-directories to save authentication information.

5) SVN color corresponding to the operation:

Blue: Submit a change

Purple: Submit a new item

Crimson: Commit a Delete or replace

Black: All Other Items

6) Other actions under Windows Skip here First, so easy.


Client Management under Linux

Usage: Svn<subcommand>[opthins][args] < subcommands >[options [parameters]

Some common commands

Checkout (CO)//Remove a copy of the working version from the repository. List (LS) [--verbose]//view file [show more details]cat svn://xxx.txt//View file Contents commit (CI)// Commits changes to the current working copy. There is a possibility that code conflicts are present in this place. Update (UP)//updates. SVN--help View All commands

Check out, update, commit of code under Linux

SVN co svn://xxx.xxx.xxx.xxx/sadoc/mnt/svndata--username=qishi--password=qishi123 # #发现已经将代码下载下来svn Update svn://xxx . xxx.xxx.xxx/sadoc/mnt/svndata--username=qishi--password=qishi123 # #发现已经将刚刚上传的代码更新过来了. Tip: If you encounter can ' t convert string from ' utf-8 ' to native encoding problem is because the code contains Chinese, need to do a character set adjustment: Export Lc_ctype= ' en_US. UTF-8 ' export lc_all= problem solved. SVN add 111.txtsvn commit-m "This is Test" 111.txt # # #提交文件.

Common error

Tip: If you encounter can ' t convert string from ' utf-8 ' to native encoding problem is because the code contains Chinese, need to do a character set adjustment:

Export Lc_ctype= ' en_US. UTF-8 ' Export lc_all= #--> problem resolution.

Local access on the SVN server

SVN Co file:///home/svndata/sadoc


Third, SVN advanced


1, the SVN directory structure planning

Svn:

Branch Branch, for testing purposes, more than a few days of the project must open branches, testing needs to pass, the main line is merged into the branch through, in order to merge into the main line for testing.

Tag version Record uses

Trunk Mainline, with the official line corresponding to the day of the non-online file is not allowed to submit.


1) Create trunk, branch, Tag directory and import SVN server

Mkdir-p/svn/trunk/svn/branch/svn/tagsvn import/svn file:///home/svndata-m "Import"


2) Copy the trunk to the branch under Linux.

SVN copy svn://127.0.0.1/sadoc/trunk svn://127.0.0.1/sadoc/branch/branch_cms110329-m "Create a branch by Qishi modifiy" --username= ' Qishi '--password=qishi123


2. SVN hooks


SVN hooks are programs that are triggered by certain repository events, such as creating a new version or modifying a property that is not versioned.


The hooks under each item has a hook directory, which is removed. The. tmpl extension is available.


Tip: For security reasons, the Subversion repository executes the hook script in an empty environment--there is no environment variable, not even $path or%path%. For this reason, many administrators will be confused that their hook scripts are run normally and can not be run in subsersion. Be aware that you must set the environment variables in your hooks to work out the absolute path for your program.


Common Hook Scripts:


1. Post-commit executes the hook after the commit has completed a successful build, the commit is completed and cannot be changed, so the return value of this script is ignored and the commit is triggered when it is completed.

2. Pre-commit triggers execution of the script before the commit is completed.

3, Start-commit before the client has submitted data to the server, there is also the establishment of subsersion Transaciton execution script.


Very useful:

Pre-revprop-change Before modifying the Revison property

Post-revprop-change after modifying the Revison property

Pre-unlock before unlocking a file

Post-unlock after the file is unlocked

Pre-lock before the file is locked

Post-lock after the file is locked



Production Environment Application:


1, the use of Pre-commit limit file extension and size, control the submission of information to be entered and so on.


2, Post-commit

SVN update automatically known, MSN, e-mail or SMS known, triggering checkout program, and then real-time rsync push to the server and so on.


Case one: rsync and SVN hooks combine to achieve real-time synchronization of data in a small business case

1, create the Site directory mkdir/home/wwwdata2, sync code SVN co svn://127.0.0.1/sadoc/home/wwwdata--username=qishi--password=qishi123

* * Write Hook Script focus: 1, environment variable 2, full path


3, write the hook code

#vim post-commit#!/bin/shrepos= "$" rev= "$" en_us "Export lc_ctype=". UTF-8 "Export lc_all=logpath="/mnt/log "[!-D ${logpath}] && mkdir ${logpath}-p#update content from svnsvn=/usr/b IN/SVN$SVN update--username=qishi--password=qishi123/home/wwwdataif [$?-eq 0]then/usr/bin/rsync-az--delete/home /wwwdata//TMP/SVNRSYNCFI


Attention:

1, give the executive permission, chmod Post-commit

2. Note Defining environment variables

3. Use full path as far as possible

4, before SVN update must be manually checkout first, because the first execution needs to do a yes and other confirmation operation.


Case two: Limit svn upload size, extension, and message length via SVN hooks

#!/bin/shrepos= "$" txn= "$" #此处更改大小限制, here is 5mmax_size=5242880# here to increase the limit file suffix name filter= ' \. (zip|rar|o|obj|tar|gz) $ ' # make sure that the log message contains some  text. Svnlook=/usr/bin/svnlooklogmsg= ' $SVNLOOK  log -t  $TXN   $REPOS |wc -c ' if [  "$LOGMSG"   -lt 9 ]thenecho -e  "Nlog message cann ' t be empty!  you must input more than 8 chars as comment! "  1>$2exit 1fifiles=$ ($SVNLOOK  changed -t  $TXN   $REPOS  |cut -d  "   " -f 4-" rc=0echo  "$files"  |while read f;do#check file typeif  echo  $f |tr a-z a-z|grep -eq  $FILTER;thenecho  "file  $f  is  Not allow ($FILTER)  file " 1>$2exit 1;fi#check file sizefilesize= ' $SVNLOOK  cat -t  $TXN   $REPOS   $f  |wc -c ' if [  "$filesize  -gt " $MAX _size " ];thenecho " file  $f  is  too large (must <= $MAX _size)  b " 1>&2exit 1fidone# all checks  passed, so allow the commit.if [ $? -eq 1 ];thenexit  1elseexit 0 fi

Four, the code on-line program and matters needing attention


# #上线思想:

1. Intranet test Environment-beta environment-formal environment

2, the principle affects the user experience minimum

3, the code first upload to the temporary directory, and then the MV way past, because the MV process is very short (PHP code does not need to restart the HTTP service).

4, as far as possible by operation and maintenance personnel management on-line, for the function of the code, developers are more concerned about the performance optimization of the code and the stability of the server after the launch, operation and maintenance more care, therefore, if the site outage problems attributed to the operation of the pipe, it is necessary to let operations control on-line more scientific. Otherwise, the development of random updates, out of the problem of operational responsibility, this is wrong.

5, on-line backup before the problem in time to roll back.

6, can take the first line of the general application server, Test no problem on the other half.


# #代码上线方案注意事项:

1, on-line process, Office test Environment-->IDC Test environment and the formal production environment, all the software in all environments should be version unified, second, should be as simple as possible, the side will endless, development test success, IDC testing may also have problems.

2, the development Team Group Office Internal Test Environment test (the test environment is maintained by the development team, or automatically update the code), the code has problems returned to a developer to re-develop.

3, there is a special test engineer, the program has a problem directly back to the developer, (at this time, the general procedure to return the bug, known as the Bug Library), do not question the IDC test.

4, the IDC test by the tester and operations personnel involved, called Idctest, to carry out the process of stress testing, there are problems directly back to the developer, no problems online environment online.

5, several server code distribution on-line scenario Example (Java program)

1) Assume that the same business Server has six, the server is divided into a, b two groups, a group of three, Group B three, first to a from the load balancer smooth offline, B group to provide services, to avoid the server due to the impact of the business.

2) The downline process is kicked out of a group a server from the RS pool (LVS,NGINX,HAPROXY,F5, etc.) through a script to prevent the load balancer from distributing the request to the Group a server (at this time it should be a few days for website traffic, usually at night)

3) Distribute the code to the Group a server's site directory, the group a server on-line and restart the service, and by a dedicated test personnel to access the test, test success, hang on a group of servers, the offline Group B server, B set of code on-line operation test and so on and a group of the same, period to observe the server status Have problems in time to roll back.

6, Special Note: If it is a PHP program, the line can be simplified, directly to the code (the best full amount) published to all on-line server specific directory, after the distribution is completed, a one-time MV or LN to the site directory, of course, testing, test, in addition to personnel testing, there are various test supervision of each relevant business interface

7, most of the front page of the portal has been static or cache, therefore, the dynamic part of the visit usually will not be particularly much, the flow of underestimated when the better, plus is smooth up and down the line, so basically no impact on the user experience, of course, there are problems on the line, this is not to avoid.

8, SVN contains code and configuration.


Five, reference on-line structure diagram

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/7E/3D/wKioL1b6ZaaBI7i4AAErVVSMMKQ015.png "title=" Dai (2) . png "alt=" Wkiol1b6zaabi7i4aaervvsmmkq015.png "/>

This article is from the "Cheat One World de blog" blog, please be sure to keep this source http://qiyishi.blog.51cto.com/5731577/1758131

Bullying one-World charging series [SVN centralized version management system]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.