使用 svnsync 做 svn 的代码备份
1. 备份主机操作
cd /data/svn
vim pre-revprop-change
#!/bin/sh
USER="$3"
if [ "$USER"="svnsync" ];then
exit 0
fi
echo "Only the svnsync user may change revision properties as this is a read-only, mirror repository." >&2
exit 1
chmod +x pre-revprop-change
cd /data/svn
vim start-commit
#!/bin/sh
USER="$2"
if [ "$USER"="svnsync" ]; then
exit 0
fi
echo "Only the svnsync user may commit new revisions as this is a read-only, mirror repository." >&2
exit 1
chmod +x start-commit
cd /data/svn
cat > authz <<EOF
[/]
svnsync=rw
EOF
cat > passwd <<EOF
[users]
svnsync=svnsync
EOF
cat > svnserve.conf <<EOF
[general]
anon-access = none
auth-access = write
password-db = /data/svn/passwd
authz-db = /data/svn/authz
EOF
svnadmin create SVN_REPO
cp pre-revprop-change start-commit SVN_REPO/hooks
cp svnserver.conf SVN_REPO/conf/
2. svn 主机
# 初始化
svnsync initialize svn://192.168.2.22/test file:///data/svn/ttt --username=svnsync --password=svnsync
# svnsync initialize URL_MIRROR_REPO URL_MASTER_REPO --username=svnsync --password=svnsyncpassword
# 同步
svnsync synchronize svn://192.168.2.22/test --username=svnsync --password=svnsync
# svnsync synchronize URL_TO_MIRROR_REPO --username=svnsync --password=passwd
创建一个钩子,自动同步
vim hooks/post-commit
#!/bin/bash
/usr/bin/svnsync sync svn://192.168.2.22/test --username=svnsync --password=svnsync &
exit 0
chmod +x hooks/post-commit