yum install subversion / apt install subversion/home/svn(建議獨立分區/磁碟)svn(建議專用帳號,非 root)mkdir -p /home/svn
chown svn:svn /home/svn
cd /home/svn
svnadmin create ityizhan
chown -R svn:svn ityizhan
cd ityizhan/conf
# 編輯 passwd
cat > passwd <<'EOF'
[users]
ituser = itpassword
dev1 = devpass123
admin = adminpass456
EOF
# 設定權限檔案 authz
cat > authz <<'EOF'
[groups]
ityizhan = ituser, dev1
admins = admin
[ityizhan:/]
@ityizhan = rw
@admins = rw
* = r # 匿名唯讀(可選,建議 = 禁止)
EOF
cat > svnserve.conf <<'EOF'
[general]
anon-access = none # 匿名不可讀
auth-access = write # 認證用戶可寫
password-db = passwd
authz-db = authz
realm = iTyiZhan SVN Repository
EOF
# 前台測試
svnserve -d -r /home/svn
# 背景常駐(生產環境建議用 systemd)
# 建立 /etc/systemd/system/svnserve.service
[Unit]
Description=Subversion Server
After=network.target
[Service]
Type=forking
User=svn
Group=svn
ExecStart=/usr/bin/svnserve -d -r /home/svn
ExecStop=/usr/bin/killall svnserve
Restart=on-failure
[Install]
WantedBy=multi-user.target
# 啟用
systemctl daemon-reload
systemctl enable --now svnserve
# 檢出
svn checkout svn://server_ip/ityizhan --username ituser
# 提交測試
cd ityizhan
echo "test" > test.txt
svn add test.txt
svn commit -m "initial commit"
# hooks/post-commit
#!/bin/bash
REPOS="$1"
REV="$2"
/usr/share/subversion/hook-scripts/commit-email.pl "$REPOS" "$REV" -h smtp.example.com dev-team@example.com
記得 chmod +x hooks/post-commit
# 熱備份(不鎖定倉庫)
svnadmin hotcopy /home/svn/ityizhan /backup/svn/ityizhan-$(date +%F)
# 增量備份腳本(每日)
svnadmin dump /home/svn/ityizhan -r {$(date -d yesterday +%F)}:HEAD --incremental | gzip > /backup/svn/ityizhan-inc-$(date +%F).dump.gz
# 完整遷移
svnadmin dump /home/svn/ityizhan > full.dmp
svnadmin load /new/path/ityizhan < full.dmp
# 格式升級
svnadmin upgrade /home/svn/ityizhan
[project:/] 控制整個專案[project:/trunk/src] 精細控制模組存取[groups] 定義角色,授權引用群組而非個人| 錯誤 | 原因 | 解決 |
|---|---|---|
| Authorization failed | authz 規則不匹配、大小寫敏感 | 檢查 authz 路徑大小寫、群組名拼寫 |
| Could not open the requested SVN filesystem | 倉庫路徑錯誤、權限不足 | 確認 -r 參數指向倉庫父目錄、svn 用戶有讀寫權 |
| Repository moved permanently | 客戶端 URL 缺少尾斜線、Apache 配置重導向 | 統一使用 svn://ip/repo/ 結尾帶斜線 |
| Out of date / Conflict | 版本衝突 | svn update 後手動解決衝突再 commit |
git svn 雙向同步漸進遷移遵循標準化建倉、權限分層、服務化部署、備份驗證流程,即可建立穩定可靠的 SVN 版本控制基礎設施。