天天看點

用svnsync 同步備份任意兩個svn 版本庫

用svnsync 同步備份任意兩個svn 版本庫    20100706

如用svnsync 同步備份兩台機器的svn 。

要同步的項目名稱:svn_repos

svn 版本庫1 。4 以上

源目錄:            svn://192.168.108.254/svn_repos

同步目标目錄:      http:// 目标IP:8080/svn/svn_repos/

方法:

1. 如果目标目錄 存在相同的項目,請先清除,重建立立空項目

    svnadmin create svn_repos

2. 在 192.168.120.190 ( 目标目錄 )-> cendyn 目錄下hooks 目錄下,建立

pre_revprop-change.bat 全部内容隻有一行:exit 0

如果用拷貝同目錄下的pre_revprop-change.tmpl 則必須删除最後三行的内容或替換為隻有一行:exit 0

不然下面初始化同步的時候,将停頓.

3. 執行 初始化(在目标目錄 )

    svnsync init http:// 目标IP:8080/svn/svn_repos/ svn://192.168.108.254/svn_repos

即svnsync init 目标庫 源庫

将向你詢問登入目标庫和源庫的使用者名和密碼,建議為兩個庫設定相同的使用者名及相同的密碼正确後,顯示

Copied properties for revision 0.

4. 執行同步(目标目錄 )

svnsync sync http:// 目标IP:8080/svn/svn_repos/

5. 更新同步

windows 下:

在源庫的hooks 下面,添加post-commit 腳本

可拷貝post- commit.tmpl->post- commit.bat

set SVN_HOME="C:\Install Files\svnserver\bin"

%SVN_HOME%\svnsync sync --non-interactive http://192.168.120.190:8080/svn/cendyn --username R00130 --password 123

linux 下:

在源庫的hooks 下面,添加post-commit 腳本

可拷貝post-commit.tmpl 即 

cp post-commit.tmpl post-commit

然後

把 post-commit 中,最後兩行替換為 

svnsync sync  --non-interactive http://192.168.108.187:8080/svn/svn_repos/ --username edison --password edison

即送出更新後,即執行同步指令,不進行互動

把post-commit 設為755 權限。 

ps :

如果post-commit 腳本出錯,或者無可執行權限,在送出更新時會報錯

錯誤處理 :

在源端 , 同步用的帳号需要有讀權限 , 在目的端同步帳号需要讀寫權限 . 權限配置設定合理後 , 基本上就不會出現其他錯誤 .

如果出現以下列出的之外的錯誤 , 請先檢查一下 svn 服務是否可正常使用 .

比較常見的錯誤是 :

# svnsync initialize DEST_URI SRC_URI --username cax  --password password_for_cax

svnsync: DAV request failed; it's possible that the repository's pre-revprop-change hook either failed or is non-existent

svnsync: At least one property change failed; repository is unchanged

這是由于系統中沒有 pre-revprop-change 鈎子腳本導緻的 , 該檔案在版本庫的 ~/hooks/ 下 , 隻需拷貝一份即可 .

cp -pf hooks/pre-revprop-change.tmpl hooks/pre-revprop-change

如果是 windows 系統 , 還需要清空 pre-revprop-change 的内容 , 并添加字尾為 pre-revprop-change.bat

在批處理檔案中 , Linux 下 shell 中注釋符 #   不能被 batch 正确解釋也會重複出現該錯誤 .

繼續閱讀