svn备份、恢复与同步

关闭所有运行的进程,并确认没有程序在访问存储库(如 httpd、svnserve 或本地用户在直接访问)。

备份svn存储库
Java代码   收藏代码
  1. #压缩备份  
  2. svnadmin dump /home/workhome/svn/repository | gzip > ~/repository-backup.gz  
  3. #不压缩备份  
  4. svnadmin dump /home/workhome/svn/repository > ~/repository-backup.svn  


恢复svn存储库
Java代码   收藏代码
  1. #建立新的svn存储库  
  2. svnadmin create /home/workhome/svn/newrepository  
  3. #确认成功与否  
  4. ls -l /home/workhome/svn/newrepository  
  5. #导入存储库数据  
  6. svnadmin load /home/workhome/svn/newrepository < ~/repository-backup.svn  


其他svn命名
svnadmin recover — 将版本库数据库恢复到稳定状态
Java代码   收藏代码
  1. svnadmin recover /home/workhome/svn/newrepository  


删除存储库中无用的日志文件
Java代码   收藏代码
  1. svnadmin list-unused-dblogs /home/workhome/svn/newrepository/ | xargs rm -vf  


删除存储库中所有剩余的共享内存文件
Java代码   收藏代码
  1. rm -f /home/workhome/svn/newrepository/db/_db.0*  




实现svnsync

实现svnsync的唯一的前提条件是创建一个希望镜像的版本库,一旦创建,你就可以按照下面步骤继续。

Step 1: 创建镜像Repository(要与主Repository名字相同)
Java代码   收藏代码
  1. svnadmin create MIRROR_REPO_PATH  


Step 2: 设置镜像版本库只对同步用户可写

Java代码   收藏代码
  1. svnsync synchronize -h  
  2. synchronize (sync): usage: svnsync synchronize DEST_URL  
  3.   
  4. Transfer all pending revisions to the destination from the source  
  5. with which it was initialized.  
  6.   
  7. Valid options:  
  8.   --non-interactive        : do no interactive prompting  
  9.   --no-auth-cache          : do not cache authentication tokens  
  10.   --username ARG           : specify a username ARG (deprecated;  
  11.                              see --source-username and --sync-username)  
  12.   --password ARG           : specify a password ARG (deprecated;  
  13.                              see --source-password and --sync-password)  
  14.   --source-username ARG    : connect to source repository with username ARG  
  15.   --source-password ARG    : connect to source repository with password ARG  
  16.   --sync-username ARG      : connect to sync repository with username ARG  
  17.   --sync-password ARG      : connect to sync repository with password ARG  
  18.   --config-dir ARG         : read user configuration files from directory ARG  
  19.   -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的授权功能设置缺省的访问规则:
Java代码   收藏代码
  1. [/]  
  2. * = r  
  3. svnsync = rw  


另一个选项就是使用start-commit(MIRROR_REPO_PATH/hooks下) 检查svnsync用户,下面是一个例子,是shell脚本:
Java代码   收藏代码
  1. #!/bin/sh  
  2. USER=”$2″   
  3. if [ “$USER” = “svnsync” ];  
  4.    then exit 0  
  5. fi   
  6. echo “Only the syncuser user may commit new revisions as this is a read-only, mirror repository.” >&2  
  7. exit 1  



Step 3: 让镜像版本库使用同步用户修改修订版本属性

为此,我们需要创建一个pre-revprop-change(MIRROR_REPO_PATH/hooks下)钩子,类似于下面的例子,也是shell脚本:
Java代码   收藏代码
  1. #!/bin/sh   
  2. USER=”$3″   
  3. if [ “$USER” = “svnsync” ];  
  4.    then exit 0;  
  5. fi   
  6. echo “Only the syncuser user may change revision properties as this is a read-only, mirror repository.”  >&2  
  7. exit 1  


Step 4: 注册同步的镜像版本库

在任何平台使用下面的svnsync命令:
Java代码   收藏代码
  1. svnsync initialize URL_TO_MIRROR_REPO URL_TO_MASTER_REPO --username=svnsync --password=svnsyncpassword  


如果所有的配置正确,你一定会看到下面的输出:
Copied properties for revision 0.

现在你已经注册了镜像版本库与主版本库的同步,我们必须继续执行初始的同步,这样镜像版本库才和主版本库是一样的了。

Step 5: 执行初始同步

为了确定所有事情已经准备好了,并且执行初始同步,在任何系统只需要执行:
Java代码   收藏代码
  1. 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脚本:
Java代码   收藏代码
  1. # Example for synchronizing one repository from the post-commit hook  
  2. #!/bin/sh  
  3.   
  4. svnsync synchronize URL_TO_MIRROR_REPO -username=svnsync -password=svnsyncpassword &   
  5.   
  6. exit 0  


注:上述钩子脚本需用 chmod 755 使之可运行。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值