Merging two trac instances

Tags: python, thehealthagency

We’ve got two Trac instances at The Health Agency, one for our code and the technical issues, the other more for the content and some general pages (like telephone numbers). Well, that’s just not handy so we want to merge them.

Hard part: I couldn’t find any handy scripts or conversion tools. Easy part: I just had to merge the wiki content, not any issues. Wiki names generally don’t clash between two instances, but issue numbers probably will.

I twittered that I was pondering this problem and Martijn Pieters suggested a simple sqlite3 db/trac.db, select * from wiki. Ok, good tip. I looked at the database and it was simpler than I thought. Good design on the Trac part.

What I did in the end was effectively:

cp old_tech.db new.db
# Dump wiki and attachment content as that's all we need.
sqlite3 old_general.db ".dump wiki" > wiki.txt
sqlite3 old_general.db ".dump attachment" > attachment.txt
# Insert old general wiki content into new database
sqlite3 new.db ".read wiki.txt" > wikierrors.txt
sqlite3 new.db ".read attachment.txt" > attachmenterrors.txt
# Copy new database to the trac instance
cp new.db var/trac/db/trac.db

I put it all into a short shell script as that’s the best way to document it. And we’ll have to run it multiple times. Automate these things! (Yes, I’m going to speak about automating projects at this evening’s Dutch python user group meeting!)

And then I wrote a quick python script that extracted the line numbers from the wikierrors.txt file, looked up those lines in the sql dump (wiki.txt) and printed out the name of the wiki page that gave the error. All errors were about duplicate names, all but four were standard Trac WikiSomething or TracSomething names.

Another migration mostly done!

 
vanrees.org logo

Reinout van Rees

My name is Reinout van Rees and I program in Python, I live in the Netherlands, I cycle recumbent bikes and I have a model railway.

Weblog feeds

Most of my website content is in my weblog. You can keep up to date by subscribing to the automatic feeds (for instance with Google reader):