SVN-/Trac-Migration to Github in 2021We have a very complex and big trac-/svn-environment since we started coding our VoIP-One PBX. Trac was a great tool for such a long time and having so much data inside of it stopped us moving to the modern Git-/Github-Environment for a veeeery long time.

But now we did it and it really wasn’t that easy.

The reason is that we didn’t have to just migrate our SVN-Infrastructure but also all Wiki-Pages that document our code and also our Trac-Tickets where we managed our futher development.

After I had to deal with so many problems during the last days I try to collect all steps I have done and maybe it might help other people in the same situation.

There exist some complete solutions to migrate everything with one script but I had no luck with it in 2021. So here are my steps for migrating today.

SVN to Git Migration

First we download a small helper-file from Atlassian to generate a authors.txt file. In the authors.txt we describe which users in the svn-repository will be which users in the new git-repository.

Download the file here…

wget https://bitbucket.org/atlassian/svn-migration-scripts/downloads/svn-migration-scripts.jar

The authors.txt file could look like this

foo.bar = Foo Bar <f.bar@voipone.ch>
2nd.user = 2nd User <2nd.user@voipone.ch>
3nd.user = 3rd User <3rd.user@voipone.ch>

No execute the following command for creating the authors.txt file automatically out of your existing SVN-Repository. After downloading edit the file and add the names based on your environment.

java -jar svn-migration-scripts.jar authors https://svn.your-server.ch/your-repository SVN_USERNAME SVN_PASSWORD > authors.txt

On Mac OSX Big Sur (and it seems this is valid for Catalina too) git-svn is no longer working. I found a solution here.

On Mac OSX BigSur I had to execute the following command for getting git svn running.

export PERL5LIB=/usr/local/lib/perl5/site_perl/5.28.2/darwin-thread-multi-2level

The following commands checkout the SVN-Repository as Git and do some format-changes for example for transforming SVN-Tags to real Git-Tags.

I got this list of commands from this page.

git svn clone --stdlayout --authors-file=authors.txt --no-metadata https://svn.your-server.ch/your-repository svnRepositoryAsGit
cd svnRepositoryAsGit
for t in $(git for-each-ref --format='%(refname:short)' refs/remotes/tags); do git tag ${t/tags\//} $t && git branch -D -r $t; done
for b in $(git for-each-ref --format='%(refname:short)' refs/remotes); do git branch $b refs/remotes/$b && git branch -D -r $b; done
for p in $(git for-each-ref --format='%(refname:short)' | grep @); do git branch -D $p; done

And finally let’s transmit the changes to Github.

git remote add origin https://github.com/your-company/your-project.git
git push origin --all
git push origin --tag

Trac-Wiki to Github-Wiki Migration

Next login to your trac-server to do our wiki-migration. These steps are mainly based on the description of this page.

Run a trac-wiki-export

cd /usr/src
mkdir trac-wiki-dump
cd trac-wiki-dump/
trac-admin /home/trac/default/ wiki dump /usr/src/trac-wiki-dump/

Rename the Homepage and cleanup trac-specific junk

mv WikiStart Home
rm -f Wiki* Trac* CamelCase BadIP PageTemplates Inter* SandBox TitleIndex RecentChanges

Transform Trac-Wiki-Syntax to MediaWiki-Syntax which is used by Github.

Therefore we need a small helper-file which you can download here: https://www.mediawiki.org/w/index.php?oldid=2103135

Enter the code into a new file in /usrc/src/TracWiki2MediaWiki.pl

cd /usr/src/trac-wiki-dump
for f in *; do perl ../TracWiki2MediaWiki.pl $f; mv $f.after $f.wiki; done

Remove old Trac-Footer from all wiki-files which conflicts with MediaWiki-Syntax

sed -i -- 's/{{TracNotice|{{PAGENAME}}}}//g' *

Clone the Wiki of your Github-Repository and add your new content.

cd /usr/src
git clone https://github.com/your-company/your-repository.wiki.git
cd your-repository.wiki/
git rm -f Home.md
cp /usr/src/trac-wiki-dump/*wiki .
git add *wiki
git commit
git push

Trac-Tickets to Github-Issues Migration

In our last step we want to transfer all Trac-Tickets and Roadmaps to Github Issues.

First we have to prepare trac and install xml-rpc plugin. Go to you trac home-directory and execute the following commands.

apt-get install python python-pip
cd /home/trac/default/
pip install svn+https://trac-hacks.org/svn/xmlrpcplugin/trunk
trac-admin . config set components tracrpc.* enabled
trac-admin . permission add authenticated XML_RPC

Next we use a handy script again that does this migration-job for us.

cd /usr/src
git clone https://github.com/robertoschwald/migrate-trac-issues-to-github.git
cd migrate-trac-issues-to-github
pip install PyGithub
git config --global github.username myusername
git config --global github.password 
./migrate.py --trac-url=https://YOUR_TRAC_USERNAME:YOUR_TRAC_PASSWORD@trac.voip-one.ch/default --github-api-url=https://api.github.com --github-project=your-company/your-repository

Here on my side the script stopped again and again after about 50 requests because there seems to exist a request-limit on github. This is not a big deal. You can run the script again and again when it stops. It automatically recognizes where it stopped and continues with the next ticket.

Schreiben Sie einen Kommentar

Ihre E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

Fill out this field
Fill out this field
Bitte geben Sie eine gültige E-Mail-Adresse ein.
You need to agree with the terms to proceed

Menü
Support