关闭所有运行的进程,并确认没有程序在访问存储库(如 httpd、svnserve 或本地用户在直接访问)。
备份svn存储库
恢复svn存储库
其他svn命名
svnadmin recover — 将版本库数据库恢复到稳定状态
删除存储库中无用的日志文件
删除存储库中所有剩余的共享内存文件
实现svnsync
实现svnsync的唯一的前提条件是创建一个希望镜像的版本库,一旦创建,你就可以按照下面步骤继续。
Step 1: 创建镜像Repository(要与主Repository名字相同)
Step 2: 设置镜像版本库只对同步用户可写
--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的授权功能设置缺省的访问规则:
另一个选项就是使用start-commit(MIRROR_REPO_PATH/hooks下) 检查svnsync用户,下面是一个例子,是shell脚本:
Step 3: 让镜像版本库使用同步用户修改修订版本属性
为此,我们需要创建一个pre-revprop-change(MIRROR_REPO_PATH/hooks下)钩子,类似于下面的例子,也是shell脚本:
Step 4: 注册同步的镜像版本库
在任何平台使用下面的svnsync命令:
如果所有的配置正确,你一定会看到下面的输出:
Copied properties for revision 0.
现在你已经注册了镜像版本库与主版本库的同步,我们必须继续执行初始的同步,这样镜像版本库才和主版本库是一样的了。
Step 5: 执行初始同步
为了确定所有事情已经准备好了,并且执行初始同步,在任何系统只需要执行:
如果所有的同步正确,你会看到类似的输出:
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脚本:
注:上述钩子脚本需用 chmod 755 使之可运行。
备份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″
- if [ “$USER” = “svnsync” ];
- then exit 0;
- fi
- echo “Only the syncuser user may change revision properties as this is a read-only, mirror repository.” >&2
- exit 1
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
- #!/bin/sh
- svnsync synchronize URL_TO_MIRROR_REPO -username=svnsync -password=svnsyncpassword &
- exit 0
注:上述钩子脚本需用 chmod 755 使之可运行。