Svnsync synchronizes and backs up svn version libraries. Everyone knows that code is a life for the entire IT company. Most small and medium-sized companies use svn for version control due to personnel level issues, therefore, version database backup of svn is crucial. Here I will introduce svnsync to implement version Database Synchronization of svn, in addition, the master database whose process is scripted and needs to be synchronized from www.2cto.com is located on server A (192.168.1.1) and access control is implemented based on apache, configure the nine version libraries test [1-9] in the root directory. Use the http protocol to access the image version library on server B (192.168.1.2) and perform access control based on apache, use http protocol for Access Authorization Access Control because the master library and Image Library are using libapache2-svn module for access control, so we first need to provide a svn detection user, this user has read and write permissions for all versions of the database on server A and server B. Assume that the user detected by svn is: [html] -- username root- -Password root: Create the target version database www.2cto.com to create the version database. image server B must create A version database with the same name as master server, in this way, you can use the svnadmin create command to create a version database and modify the pre-revprop-change source code of the target database [html] #! /Bin/bash 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 script read if the svn: log attribute is modified, 0 is returned, and modification is allowed.-1 is returned for other attributes. We do not want to modify all attributes of the version library. Therefore, we need this script to return 0 successfully, therefore, you need to change exit-1 to exit 0 and then modify the code [html] #! /Bin/bash 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 0 implementation script (bash) [html] #! /Bin/bash # variable definition svnstorage = ("test1" "test2" "test3" "test4" "test5" "test6" "test7" "test8" "test9 ") svndir = "/srv/svn" if [! -D $ svndir]; then mkdir-p $ svndir chown-R www-data.www-data $ svndir fi # cyclically create the target repository for svn in $ {svnstorage [*]} do # delete an existing svn repository if [- d $ svndir/$ svn]; then rm-r $ svndir/$ svn fi # create the target version library svnadmin create $ svndir/$ svn # modify pre-revprop-change cp $ svndir/$ svn/hooks/pre-revprop-change.tmpl $ svndir/$ svn/hooks/pre-revprop-change chmod + x $ svndir/$ svn/hooks/pre-revprop-change sed-I "s/exit 1/exit 0/ g "$ s Vndir/$ svn/hooks/pre-revprop-change # modify the version database owner (svn is accessed through the http protocol through apache, so the owner is www-data) chown-R www-data.www-data $ svndir/$ svn done initialization & synchronize initialization command initialization, establish the synchronization relationship between the target database and the source database [html] svnsync initialize target database URL source database URL synchronization Command [html] svnsync synchronize target database URL implementation script in order to synchronize the image version Library, therefore, the username and password that can access the version database on server A and server B are written in the script as variables [html] #! /Bin/bash # variable definition svnstorage = ("test1" "test2" "test3") svndir = "/srv/svn" if [! -D $ svndir]; then mkdir-p $ svndir chown-R www-data.www-data $ svndir fi # cyclically create the target repository for svn in $ {svnstorage [*]} do # delete an existing svn repository if [- d $ svndir/$ svn]; then rm-r $ svndir/$ svn fi # create the target version library svnadmin create $ svndir/$ svn # modify pre-revprop-change cp $ svndir/$ svn/hooks/pre-revprop-change.tmpl $ svndir/$ svn/hooks/pre-revprop-change chmod + x $ svndir/$ svn/hooks/pre-revprop-change sed-I "s/exit 1/exit 0/ g "$ s Vndir/$ svn/hooks/pre-revprop-change # modify repository attributes chown-R www-data.www-data $ svndir/$ svn done # initialize & Sync target repository localip = "192.168.1.2" remoteip = "192.168.1.1" username = "root" password = "root" for svn in $ {svnstorage [*]} do # initialize svnsync initialize http: // $ localip/svn/$ svn http: // $ remoteip/svn/$ svn -- username $ username -- password $ password # synchronize if [$? -Eq 0]; then svnsync synchronize http: // $ localip/svn/$ svn -- username $ username -- password $ password fi done: the requirement for synchronous update on the backup storage is as follows: Take the test1 database of server A as an example. If someone submits code to test1, the corresponding image version library test1 of server B needs to synchronously update the post-commit hook to automatically synchronize the following code in the post-commit script under the hooks directory of the source database test1 of server: [html] SVNSYNC =/usr/bin/svnsync $ SVNSYNC sync -- non-interactive http: // target database URI -- username root -- password root www.2cto.com image version database and source database UUID consistency problem through svnlook to check whether the image version library and source database uuid are consistent, if not, you can use the following methods: view the source database uuid [html] svnlook uuid $ svn_path update the image database uuid [html] sudo svnadmin setuuid $ svn_path $ source database uuid view the updated image database uuid [html] svnlook uuid $ svn_path update svn submit address to image version library Command [html] svn switch -- relocate http: // oldcheckpath http: // newcheckpath source http://blog.csdn.net/zinss26914/article/details/8601458