SVN数据迁移至Gitlab

近日有需求,需要将原有SVN的数据迁移至Gitlab上,原SVN停用。

经过一番查找和测试,网上大部分方法差不多,但并不成功。

后查看了下Gitlab官方网站的操作方法,是挻简单,主要是使用了一个ruby的svn2git的工具来进行格式变换操作,可能是由于yum安装版本过低的原因,仍然不成功:

yum install svn git git-svn ruby
gem install svn2git
cd /opt
svn co svn://ipaddr/project
cd project/
svn log -q | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > /home/users.txt
svn2git svn://ipaddr/project/ios --authors /home/users.txt --username administrator
git remote add origin [email protected]:<group>/<project>.git
git push --all origin
git push --tags origin

原方法操作是挻简单,先通过svn log找出所有提交过的用户,然后转换成gitlab的格式;然后通过svn2git工具来检出svn项目,并同时转换成git格式。但执行git2svn时却出现问题:

[[email protected] ios]# mkdir /opt/ios
[[email protected] ios]# cd /opt/ios
[[email protected] ios]# svn2git svn://10.10.0.68/zongsproject/ios --authors /home/users.txt  --username administrator
Initialized empty Git repository in /opt/ios/.git/
Using higher level of URL: svn://10.10.0.68/zongsproject/ios => svn://10.10.0.68/zongsproject
command failed:
git checkout -f master
[[email protected] ios]# rm -rf .git/
[[email protected] ios]# svn2git svn://10.10.0.68/zongsproject/ios --authors /home/users.txt --rootistrunk --username administrator
Initialized empty Git repository in /opt/ios/.git/
E: 'svn:/10.10.0.68/project/ios' is not a complete URL  and a separate URL is not specified
command failed:
git svn init --prefix=svn/ --username='administrator' --no-metadata --trunk='svn://10.10.0.68/project/ios'

一直提示命令执行失败,且公司SVN上项目的结构与标准SVN结构不一致,经查看git2svn的使用说明,添加了参数后依然执行不成功,于是怀疑跟程序版本有关。

后所有程序均使用源码安装,git2svn命令可成功执行,这里记录下,过程还是有些曲折的,主要是安装perl模块SVN::Core时,由于其它依赖库不在系统默认搜索路径中导致:

基础库:

wget http://zlib.net/zlib-1.2.11.tar.xz
tar Jxf zlib-1.2.11.tar.xz -C /usr/local/src/
cd /usr/local/src/zlib-1.2.11/
CFLAGS="-fPIC -O3" ./configure --shared --64
make -j `nproc` && make install
echo '# User Defined.' > /etc/ld.so.conf.d/complie.conf
echo '/usr/local/lib' >> /etc/ld.so.conf.d/complie.conf
cd -

wget https://www.openssl.org/source/openssl-1.0.2p.tar.gz
tar zxf openssl-1.0.2p.tar.gz -C /usr/local/src/
cd /usr/local/src/openssl-1.0.2p/
CFLAGS="-fPIC -O3" ./config --prefix=/usr/local/openssl shared threads zlib
make -j `nproc` && make install
echo '/usr/local/openssl/lib' >> /etc/ld.so.conf.d/complie.conf
echo 'export PATH=/usr/local/openssl/bin:$PATH' > /etc/profile.d/openssl.sh
source /etc/profile.d/openssl.sh
openssl version
cd -

wget ftp://ftp.cwru.edu/pub/bash/readline-7.0.tar.gz
tar zxf readline-7.0.tar.gz -C /usr/local/src/
cd /usr/local/src/readline-7.0/
CFLAGS="-fPIC -O3" ./configure --enable-multibyte --with-curses
make SHLIB_XLDFLAGS=-lncurses && make install
ldd /usr/local/lib/libreadline.so.7
chcon -R -u system_u -t lib_t /usr/local/lib/libreadline.so*
ls -Z /usr/local/lib/libreadline.so.7
cd -

wget https://www.cpan.org/src/5.0/perl-5.28.0.tar.gz
tar zxf perl-5.28.0.tar.gz -C /usr/local/src/
cd /usr/local/src/perl-5.28.0/
./configure.gnu --prefix=/usr/local/perl
make -j `nproc` && make install
echo 'export PATH=/usr/local/perl/bin:$PATH' > /etc/profile.d/perl.sh
source /etc/profile.d/perl.sh
perl -v
cd -

SVN依赖库:

wget http://www.us.apache.org/dist/apr/apr-1.6.5.tar.gz
tar zxf apr-1.6.5.tar.gz -C /usr/local/src/
cd /usr/local/src/apr-1.6.5/
CFLAGS="-fPIC -O3" ./configure --prefix=/usr/local/apr --enable-threads
make -j `nproc` && make install
cd -

wget http://www.us.apache.org/dist/apr/apr-util-1.6.1.tar.gz
tar zxf apr-util-1.6.1.tar.gz -C /usr/local/src/
cd /usr/local/src/apr-util-1.6.1/
CFLAGS="-fPIC -O3" ./configure --prefix=/usr/local/apr/ --with-apr=/usr/local/apr/ --with-mysql=/usr/local/mysql/ --with-openssl=/usr/local/openssl/
make -j `nproc` && make install
cd -

wget https://www.sqlite.org/2018/sqlite-autoconf-3250200.tar.gz
tar zxf sqlite-autoconf-3250200.tar.gz -C /usr/local/src/
cd /usr/local/src/sqlite-autoconf-3250200/
CFLAGS="-fPIC -O3" ./configure
make -j `nproc` && make install
cd -
wget https://ftp.postgresql.org/pub/source/v11.0/postgresql-11.0.tar.gz
tar zxf postgresql-11.0.tar.gz -C /usr/local/src/
cd /usr/local/src/postgresql-11.0/
CFLAGS="-fPIC -O3" ./configure
make -j `nproc` && make install
cd -

wget ftp://ftp.cyrusimap.org/cyrus-sasl/cyrus-sasl-2.1.26.tar.gz
tar zxf cyrus-sasl-2.1.27.tar.gz -C /usr/local/src/
cd /usr/local/src/cyrus-sasl-2.1.27/
CFLAGS="-fPIC -O3" ./configure --prefix=/usr/local/sasl --enable-sql --with-openssl=/usr/local/openssl/ --with-sqlite3=/usr/local/
make -j `nproc` && make install
cd -

wget http://prdownloads.sourceforge.net/tcl/tcl8.6.8-src.tar.gz
tar zxf tcl8.6.8-src.tar.gz -C /usr/local/src/
cd /usr/local/src/tcl8.6.8/unix
CFLAGS="-fPIC -O3" ./configure --enable-64bit
make -j `nproc` && make install
cd -
wget http://prdownloads.sourceforge.net/tcl/tk8.6.8-src.tar.gz
tar zxf tk8.6.8-src.tar.gz -C /usr/local/src/
cd /usr/local/src/tk8.6.8/unix/
CFLAGS="-fPIC -O3" ./configure --enable-64bit
make -j `nproc` && make install
cd -
wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz
tar Jxf Python-3.7.0.tar.xz -C /usr/local/src/
cd /usr/local/src/Python-3.7.0/
yum install -y libffi-devel
CFLAGS="-fPIC -O3" ./configure --prefix=/usr/local/python3 --enable-shared --enable-optimizations --enable-ipv6 --with-openssl=/usr/local/openssl --with-tcltk-includes='-I /usr/local/include' --with-tcltk-libs='-I /usr/local/lib'
make -j `nproc` && make install
echo 'export PATH=$PATH:/usr/local/python3/bin/' > /etc/profile.d/python.sh
source /etc/profile.d/python.sh
echo '/usr/local/python3/lib/' >> /etc/ld.so.conf.d/complie.conf
ldconfig
pip3 install --upgrade pip setuptools
cd -

wget http://prdownloads.sourceforge.net/scons/scons-3.0.1.tar.gz
tar zxf scons-3.0.1.tar.gz -C /usr/local/src/
cd /usr/local/src/scons-3.0.1/
python3 setup.py install
cd -

wget https://www.apache.org/dist/serf/serf-1.3.9.tar.bz2
tar jxf serf-1.3.9.tar.bz2 -C /usr/local/src/
cd /usr/local/src/serf-1.3.9/
scons PREFIX=/usr/local APR=/usr/local/apr APU=/usr/local/apr OPENSSL=/usr/local/openssl/ ZLIB=/usr/local/lib
scons install
cd -

wget https://github.com/JuliaStrings/utf8proc/archive/v2.2.0.tar.gz
tar zxf v2.2.0.tar.gz -C /usr/local/src/
cd /usr/local/src/utf8proc-2.2.0/
make -j `nproc` && make install
cd -

SVN安装:

wget http://mirrors.hust.edu.cn/apache/subversion/subversion-1.10.3.tar.gz
tar zxf subversion-1.10.3.tar.gz -C /usr/local/src/
cd /usr/local/src/subversion-1.10.3/
CFLAGS="-fPIC -O3" CC="gcc -std=gnu99" ./configure --enable-optimize --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr --with-serf=/usr/local --with-zlib=/usr/local/lib --with-sasl=/usr/local/sasl/ --with-lz4=internal
make -j `nproc` && make install
cd -

Git安装:

wget https://github.com/git/git/archive/v2.19.1.tar.gz -O git-2.19.1.tar.gz
tar zxf git-2.19.1.tar.gz -C /usr/local/src/
cd /usr/local/src/git-2.19.1/
make configure
CPPFLAGS=-I/usr/local/openssl/include LDFLAGS=-L/usr/local/openssl/lib CFLAGS="-fPIC -O3" ./configure --prefix=/usr/local --with-zlib=/usr/local --with-python=/usr/local/python3 --with-curl=/usr/local/curl --with-openssl=/usr/local/openssl
make -j `nproc` && make install

PERL的SVN::Core,默认它自己下的svn包过旧,且会出现编译配置失败问题(因为上面大部分库是单独路径),故需手动安装下:

CFLAGS="-fPIC -O3 -std=gnu99" cpan SVN::Core
..
error
..

cd /root/.cpan/build/Alien-SVN-v1.8.11.0-0
mv src/subversion/ src/subversion2
cp -rfp /usr/local/src/subversion-1.10.3/ src/subversion
cd src/subversion/
make distclean
CFLAGS="-fPIC -O3 -std=gnu99" PERL=/usr/local/perl/bin/perl ./configure --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr --with-serf=/usr/local --with-zlib=/usr/local/lib --with-sasl=/usr/local/sasl/ --libdir=/usr/local/perl/lib/site_perl/5.28.0/x86_64-linux/Alien/SVN --prefix=/usr/local/perl --with-lz4=internal
make -j 4
cd -
./Build
./Build install

svn2git安装:

gem install svn2git

然后再执行转换检出命令即可成功:

mkdir /opt/ios
cd /opt/ios
svn2git svn://10.10.0.68/project/ios --authors /home/users.txt --rootistrunk --username administrator

然后在gitlab中新建一个空项目:

在刚才的目录中执行连接并上传:

git remote add origin http://172.16.220.223/root/ios.git
git push --all origin
git push --tags origin

查看刚才Gitlab建立的项目:

留下评论

error: Content is protected !!