Linux下SVN服务器的安装与配置-备份-恢复-计划任务
简介:
SVN是Subversion的简称,是一个开放源代码的版本控制系统,相较于RCS、CVS,它采用了分支管理系统,它的设计目标就是取代CVS。互联网上很多版本控制服务已从CVS迁移到Subversion。
运行方式
svn服务器有2种运行方式:独立服务器和借助apache运行。两种方式各有利弊,用户可以自行选择。
一、安装svn
# yum install subversion-1.6.11-7.el5_6.4 mysql-server httpd mod_dav_svn mod_perl sendmail wget gcc-c++ make unzip perl* ntsysv vim-enhanced subversion-1.6.11-7.el5_6.4 (SVN服务器,版本号) mysql-server (用于codestriker) httpd mod_dav_svn mod_perl (用于支持WEB方式管理SVN服务器) sendmail (用于配置用户提交代码后发邮件提醒) wget gcc-c++ make unzip perl* (必备软件包) ntsysv vim-enhanced (可选)软件包作用说明
二、基本配置
1,新建一个目录用于存储SVN所有文件
# mkdir /data/svn # cd /data/
2,新建一个版本仓库
# svnadmin create /data/svn/project
3,初始化版本仓库中的目录
# mkdir project project/server project/client project/test //建立临时目录,目录为开发人员上传的数据目录 # svn import project file:///data/svn/project -m "初始化" # rm -rf project //删除刚刚创建的project文件,因为已经初始化到了svn版本库
4,添加用户
# vim /data/svn/project/conf/passwd [users] # harry = harryssecret # sally = sallyssecret admin = 123456 //账号是admin密码是123456(SVN账户的密码是明文,不支持http密文密码,下面会有解释)
5,修改用户访问策略
# vim /data/svn/project/conf/authz //记录用户的访问策略,以下是参考: [groups] [/] admin = rw * = //* =表示,除了上面设置了权限的用户组之外,其他任何人都被禁止访问本目录。这个很重要,一定要加上!
6,修改svnserve.conf文件,指定密码与策略文件。
# vim svnserve.conf [general] anon-access = none auth-access = write password-db = /data/svn/project/conf/passwd authz-db = /data/svn/project/conf/authz
7,启动服务器
# svnserve -d -r /data/svn
注意:如果修改了svn配置,需要重启svn服务,步骤如下:
# ps -aux|grep svnserve # kill -9 ID号 # svnserve -d -r /data/svn
8,测试服务器(目前还不能通过web测试)
# svn co svn://192.168.5.10/project
Authentication realm: <svn://192.168.5.10:3690> d72f34c5-d386-4d19-bc8b-9e5192737eee Password for 'root': //直接回车 Authentication realm: <svn://192.168.5.10:3690> d72f34c5-d386-4d19-bc8b-9e5192737eee Username: admin //用户名 Password for 'admin': //刚刚passwd里设置的密码 ----------------------------------------------------------------------- ATTENTION! Your password for authentication realm: <svn://192.168.5.10:3690> d72f34c5-d386-4d19-bc8b-9e5192737eee can only be stored to disk unencrypted! You are advised to configure your system so that Subversion can store passwords encrypted, if possible. See the documentation for details. You can avoid future appearances of this warning by setting the value of the 'store-plaintext-passwords' option to either 'yes' or 'no' in '/root/.subversion/servers'. ----------------------------------------------------------------------- Store password unencrypted (yes/no)? yes A project/test A project/server A project/client Checked out revision 1.
三、配置SVN服务器的HTTP支持可以启动一下httpd测试一下
1,设置apache访问svn的权限,不然apache是没有权限读取svn下的数据的
# chown -R apache:apache /data/svn/
那我们来转换SVN服务器的密码,由于SVN服务器的密码是明文的,HTTP服务器不与支持,所以需要转换成HTTP支持的格式。
2,创建支持apache的SVN账号密码
# touch passwd # htpasswd -c /data/passwd admin //创建用户admin,并为其设置密码 # cat passwd >> /data/svn/project/conf/passwd# vim /data/svn/project/conf/passwd //注释admin的明文账户 #admin = admin
3,在apache的配置文件中添加下面这些内容,以便支持SVN服务
# vim /etc/httpd/conf/httpd.conf <Location /project> DAV svn SVNPath /data/svn/project/ AuthType Basic AuthName "svn for project" AuthUserFile /data/svn/project/conf/passwd AuthzSVNAccessFile /data/svn/project/conf/authz Satisfy all Require valid-user </Location>
重启svn、httpd服务# ps -ef |grep svnserve# kill -9 3994# svnserve -d -r /data/svn# service httpd restart
4,客户端测试
这样用Windows的svn客户端或者浏览器测试
浏览器测试:http://192.168.5.10/project
Windows客户端测试:
安装TortoiseSVN----->在桌面右击鼠标----->TortoiseSVN----->版本库浏览器(R)----->http://192.168.5.10/project----->账号密码----->确定
注意:输入账号或密码就可以了(密码为http支持的格式非明文)
===========================================================================================================================================================================================================================================
===========================================================================================================================================================================================================================================
四、添加删除版本库
先把httpd停掉,再给passwd添加一个明文用户,设置authz的权限
# service httpd stop Stopping httpd: [ OK ] # vim /data/svn/project/conf/passwd : : [users] # harry = harryssecret # sally = sallyssecret #admin = 123456 test = test admin:uyvcrbGbdBPuk : : # vim /data/svn/project/conf/authz : : [groups] [/] admin = rw test = rw * = : : # ps -ef |grep svn root 4032 1 0 15:14 ? 00:00:00 svnserve -d -r /data/svn root 25723 3556 0 16:35 pts/1 00:00:00 grep svn # kill -9 4032 # svnserve -d -r /data/svn # svn ls svn://192.168.5.10/project Authentication realm: <svn://192.168.5.10:3690> d72f34c5-d386-4d19-bc8b-9e5192737eee Password for 'admin': Authentication realm: <svn://192.168.5.10:3690> d72f34c5-d386-4d19-bc8b-9e5192737eee Username: test Password for 'test': ----------------------------------------------------------------------- ATTENTION! Your password for authentication realm: <svn://192.168.5.10:3690> d72f34c5-d386-4d19-bc8b-9e5192737eee can only be stored to disk unencrypted! You are advised to configure your system so that Subversion can store passwords encrypted, if possible. See the documentation for details. You can avoid future appearances of this warning by setting the value of the 'store-plaintext-passwords' option to either 'yes' or 'no' in '/root/.subversion/servers'. ----------------------------------------------------------------------- Store password unencrypted (yes/no)? yes client/ server/ test/ # svn delete svn://192.168.5.10/progect/client -m "delete" svn: No repository found in 'svn://192.168.5.10/progect/client' # svn delete svn://192.168.5.10/project/client -m "delete" Committed revision 2. # svn delete svn://192.168.5.10/project/server -m "delete" Committed revision 3. # svn delete svn://192.168.5.10/project/test -m "delete" Committed revision 4. # svn mkdir -m "UP" svn://192.168.5.10/project/union Committed revision 5. # svn mkdir -m "UP" svn://192.168.5.10/project/wangyi Committed revision 6. # vim /data/svn/project/conf/passwd [users] # harry = harryssecret # sally = sallyssecret #admin = 123456 test = test admin:uyvcrbGbdBPuk # ps -ef |grep svn root 25725 1 0 16:35 ? 00:00:00 svnserve -d -r /data/svn root 25759 3556 0 16:40 pts/1 00:00:00 grep svn # kill -9 25725 # svnserve -d -r /data/svn # service httpd start Starting httpd: [ OK ] 详细步骤,请打开查看 上传文件到svn版本库 file目录下的文件是其它服务器的备份文件 # export LANG="zh_CN.GB2312" //文件名有中文的时候需要设置变量 # svn import /data/file/ file:///data/svn/project/file --message "init" # svn import /data/file/ svn:///data/svn/project/file --message "init" //两条命令是一样的
五、SVN的备份和还原(两种备份方式)
1、hotcopy备份方式: # svnadmin hotcopy /data/svn/project /data/bakup/`date +/%y%m%d`/ --clean-logs //用svnadmin整体备份/data/svn/project到/data/bakup/目录里并且以时间命名 2、dump备份方式: # svnadmin dump /data/svn/project > /data/beifen/`date +/%Y%m%d`.bak //推荐此方法备份,下面模拟用的就是dump的方式
六、模拟服务器奔溃(在有备份文件的情况下,恢复到新服务器)
# rm -rf /data/svn/* # ps -ef |grep svn # kill -9 26221 # svnadmin create /data/svn/ceshi # export LANG=en_US # svnadmin load /data/svn/ceshi < /data/20150906 # cat /data/passwd >> /data/svn/ceshi/conf/passwd [users] admin:uyvcrbGbdBPuk
# vim /data/svn/ceshi/conf/authz
[groups] [/] admin = rw * =
# vim /data/svn/ceshi/conf/svnserve.conf
[general] anon-access = none auth-access = write password-db = /data/svn/ceshi/conf/passwd authz-db = /data/svn/ceshi/conf/authz
# vim /etc/httpd/conf/httpd.conf
<Location /ceshi> DAV svn SVNPath /data/svn/ceshi/ AuthType Basic AuthName "svn for ceshi" AuthUserFile /data/svn/ceshi/conf/passwd AuthzSVNAccessFile /data/svn/ceshi/conf/authz Satisfy all Require valid-user </Location>
# service httpd restart # svnserve -d -r /data/svn 测试是否成功恢复 http://192.168.5.10/ceshi
七、自动全量备份脚本
# vim svn.pl #!/usr/bin/perl -w my $svn_repos="/data/svn/project"; my $backup_dir="/data/backup/svn/"; my $next_backup_file = "svn".`date +%Y%m%d`; $youngest=`svnlook youngest $svn_repos`; chomp $youngest; print "Backing up to revision $youngest"; my $svnadmin_cmd="svnadmin dump --revision $youngest $svn_repos >$backup_dir/$next_backup_file"; `$svnadmin_cmd`; open(LOG,">$backup_dir/last_backed_up"); #记录备份的版本号 print LOG $youngest; close LOG; #如果想节约空间,则再执行下面的压缩脚本 #print "Compressing dump file...n"; #print `gzip -9 $backup_dir/$next_backup_file`;
删除三天前的备份文件
# vim svn-Timing-delete.sh find /data/backup/svn/ -type f -mtime +3 -exec rm '{}' \;
添加到计划任务
Subversion (SVN) 的详细介绍:请点这里
Subversion (SVN) 的下载地址:请点这里
相关推荐
pub_svnserve.conf的 pub_authz.conf的配置文件有非法字符的原因引起,需要查找pub_authz.conf提的非法内容比如多余的空格删除或直接将pub_authz.conf