Install, configure, and hook the SVN server in ubuntu

Source: Internet
Author: User
Tags svn update

SVN Server Installation configuration and hooks in ubuntu 1. SVN installation 1. installation Package 1. $ sudo apt-get install subversion2. create a project directory $ sudo mkdir/home/xiaozhe/svn $ cd/home/xiaozhe/svn/$ sudo mkdir mypro 3. create an svn File Repository $ sudo svnadmin create/home/xiaozhe/svn/mypro 4. import the project to the svn file Repository (optional) $ sudo svn import-m "" your folder path file: // home/xiaozhe/svn/mypro 5. modify the access permission settings in the/home/xiaozhe/svn/mypro/conf directory: svnserve. conf and passwd files. spaces are not allowed at the front of the line to edit svnserve. conf file, uncomment the following line, and need Top grid anon-access = readauth-access = write password-db = passwd edit passwd as follows: [users] andy = andy 6. enable svnserve and enable it in the SVN root directory: $ svnserve-d-r/home/xiaozhe/svn 7. check whether the instance is started normally. $ netstat-ntlp indicates that the instance is successfully started (if Apache is used for connection, skip the next step. local Area Network Access. Check the SVN repository file svn checkout svn: // SvnIp address/mypro or abbreviation: svn co svn: // SvnIp address/mypro 2. Use Apache in Ubuntu to configure Subversion 1. install necessary software $ sudo apt-get install subversion libapache2-svn apa Che22. modify apache configuration file/etc/apache2/mod-available/logs <Location/svn/mypro> DAV svnSVNPath/home/xiaozhe/svn/myproAuthType BasicAuthName "myproject subversion repository" AuthUserFile/ etc/subversion/passwd # <limit0000t get propfind options report> Require valid-user # </limit0000t> </Location> if you need to verify the user password each time you log on, comment out the two lines <limitaskt get propfind options report> and </limitcontactt>. When you add the preceding content, you must restart the Apache 2 Web server. Enter the following command: $ sudo/etc/init. d/apache2 restart 3. create a/etc/subversion/passwd file that contains user authorization details $ sudo htpasswd-c/etc/subversion/passwd user_name it will prompt you to enter the password, when you enter the password, this user is created. The "-c" option indicates creating a new/etc/subversion/passwd file. Therefore, user_name indicates that the user is the only user in the file. To add other users, remove the "-c" option: $ sudo htpasswd/etc/subversion/passwd other_user_name4. you can use the following command to access the File Repository: $ svn co http: // hostname/svn/myproject -- username user_name or use the browser: http: // hostname/svn/myproject 3. ubuntu SVN command Daquan 1. Run the file checkout to the local directory svn checkout path (path is the directory on the server) for example: $ svn checkout svn: // 192.168.1.1/pro Abbreviation: $ svn co svn: // 192.168.1.1/pro 2. add a new file to the version library $ svnadd file $ svn add test. php (add test. ph P) $ svn add *. php (add all php files in the current directory) 3. Submit the modified file to the version library $ svn commit-m "LogMessage" [-N] [-- no-unlock] PATH (if the lock is selected, use the-no-unlock switch. for example, $ svn commit-m' add test file for my test' test. php Abbreviation: $ svn ci 4. update to a certain version $ svn update-rm path for example: $ svn update if there is no directory after, by default, all files in the current directory and subdirectory are updated to the latest version. $ Svn update-r 200 test. php (restore the file test. php In the version library to version 200) $ svn update test. php (update, which is synchronized in the version library. If the message "expired" is displayed at the time of submission, it is because of a conflict. update the file, modify the file, clear $ svn resolved, and submit the file "commit: svn up 5. delete the file $ svn delete path-m'delete test fle' For example: $ svn delete test. php and then $ svn ci-m'delete test file' Abbreviation: svn (del, remove, rm) 6. Differences $ svn diff path (compare the modified file with the basic version) for example: $ svn diff test. php $ svn diff-r m: n path (for version m and version n are different) for example: svn diff-r 200:201 test. php Abbreviation: svn di 7. view the file or directory status 1) svn status path (the status of the files and subdirectories under the directory, the normal status is not displayed) 【?: Not under svn control; M: The content is modified; C: A conflict occurs; A: It is scheduled to be added to the version Library; K: it is locked.] 2) svn status-v path (display file and subdirectory status) the first column remains the same, the second column shows the working version number, and the third and fourth columns show the last modified version number and modifier. Note: svn status, svn diff, and svn revert commands can be executed without a network, because svn is locally deployed. svn retains the original copy of the local version. Abbreviation: svn st 8. Conflict Resolution $ svn resolved: "Conflict" Status of directories or files that remove working copies. Usage: $ resolved PATH... Note: subcommands do not follow the syntax to resolve conflicts or remove conflicting tags. They only remove conflicting files and then allow the PATH to be submitted again. 4. Synchronously update the [Hook] synchronization program idea: the user submits the program to SVN, SVN triggers hooks, and processes it according to different hooks. Here post-commit is used, use post-commit to check the code to the local hard disk directory of the SVN server, and then synchronize it to the remote WEB server through rsync. Knowledge point: 1. SVN hooks # start-commit trigger transaction before commit # pre-commit trigger transaction before commit is complete # post-commit trigger transaction when commit is complete # pre-revprop-change Attribute Modification previously triggered transactions # After modifying the post-revprop-change attribute, the transaction will be triggered through the scripts written with these names to implement multiple functions, very powerful. 2. Use the specific parameters of the synchronization command rsync. 3. Use bash python perl with the programming capability of the base language to implement post-commit script file Editing: sudo vim/home/xiaozhe/svn/mypro/hooks/post-commit Note: After post-commit is edited, run: $ sudo chmod 755 post-commit :#! /Bin/shexport LANG = zh_CN.UTF-8sudo/usr/bin/svn update/var/www/myblog -- username xiaozhe -- password xiaozhe or more complex synchronous updates # Set variableSVN =/usr/bin/ svnWEB =/home/test_nokia/RSYNC =/usr/bin/rsyncLOG =/tmp/rsync_test_nokia.logWEBIP = "192.168.0.23" export LANG = en_US.UTF-8 # update the code from the SVN $ SVN update $ WEB -- username user -- password # If the previous command completed successfully, to contin Ue the followingif [$? = 0] then echo ""> $ LOG echo 'date'> $ LOG echo "################## ########### "> $ LOG chown-R nobody: nobody/home/test_nokia/# Synchronization code from the SVN server to the WEB server, notes: by the key $ RSYNC-vaztpH -- timeout = 90 -- exclude-from =/home/svn/exclude. list $ WEB root @ $ WEBIP:/www/> $ LOGfi and above are specific post-commit program considerations: 1. Be sure to define variables, it mainly refers to the path of used commands. Because of the security concerns of SVN, the system variables are not called. IF Manual execution is normal, but SVN Automatic Execution will fail. 2. Before SVN update, you must manually checkout it out, and here you must add users and passwords. If the password is only updated manually, it will not work automatically. 3. added the judgment on the previous command. If a problem occurs during update and the program does not exit, the code will continue to be synchronized to the WEB server, this will cause code problems. 4. Remember to set the owner because rsync can synchronize file attributes, and our WEB servers are generally not root users, if the user is incorrect, the WEB program cannot work properly. 5. It is recommended that you record the logs. If an error occurs, you can quickly troubleshoot the error. 6. In the final and most critical data synchronization, the relevant parameters of rsync must be clear. Note: In this scenario, the SVN server and the WEB server define the SVN server as the source server and the target server. Scenario 1. If the target WEB server is a comprehensive mix, for example, if there is only one static WEB resource, the automatically generated resources submitted by the user are all in the same directory of the WEB. We recommend that you do not use the-delete parameter above this program, the solution is to update and add the source server to the target server without deleting the server. The content of the WEB server is more than that of the source SVN server. Scenario 2. Implement the image, that is, the data of the target WEB server is the same as that of the source SVN server. If any changes on SVN are the same as those on the WEB, the-delete parameter scenario is required. 3. Some subdirectories do not need to be synchronized, some directories may be cached temporary junk directories, or dedicated image directories (instead of style or layout) must use the exclude parameter. Note: you do not need to write absolute paths for this parameter, as long as the directory name is used, aa represents the file aa/Represents the directory, but the disadvantage is that if multiple subdirectories are the same name, these names will not be recommended for synchronization-e Xclude-from =/home/svn/exclude. list can be used to conveniently add and delete exclude. list. svn /. DS_Storeimages/a svn Hook can also be used to write many programs to control SVN. For example, check whether logs are written and whether tabs exist before code submission. If any, replace them with spaces, whether there are files that cannot be uploaded, whether there are files that exceed the size limit, and so on.

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.