SVN - Linux下SVN安装备份迁移方案

环境介绍:

root@pts/0 $ cat /etc/redhat-release
CentOS Linux release 7.1.1503 (Core) 

root@pts/0 $ uname -rm
3.10.0-229.4.2.el7.x86_64 x86_64

SVN 安装

Centos默认的YUM base包里面就包含了subversion安装包
故用以下命令即可

安装

yum install subversion –y

验证版本

svnserver –version

新建版本库

## 创建SVN 版本库根目录
mkdir –p /opt/svn/repository

## 进入目录,创建实际的版本库
cd /opt/svn/repository
svnadmin create repos1
svnadmin create repos2

初始化版本库

mkdir svninit 
mkdir svninit/web svninit/test
svn import svninit/ file:///opt/svn/repository/repos1

配置

## 列举版本库下面的文件
ls –l /opt/svn/repository/repos1
drwxr-xr-x 2 root root 4096 Jul  6 14:02 conf
drwxr-sr-x 7 root root 4096 Jul 12 15:15 db
-r--r--r-- 1 root root    2 Feb 16 15:31 format
drwxr-xr-x 2 root root 4096 Feb 16 15:31 hooks
drwxr-xr-x 2 root root 4096 Feb 16 15:31 locks
-rw-r--r-- 1 root root  229 Feb 16 15:31 README.txt

## 详细配置
关于SVN 的详细配置可以参考《Centos7 下SVN详细配置》

启动

-r 添加 repository的根目录
-d 让SVN以deamon的形式运行

svnserve -r /opt/svn/repository/ –d

访问

# 访问地址
svn://192.168.68.9/repos1
svn://192.168.68.9/repos2

## Linux 测试
[root@duqian svntest]# svn co svn://192.168.100.6/repos1
Checked out revision 0.
[root@duqian svntest]# svn co svn://192.168.100.6/repos2
Checked out revision 0.

SVN 备份迁移

SVN备份有三种方式

svnadmin dump

官方推荐的备份方式。可以结合bzip2 备份的同时压缩

有点:可全量也可增量备份,方式比较灵活。并提供对应的恢复机制
缺点:当版本库很大的时候,这种备份方式超级耗时,恢复也很耗时,不利于紧急的灾难恢复
svnadmin dump /opt/svn/repository/repos1 |bzip2 > /tmp/repos1.bz2

svnadmin hotcopy

优点:备份和恢复的过程相对较快
缺点:只能全量copy,此外比较耗费硬盘
svnadmin hotcopy –clean-logs /opt/svn/repository/repos1 /tmp/repos1_20160712

如果添加 –clean-logs 选项,则 svnadmin 会先执行热拷贝,然后删除不用的Berkeley DB日志文件

Svnsync

SVN 1.4 版本以上支持,实际是制作两个image库
优点:制作的两个image库可以作为双机实时备份
缺点:作为两个image库使用的时候,在恢复和操作上有很大的限制

所以一般不用此方式   

停服务纯文件copy

这种方式建议在不使用SVN 的时候停掉服务,然后采用Linux下纯文件copy的方式,可以用scp或者 rsync 等命令来实现

scp /opt/svn/repository 192.168.100.7: /opt/svn/repository

建议

版本库很小的时候采用方式一 'svnadmin dump',
 如果库相对较大又想得到很好地恢复时间和操作,可以采用方式二 ‘svnadmin hotcopy’

SVN恢复

svnadmin load

svnadmin load /opt/svnnew/repository/repos1 < /tm/repos1_20160712

svnadmin hotcopy

svnadmin hotcopy /tmp/repos1_20160712 /opt/svnnew/repository/repos1

SVN错误

E205007

[root@duqian repository]# svn import /tmp/svn-init/ file:///opt/svn/repository/repos1/ 
svn: E205007: Could not use external editor to fetch log message; consider setting the $SVN_EDITOR environment variable or using the --message (-m) or --file (-F) options
svn: E205007: None of the environment variables SVN_EDITOR, VISUAL or EDITOR are set, and no 'editor-cmd' run-time configuration option was found   

解决方法:

1,  svn import/commit 的时候添加 –m 参数
2,  设置 SVN_EDITOR变量 export SVN_EDITOR=vim 这种方式会弹出一个页面填写comment

E150002

[root@duqian repository]# svn import /tmp/svn-init.log file:///opt/svn/repository/repos1/ -m 'svn 初始化'
svn: E150002: Path 'file:///opt/svn/repository/repos1' already exists

解决方法:

经过自己验证和参照,import不能导入单个文件

[root@duqian repository]# svn help import
import: Commit an unversioned file or tree into the repository.
usage: import [PATH] URL

  Recursively commit a copy of PATH to URL.
  If PATH is omitted '.' is assumed.
  Parent directories are created as necessary in the repository.
  If PATH is a directory, the contents of the directory are added
  directly under URL.
  Unversionable items such as device files and pipes are ignored
  if --force is specified.

《SVN - Linux下SVN安装备份迁移方案》 公众号: Colinws工作室

    原文作者:全栈运维
    原文地址: https://www.jianshu.com/p/34b1eba3bd8b
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞