{"id":341,"date":"2016-11-15T22:08:28","date_gmt":"2016-11-15T14:08:28","guid":{"rendered":"https:\/\/blog.haostudio.net\/hwp\/?p=341"},"modified":"2017-07-25T00:00:56","modified_gmt":"2017-07-24T16:00:56","slug":"%e4%bd%bf%e7%94%a8svn-sync-%e4%be%86%e5%90%8c%e6%ad%a5%e5%85%a9%e5%80%8b-repository","status":"publish","type":"post","link":"https:\/\/blog.haostudio.net\/hwp\/%e4%bd%bf%e7%94%a8svn-sync-%e4%be%86%e5%90%8c%e6%ad%a5%e5%85%a9%e5%80%8b-repository\/","title":{"rendered":"\u4f7f\u7528SVN sync \u4f86\u540c\u6b65\u5169\u500b Repository"},"content":{"rendered":"<!--more-->\n<h2>\u4f7f\u7528SVN sync \u4f86\u540c\u6b65\u5169\u500b Repository<\/h2>\n<hr \/>\n<h3>\u7de3\u7531:<\/h3>\n<p>\u6700\u8fd1\u6211\u5c07 SVN server \u8f49\u79fb\u5230 ARM \u7684\u958b\u767c\u7248\u4e0a, \u4f46\u662f\u53c8\u64d4\u5fc3\u9019\u677f\u5b50\u4e0aSSD \u58de\u6389, \u65bc\u662f\u958b\u59cb\u601d\u8003\u8cc7\u6599\u5099\u4efd\u7684\u554f\u984c. \u4e0a\u7db2\u627e\u4e86\u4e00\u4e0b, \u6c7a\u5b9a\u63a1\u7528 svn sync \u65b9\u5f0f, \u4f86\u505a\u8cc7\u6599\u7684\u5373\u6642\u93e1\u50cf\u5099\u4efd.\n\u56e0\u6b64\u9700\u8981\u984d\u5916\u518d\u52a0\u4e00\u584a ARM \u958b\u767c\u7248\u4f86\u653e\u93e1\u50cf\u7684\u8cc7\u6599.<\/p>\n<h3>\u74b0\u5883<\/h3>\n<p>\u6211\u7684\u5be6\u4f5c\u74b0\u5883\u5982\u4e0b:<\/p>\n<pre><code># lsb_release -a\nNo LSB modules are available.\nDistributor ID: Debian\nDescription:    Debian GNU\/Linux 8.6 (jessie)\nRelease:    8.6\nCodename:   jessie\n\n1. uname -sorm\nLinux 3.14.79-odroidc2 aarch64 GNU\/Linux\n<\/code><\/pre>\n<h3>\u5be6\u4f5c\u6d41\u7a0b :<\/h3>\n<p>\u6211\u5011\u5c07\u539f\u4f86\u4f7f\u7528\u4e2d\u7684SVN server\u7a31\u70bamaster, \u93e1\u50cf\u7684server \u70baslave.<\/p>\n<h4>Slave \u76f8\u95dc\u8a2d\u5b9a<\/h4>\n<p>\u9996\u5148\u5b89\u88dd svn \u76f8\u95dc\u5957\u4ef6<\/p>\n<pre><code># apt-get install subversion\n<\/code><\/pre>\n<p>\u6211\u5011\u9700\u5148\u5efa\u7acb\u4e00\u500b\u65b0\u7684SVN Repository \u7576\u4f5cslave server.\u6ce8\u610f, \u4ed6\u5fc5\u9808\u662f\u7a7a\u7684, \u4e0d\u80fd\u5c0d\u5b83\u505a\u4efb\u4f55commit.<\/p>\n<pre><code># svnadmin create \/svn_slave\/myrepo\n<\/code><\/pre>\n<p>\u4e26\u4e14\u65b0\u589e\u4e00\u500bSVN \u5e33\u865f\u5c08\u9580\u505a sync \u7528\u9014, \u6bd4\u5982\u53eb\u505a\n<code>mysvnsync<\/code><\/p>\n<p>\u5efa\u7acb\u5e33\u865f\u7bc4\u4f8b\u5982\u4e0b<\/p>\n<pre><code># cat &lt;&lt; EOF &gt; \/svn_slave\/myrepo\/conf\/authz\n [repos:\/]\n mysvnsync = rw\n * = \nEOF\n<\/code><\/pre>\n<p>\u5efa\u7acb\u5bc6\u78bc\u7bc4\u4f8b\u5982\u4e0b<\/p>\n<pre><code># htpasswd -c \/svn_slave\/myrepo\/conf\/passwd mysvnsync\n<\/code><\/pre>\n<p>\u5728\n<code>\/svn_slave\/myrepo\/hooks<\/code>\u76ee\u9304\u4e2d, \u65b0\u589e2\u500b hook\u7a0b\u5f0f, \u5206\u5225\u662f\u662f<code>start-commit<\/code> \u4ee5\u53ca <code>pre-revprop-change<\/code> \u4f86\u6aa2\u67e5 SVN sync \u6642\u7684\u5e33\u865f<\/p>\n<p><code>start-commit<\/code> \u5167\u5bb9\u7bc4\u4f8b\u5982\u4e0b<\/p>\n<pre><code># cat &lt;&lt; EOF &gt; \/svn_slave\/myrepo\/hooks\/start-commit\n\n  #!\/bin\/bash\n\n  set -e\n  REPOS=&quot;$1&quot;\n  USER=&quot;$2&quot;\n\n  1.   1. ALLOW_USERS=&quot;user1 user2 user3&quot;\n  1.   ALLOW_USERS=&quot;mysvnsync&quot;\n\n  1.   1. Check USER account\n  1.   found=0\n  for i in $ALLOW_USERS\n  do\n    if [[ &quot;$USER&quot; == &quot;$i&quot; ]]; then\n      found=1\n      break\n    fi\n  done\n\n  if [[ $found == 0 ]]; then\n     echo &quot;The &#039;${USER}&#039; is not allowed to commit new revisions&quot; &gt;&amp;2\n     exit 1\n  fi\n\n  1. All checks passed, so allow the commit.\n  exit 0\nEOF\n<\/code><\/pre>\n<p><code>pre-revprop-change<\/code> \u5167\u5bb9\u7bc4\u4f8b\u5982\u4e0b<\/p>\n<pre><code># cat &lt;&lt; EOF &gt; \/svn_slave\/myrepo\/hooks\/pre-revprop-change\n\n  #!\/bin\/bash\n\n  REPOS=&quot;$1&quot;\n  REV=&quot;$2&quot;\n  USER=&quot;$3&quot;\n  PROPNAME=&quot;$4&quot;\n  ACTION=&quot;$5&quot;\n\n  1.   1. ALLOW_USERS=&quot;user1 user2 user3&quot;\n  1.   ALLOW_USERS=&quot;mysvnsync&quot;\n\n  1.   1. Check USER account\n  1.   found=0\n  for i in $ALLOW_USERS\n  do\n    if [[ &quot;$USER&quot; == &quot;$i&quot; ]]; then\n      found=1\n      break\n    fi\n  done\n\n  if [[ $found == 0 ]]; then\n     echo &quot;The &#039;${USER}&#039; is not allowed to change revision properties&quot; &gt;&amp;2\n     exit 1\n  fi\n  exit 0\nEOF\n<\/code><\/pre>\n<p>\u5c07\u6b64\u5169\u500b\u7a0b\u5f0f\u8a2d\u5b9a\u70ba\u53ef\u57f7\u884c<\/p>\n<pre><code># chmod +x \/svn_slave\/myrepo\/hooks\/start-commit\n1. chmod +x \/svn_slave\/myrepo\/hooks\/pre-revprop-change\n<\/code><\/pre>\n<p>\u7531\u65bc\u6211\u7684SVN server \u662f\u4f7f\u7528 http \u7684 \u65b9\u5f0f\u4f86\u9023\u63a5, \u6240\u4ee5\u9084\u9700\u8981 apache \u76f8\u95dc\u8a2d\u5b9a, \u81f3\u65bcapache \u76f8\u95dc\u8a2d\u5b9a, \u4ee5\u4e0b\u50c5\u4f9b\u53c3\u8003, \u6bcf\u500b\u4eba\u7684\u9700\u6c42\u4e0d\u4e00\u5b9a\u76f8\u540c.<\/p>\n<p>\u9996\u5148\u5b89\u88dd apache \u76f8\u95dc\u5957\u4ef6<\/p>\n<pre><code># apt-get install apache2 libapache2-svn\n<\/code><\/pre>\n<p>\u9996\u5148\u5c07\n<code>\/svn_slave<\/code> \u6539\u70baapache \u53ef\u5b58\u53d6<\/p>\n<pre><code># chown -R www-data:www-data \/svn_slave\n<\/code><\/pre>\n<p>\u5047\u8a2d\u9019\u500bSVN slave \u7684\u4f4d\u5740\u662f\n<code>&lt;a href=&quot;http:\/\/san_slave.domain.name&quot;&gt;http:\/\/san_slave.domain.name&lt;\/a&gt;<\/code>, \u4fee\u6539 <code>\/etc\/apache2\/sites-enabled\/000-default.conf<\/code> \u5982\u4e0b<\/p>\n<pre><code>&lt;VirtualHost *:80&gt;\n    ServerAdmin your_email@com\n    ServerName svn_slave.domain.name\n\n    DocumentRoot \/svn_slave\/myrepo\n\n    &lt;Location \/&gt;\n       DAV svn\n       SVNParentPath     \/svn_slave\/myrepo\n       SVNListParentPath on\n\n       AuthType Basic\n       AuthName &quot;Authorization Realm&quot;\n       AuthzSVNAccessFile \/svn_slave\/myrepo\/conf\/authz\n       AuthUserFile \/svn_slave\/myrepo\/conf\/passwd\n       Require valid-user\n   &lt;\/Location&gt;\n\n    &lt;Directory \/svn_slave\/myrepo&gt;\n        #AllowOverride None\n        AllowOverride All\n\n        &lt;IfVersion &gt;= 2.4&gt;\n          Require all granted\n        &lt;\/IfVersion&gt;\n        &lt;IfVersion &lt; 2.4&gt;\n          Order deny,allow\n          Allow from all\n        &lt;\/IfVersion&gt;\n    &lt;\/Directory&gt;\n\n    ErrorLog ${APACHE_LOG_DIR}\/error.log\nCustomLog ${APACHE_LOG_DIR}\/access.log combined\n\n&lt;\/VirtualHost&gt;\n<\/code><\/pre>\n<p>\u91cd\u65b0\u555f\u52d5\n<code>apache<\/code><\/p>\n<pre><code># \/etc\/init.d\/apache2 restart\n<\/code><\/pre>\n<p>\u4ee5\u4e0a, SVN slave \u7684\u8a2d\u5b9a\u5df2\u7d93\u5b8c\u6210.<\/p>\n<p>\u4f7f\u7528\n<code>&lt;a href=&quot;http:\/\/svn_slave.domain.name&quot;&gt;http:\/\/svn_slave.domain.name&lt;\/a&gt;<\/code> \u5c31\u53ef\u4ee5\u67e5\u770b subversion repository \u662f\u5426\u8a2d\u7f6e\u6210\u529f<\/p>\n<h4>Master \u76f8\u95dc\u8a2d\u5b9a<\/h4>\n<p>\u6211\u7684 SVN Master \u7aef\u65e9\u5c31\u5df2\u7d93\u4f7f\u7528\u5f88\u4e45\u4e86, \u6709\u8a31\u591a\u8cc7\u6599\u90fd\u5df2\u7d93\u5b58\u653e\u5728 repository \u88e1\u9762\u4e86. \u57fa\u672c\u4e0a\u4e0d\u9700\u8981\u505a\u4efb\u4f55\u8a2d\u5b9a.<\/p>\n<p>\u53ea\u662f\u82e5\u8981\u548cSVN slave \u540c\u6b65, \u5247\u9700\u8981\u505a\u4e00\u6b21 init \u7684\u52d5\u4f5c.<\/p>\n<p>\u5047\u8a2d\u6211\u7684SVN master \u7684\u4f4d\u5740\u662f\n<code>&lt;a href=&quot;http:\/\/svn_master.domain.name&quot;&gt;http:\/\/svn_master.domain.name&lt;\/a&gt;<\/code> \u6307\u4ee4\u5982\u4e0b:<\/p>\n<pre><code># svnsync init --sync-username  mysvnsync --sync-password  slave_password http:\/\/svn_slave.domain.name  --source-username my_svn_account  --source-password http:\/\/svn_master.domain.name\n<\/code><\/pre>\n<p>\u4e0a\u8ff0\u7684\u5e33\u865f, \u5bc6\u78bc, \u4ee5\u53cahttp \u7684\u4f4d\u5740\u8acb\u81ea\u884c\u4fee\u6539\u6210\u7b26\u5408\u4f60\u81ea\u5df1\u7684\u503c. \u9019\u500b init \u7684\u52d5\u4f5c\u6703\u5728SVN slave \u5beb\u5165\u4e00\u4e9b\u521d\u59cb\u53c3\u6578, \u9019\u500b\u52d5\u4f5c\u53ea\u9700\u505a\u904e\u4e00\u6b21\u5c31\u53ef\u4ee5\u4e86.<\/p>\n<h4>\u958b\u59cb\u540c\u6b65\u8cc7\u6599<\/h4>\n<p>\u63a5\u4e0b\u4f86\u5c31\u662f\u8981\u540c\u6b65\u8cc7\u6599\u5566, \u9019\u53ef\u4ee5\u6709\u5169\u7a2e\u65b9\u5f0f.<\/p>\n<p>\u4e00\u662f\u624b\u52d5\u4e0b\u6307\u4ee4\u540c\u6b65. \u5982\u4e0b:<\/p>\n<pre><code># svnsync sync --sync-username  mysvnsync --sync-password  slave_password http:\/\/svn_slave.domain.name  --source-username my_svn_account  --source-password http:\/\/svn_master.domain.name\n<\/code><\/pre>\n<p>\u8ddf\u4e0a\u9762\u7684\u6307\u4ee4\u5e7e\u4e4e\u4e00\u6a21\u4e00\u6a23, \u53ea\u662f\u628a\n<code>init<\/code> \u6539\u70ba <code>sync<\/code> \u5373\u53ef. \u4f60\u53ef\u4ee5\u628a\u9019\u500b\u6307\u4ee4\u52a0\u5165\u5230 <code>crontab<\/code> \u88e1\u9762, \u8b93\u5b83\u5b9a\u6642\u81ea\u52d5\u57f7\u884c\u5373\u53ef.<\/p>\n<p>\u7b2c\u4e8c\u7a2e\u65b9\u5f0f\u662f, \u6bcf\u6b21\u5c0dSVN master commit \u6642, \u81ea\u52d5\u540c\u6b65\u5230 SVN slave \u4e2d. \u9019\u7a2e\u65b9\u5f0f\u9700\u8981\u4fee\u6539 SVN master \u88e1\u9762\n<code>\/svn_master\/myrepo\/hooks<\/code> \u76ee\u9304\u4e2d\u7684\u5169\u500b hook \u7a0b\u5f0f.\n\u5206\u5225\u662f\n<code>post-commit<\/code> \u53ca <code>post-revprop-change<\/code>.<\/p>\n<p><code>post-commit<\/code> \u5167\u5bb9\u7bc4\u4f8b\u5982\u4e0b<\/p>\n<pre><code># cat &lt;&lt; EOF &gt; \/svn_master\/myrepo\/hooks\/post-commit\n\n  #!\/bin\/bash\n\n  set -e\n  REPOS=&quot;$1&quot;\n  REV=&quot;$2&quot;\n  TXN_NAME=&quot;$3&quot;\n\n  1.   1. Automatic sync to mirror site\n  1.   SVNSYNC=\/usr\/bin\/svnsync\n  TO=http:\/\/svn_slave.domain.com\n  SYNC_USER=mysvnsync\n  SYNC_PASS=password_for_sync\n  SOURCE_USER=my_svn_account\n  SOURCE_PASS=my_svn_password\n\n  $SVNSYNC --non-interactive sync $TO \\\n  --sync-username $SYNC_USER --sync-password $SYNC_PASS \\\n  --source-username $SOURCE_USER --source-password $SOURCE_PASS &amp;\n\n  exit 0\nEOF\n<\/code><\/pre>\n<p><code>post-revprop-change<\/code> \u5167\u5bb9\u7bc4\u4f8b\u5982\u4e0b<\/p>\n<pre><code># cat &lt;&lt; EOF &gt; \/svn_master\/myrepo\/hooks\/post-revprop-change\n\n  #!\/bin\/bash\n\n  set -e\n  REPOS=&quot;$1&quot;\n  REV=&quot;$2&quot;\n  USER=&quot;$3&quot;\n  PROPNAME=&quot;$4&quot;\n  ACTION=&quot;$5&quot;\n\n  1.   1. Automatic sync to mirror site\n  1.   SVNSYNC=\/usr\/bin\/svnsync\n  TO=http:\/\/svn_slave.domain.com\n  SYNC_USER=mysvnsync\n  SYNC_PASS=password_for_sync\n  SOURCE_USER=my_svn_account\n  SOURCE_PASS=my_svn_password\n\n  $SVNSYNC --non-interactive copy-revprops $TO \\\n  --sync-username $SYNC_USER --sync-password $SYNC_PASS \\\n  --source-username $SOURCE_USER --source-password $SOURCE_PASS &amp;\n\n  exit 0\nEOF\n<\/code><\/pre>\n<p>\u5c07\u6b64\u5169\u500b\u7a0b\u5f0f\u8a2d\u5b9a\u70ba\u53ef\u57f7\u884c<\/p>\n<pre><code># chmod +x \/svn_master\/myrepo\/hooks\/post-commit\n1. chmod +x \/svn_master\/myrepo\/hooks\/post-revprop-change\n<\/code><\/pre>\n<p>\u5b8c\u6210\u4e4b\u5f8c, \u4ee5\u5f8c\u6bcf\u6b21\u5c0d\u65bcSVN master commit, \u5247\n<code>post-commit<\/code> \u9019\u500bhook \u7a0b\u5f0f\u5c31\u6703\u81ea\u52d5\u57f7\u884c, \u7136\u5f8c\u5c0dSVN slave \u505a sync \u52d5\u4f5c\u4e86.<\/p>\n<hr \/>\n<h3>\u53c3\u8003\u8cc7\u6599<\/h3>\n<ol>\n<li><a href=\"http:\/\/www.zawmin.com\/blog\/?p=216\">\u7528svnsync \u505amirror repository<\/a><\/li>\n<li><a href=\"http:\/\/www.cardinalpath.com\/how-to-use-svnsync-to-create-a-mirror-backup-of-your-subversion-repository\/\">HOW TO USE SVNSYNC TO CREATE A MIRROR BACKUP OF YOUR SUBVERSION REPOSITORY<\/a><\/li>\n<li><a href=\"http:\/\/svnbook.red-bean.com\/en\/1.6\/svn.ref.svnsync.html\">svnsync\u2014Subversion Repository Mirroring<\/a><\/li>\n<li><a href=\"http:\/\/blog.xuite.net\/happyman\/tips\/16769572-svnsync+%E5%81%9A+svn+repository+%E7%9A%84%E5%96%AE%E5%90%91%E5%82%99%E4%BB%BD\">svnsync \u505a svn repository \u7684\u55ae\u5411\u5099\u4efd<\/a><\/li>\n<\/ol>","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[93,12],"tags":[94],"class_list":["post-341","post","type-post","status-publish","format-standard","hentry","category-subversion","category-12","tag-svn"],"_links":{"self":[{"href":"https:\/\/blog.haostudio.net\/hwp\/wp-json\/wp\/v2\/posts\/341","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.haostudio.net\/hwp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.haostudio.net\/hwp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.haostudio.net\/hwp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.haostudio.net\/hwp\/wp-json\/wp\/v2\/comments?post=341"}],"version-history":[{"count":5,"href":"https:\/\/blog.haostudio.net\/hwp\/wp-json\/wp\/v2\/posts\/341\/revisions"}],"predecessor-version":[{"id":374,"href":"https:\/\/blog.haostudio.net\/hwp\/wp-json\/wp\/v2\/posts\/341\/revisions\/374"}],"wp:attachment":[{"href":"https:\/\/blog.haostudio.net\/hwp\/wp-json\/wp\/v2\/media?parent=341"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.haostudio.net\/hwp\/wp-json\/wp\/v2\/categories?post=341"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.haostudio.net\/hwp\/wp-json\/wp\/v2\/tags?post=341"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}