九零不老心
发布于 2019-06-04 / 10 阅读 / 0 评论 / 0 点赞

subversion常用操作

#安装
    yum install subversion mod_dav_svn -y
    mkdir -pv /opt/svn
    #创建版本库
        svnadmin create /opt/svn/weekly-publication
    #修改配置文件
        vi conf/authz
        vi conf/passwd
        vi conf/svnserve.conf
    #启动svn服务
        svnserve -d -r /opt/svn
#二进制安装https://svn.apache.org/repos/asf/subversion/trunk/INSTALL
    yum install -y apr apr-util apr-devel apr-util-devel libserf libserf-devel httpd httpd-devel
    wget http://mirror.bit.edu.cn/apache/subversion/subversion-1.12.0.tar.gz
    tar -xzvf /opt/subversion-1.12.0
    cd /opt/subversion-1.12.0/
    wget https://www.sqlite.org/2015/sqlite-amalgamation-3081101.zip
    unzip sqlite-amalgamation-3081101.zip && mv sqlite-amalgamation-3081101 sqlite-amalgamation
    ./configure --prefix=/opt/subversion --enable-apache-whitelist=2.4.6 --with-lz4=internal --with-utf8proc=internal
    make -j
    make install
    /opt/subversion/bin/svnadmin create /data/subversion/official
    /opt/subversion/bin/svnserve -d -r /data/subversion/
#svn检出,文件受版本控制
    /usr/bin/svn checkout svn://192.168.1.1/test/webapp/ /opt/docker_app/nginx/www/ --username test --password 'test@#321' --no-auth-cache --force
#svn更新受版本控制的文件
    cd /opt/docker_app/nginx/www
    /usr/bin/svn update /opt/docker_app/nginx/www --username test --password 'test@#321' --no-auth-cache
#svn导出,文件不受版本控制    
    /usr/bin/svn export svn://192.168.1.1/test/webapp/ /opt/docker_app/nginx/www/ --username test --password 'test@#321' --no-auth-cache --force
#svn添加未添加的文件到版本库
    svn st | grep '^\?' | tr '^\?' ' ' | sed 's/[ ]*//' | sed 's/[ ]/\\ /g' | xargs svn add
#svn提交
    svn commit -m '20181126' *  --username websites --password 'websites' --no-auth-cache

#svn同步
    #全部同步svnadmin hotcopy
        svnadmin hotcopy /data/svndata/official /data/subversion/official
    #全部同步or增量同步svnadmin dump是官方推荐的备份方式,优点:比较灵活,可以全量备份也可以增量备份,并提供了版本恢复机制
        svnadmin dump /data/svndata/official > /data/backup/subversion/official.dump
        svnadmin load -q /data/svndata/official < /data/backup/subversion/official.dump
    #另一种svn热同步
        #现有环境已经有一个版本库/data/svndata/official现在同步到另一个版本的svn版本库/data/subversion/official(新建的空版本库)中
            #创建新的空的版本库
                /opt/subversion/bin/svnadmin create /data/subversion/official
            #创建pre-revprop-change hooks
                cd /data/subversion/official/hooks && \cp -f pre-revprop-change.tmpl pre-revprop-change && chmod u+x pre-revprop-change
                vi pre-revprop-change修改exit 1 为exit 0 (否则后续流程会报错ask the administrator to create a pre-revprop-change hook)
            #启动另一个版本库,使用非默认端口
                /opt/subversion/bin/svnserve -d -r /data/subversion --listen-port 8888
            #初始化镜像版本库(注意顺序:svnsync initialize MIRROR_URL SOURCE_URL)
                /opt/subversion/bin/svnsync init file:///data/subversion/official svn://localhost/official  --username websites --password 'websites' --no-auth-cache
            #同步
                nohup /opt/subversion/bin/svnsync sync file:///data/subversion/official --username websites --password 'websites' --no-auth-cache &
                #如果有数据更新,再次执行就是增量同步
                    /opt/subversion/bin/svnsync sync file:///data/subversion/official --username websites --password 'websites' --no-auth-cache
#svn导出版本库
    DOS:
        #从版本库中导出
        svnadmin.exe dump D:\svndata\myrepos1 > D:\backup.dump
        #导入版本库
        svnadmin.exe load D:\svndata\myrepos1 < D:\backup.dump
    Unix:
        #从版本库中导出
        svnadmin dump /data/svndata/official > /data/backup/subversion/official.dump
        #导入版本库
        svnadmin load -q /data/svndata/official < /data/backup/subversion/official.dump
#svn问题汇总及解决
    #提示 "svn: Commit failed (details follow): svn: '/***/xxx.c' is scheduled for addition, but is missing "
        svn revert xxx.c --depth infinity
    #版本库的 UUID“6733b047-760f-442f-90de-1e1d830f442f”与期望的 UUID“06bf0569-abf7-47c7-81f8-d53f56c8fa68”不匹配
    #出现这个问题的原因就是SVN服务器上仓库的uuid和我们本地仓库中的uuid不一致引起的。uuid是SVN服务器在创建仓库时自动生成的一个随机数,通过这个随机数用来判断服务器和客户端的仓库是否一致,如果不一致,就会引起冲突。
        #svnserver上查看uuid
            /opt/subversion/bin/svnlook uuid /data/subversion/official #返回6733b047-760f-442f-90de-1e1d830f442f
        #设置svnserver repo的uuid为我本地id
            /opt/subversion/bin/svnadmin setuuid /data/subversion/official 06bf0569-abf7-47c7-81f8-d53f56c8fa68
        #查看svenserver设置结果
            /opt/subversion/bin/svnlook uuid /data/subversion/official
        #客户端进行正常的更新修改提交