天天看點

svn日常管理

關于svn的備份還原,很有用就轉來了

備份svn存儲庫

#壓縮備份   

svnadmin dump /home/workhome/svn/repository | gzip > ~/repository-backup.gz   

#不壓縮備份   

svnadmin dump /home/workhome/svn/repository > ~/repository-backup.svn  

恢複svn存儲庫

#建立新的svn存儲庫   

svnadmin create /home/workhome/svn/newrepository   

#确認成功與否   

ls -l /home/workhome/svn/newrepository   

#導入存儲庫資料   

svnadmin load /home/workhome/svn/newrepository < ~/repository-backup.svn  

其他svn命名

svnadmin recover — 将版本庫資料庫恢複到穩定狀态

svnadmin recover /home/workhome/svn/newrepository  

删除存儲庫中無用的日志檔案

svnadmin list-unused-dblogs /home/workhome/svn/newrepository/ | xargs rm -vf  

删除存儲庫中所有剩餘的共享記憶體檔案

rm -f /home/workhome/svn/newrepository/db/_db.0*  

實作svnsync

實作svnsync的唯一的前提條件是建立一個希望鏡像的版本庫,一旦建立,你就可以按照下面步驟繼續。

Step 1: 建立鏡像Repository(要與主Repository名字相同)

svnadmin create MIRROR_REPO_PATH  

Step 2: 設定鏡像版本庫隻對同步使用者可寫

svnsync synchronize -h   

synchronize (sync): usage: svnsync synchronize DEST_URL   

Transfer all pending revisions to the destination from the source   

with which it was initialized.   

Valid options:   

  --non-interactive        : do no interactive prompting   

  --no-auth-cache          : do not cache authentication tokens   

  --username ARG           : specify a username ARG (deprecated;   

                             see --source-username and --sync-username)   

  --password ARG           : specify a password ARG (deprecated;   

                             see --source-password and --sync-password)   

  --source-username ARG    : connect to source repository with username ARG   

  --source-password ARG    : connect to source repository with password ARG   

  --sync-username ARG      : connect to sync repository with username ARG   

  --sync-password ARG      : connect to sync repository with password ARG   

  --config-dir ARG         : read user configuration files from directory ARG   

  -q [--quiet]             : print as little as possible  

  --username ARG           : specify a username ARG (deprecated;

                             see --source-username and --sync-username)

  --password ARG           : specify a password ARG (deprecated;

                             see --source-password and --sync-password)

這句意思是不是同步使用者可以主Repository和鏡像Repository都設成一樣。待實踐

為了讓鏡像版本庫隻被同步使用者寫,我們的例子裡使用者名是”svnsync”,我們有一些選項,一個就是使用Subversion的授權功能設定預設的通路規則:

[/]   

* = r   

svnsync = rw  

另一個選項就是使用start-commit(MIRROR_REPO_PATH/hooks下) 檢查svnsync使用者,下面是一個例子,是shell腳本:

#!/bin/sh   

USER=”$2″    

if [ “$USER” = “svnsync” ];   

   then exit 0  

fi    

echo “Only the syncuser user may commit new revisions as this is a read-only, mirror repository.” >&2  

exit 1  

Step 3: 讓鏡像版本庫使用同步使用者修改修訂版本屬性

為此,我們需要建立一個pre-revprop-change(MIRROR_REPO_PATH/hooks下)鈎子,類似于下面的例子,也是shell腳本:

#!/bin/sh    

USER=”$3″    

   then exit 0;   

echo “Only the syncuser user may change revision properties as this is a read-only, mirror repository.”  >&2  

Step 4: 注冊同步的鏡像版本庫

在任何平台使用下面的svnsync指令:

svnsync initialize URL_TO_MIRROR_REPO URL_TO_MASTER_REPO --username=svnsync --password=svnsyncpassword  

如果所有的配置正确,你一定會看到下面的輸出:

Copied properties for revision 0.

現在你已經注冊了鏡像版本庫與主版本庫的同步,我們必須繼續執行初始的同步,這樣鏡像版本庫才和主版本庫是一樣的了。

Step 5: 執行初始同步

為了确定所有事情已經準備好了,并且執行初始同步,在任何系統隻需要執行:

svnsync synchronize URL_TO_MIRROR_REPO --username=svnsync --password=svnsyncpassword  

如果所有的同步正确,你會看到類似的輸出:

Committed revision 1.

Copied properties for revision 1.

Committed revision 2.

Copied properties for revision 2.

Committed revision 3.

Copied properties for revision 3.…

Step 6: 使用post-commit(MASTER_REPO_PATH/hooks下)鈎子自動同步

根據初始同步的輸出,我們現在要做的就是寫一個定時執行或post-commit鈎子來同步鏡像版本庫,我建議post-commit,因為它讓你的鏡像版本庫盡可能的最新,下面是可以用在主版本庫上同步鏡像版本庫的post-commit鈎子,一個shell腳本:

# Example for synchronizing one repository from the post-commit hook   

svnsync synchronize URL_TO_MIRROR_REPO -username=svnsync -password=svnsyncpassword &    

exit 0  

注:上述鈎子腳本需用 chmod 755 使之可運作。

原文位址:http://saplingidea.javaeye.com/blog/482924

繼續閱讀