I have MainGerritServer
which hosts many projects.
Also, I have RogueGerritServer
which also hosts many projects.
I'm looking for a way to move a ProjectA
from RogueGerritServer
to MainGerritServer
while preserving both Git commit history as well as the Gerrit review history.
For example, I want to import Android project's Gerrit history onto my own Gerrit server, so that when I work on a forked version of Android, I can look up the Gerrit history on my local server. What's the best way to do this?
If it were a simple Git installation, I would simply clone ProjectA
into my computer then push to MainGerritServer
. Does a Gerrit based project work the same way?
I'm concerned because Gerrit installation uses a database on the background, and I'm not sure whether I need to also migrate the information in the database. I saw many threads about taking a database dump and moving it to a brand new server. However, I'm trying to move just one project so taking a DB dump doesn't seem appropriate. The closest answer I saw was this which is still not exactly what I'm looking for.
I would appreciate any help, especially if you can show me whether I'm misunderstanding how to approach this.
Thank you
I've been moving a lot of git projects around lately and although I've mostly been moving from Gerrit (due to department fiat, Gerrit's a fine choice IMO) this should work the same and is relatively easy. Moving the Gerrit history, however will be more difficult.
Here's how to move a repo:
In your local clone of the project you want to move, add the new project location as a new remote:
git remote add NewGerrit ssh://NewGerritServer:29418/NewProject
push to the new remote. To push the full history do:
git push --all NewGerrit
You can also set it to automatically track the new repo by adding a -u flag:
git push --all -u NewGerrit
Migrating the Gerrit database stuff is a much bigger job and honestly I'd suggest you simply forgo it unless absolutely necessary. You can get an idea of what's involved by accessing the database directly through Gerrit's own (terrible) query language, GSQL. It's a lot like mysql except more temperamental and lacking a lot of features.
ssh -p 24981 HOSTNAME gerrit gsql
This will give you a gsql prompt. Try this:
gerrit> SHOW TABLES;
The caps, at least in the version of Gerrit I have access to, are important. (Mine is admittedly outdated.) This will show you around 29 tables and your project history is spread throughout them.
According to this posting from Shawn Pearce (Gerrit project lead) you would need to copy the database to a new db server then manually remove all other projects using SQL. You could then dump the remaining data and import it to the other Gerrit server. NOTE THE CAVEAT: there could be a collision of change_id values. He does suggest a work around for this however:
You could find out the max change_id of the incoming set, go manually bump the destination server's change_id_seq to reserve sufficient id space, then bump all of the old change_ids by some base value so they are in a unique space in the destination... and finally load the rows to the destination.
So it can be done. It is a pain in the hind quarters.
There is also now an importer plugin that can be used to migrate a git repository and all reviews from one server to another. It works with Gerrit version 2.11 and later.
More documentation:
The importer plugin is downloadable from the (unofficial) CI server: master version, stable-2.12 version, stable-2.11 version.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With