使用 svnsync 做 svn 的代码备份

1. 备份主机操作

  1. cd /data/svn
  2. vim pre-revprop-change
  3. #!/bin/sh
  4. USER="$3"
  5. if [ "$USER"="svnsync" ];then
  6. exit 0
  7. fi
  8. echo "Only the svnsync user may change revision properties as this is a read-only, mirror repository." >&2
  9. exit 1
  10. chmod +x pre-revprop-change
  1. cd /data/svn
  2. vim start-commit
  3. #!/bin/sh
  4. USER="$2"
  5. if [ "$USER"="svnsync" ]; then
  6. exit 0
  7. fi
  8. echo "Only the svnsync user may commit new revisions as this is a read-only, mirror repository." >&2
  9. exit 1
  10. chmod +x start-commit
  1. cd /data/svn
  2. cat > authz <<EOF
  3. [/]
  4. svnsync=rw
  5. EOF
  6. cat > passwd <<EOF
  7. [users]
  8. svnsync=svnsync
  9. EOF
  10. cat > svnserve.conf <<EOF
  11. [general]
  12. anon-access = none
  13. auth-access = write
  14. password-db = /data/svn/passwd
  15. authz-db = /data/svn/authz
  16. EOF
  17. svnadmin create SVN_REPO
  18. cp pre-revprop-change start-commit SVN_REPO/hooks
  19. cp svnserver.conf SVN_REPO/conf/

2. svn 主机

  1. # 初始化
  2. svnsync initialize svn://192.168.2.22/test file:///data/svn/ttt --username=svnsync --password=svnsync
  3. # svnsync initialize URL_MIRROR_REPO URL_MASTER_REPO --username=svnsync --password=svnsyncpassword
  4. # 同步
  5. svnsync synchronize svn://192.168.2.22/test --username=svnsync --password=svnsync
  6. # svnsync synchronize URL_TO_MIRROR_REPO --username=svnsync --password=passwd

创建一个钩子,自动同步

  1. vim hooks/post-commit
  2. #!/bin/bash
  3. /usr/bin/svnsync sync svn://192.168.2.22/test --username=svnsync --password=svnsync &
  4. exit 0
  5. chmod +x hooks/post-commit