Migration of Gerrit Server Old to New

From ppwiki
Jump to: navigation, search

In this tutorial, we will be migrating our gerrit 2.13 to a new server running gerrit 2.15

Prerequisites

To complete this tutorial, you'll need the following 2 nodes

  • Database node
  • New gerrit node

Environment

Old gerrit

Server Information
OS MYSQL MYSQL version Gerrit version Authentication
Ubuntu 14.04 mysql-server 5.5.57 2.13 LDAP

New gerrit

Server Information
OS MYSQL MYSQL version Gerrit version Authentication
Debian 9 (Stretch) mysql-client 5.8 2.15 LDAP

MYSQL node

Server Information
OS MYSQL mysql-version
Ubuntu 16.04 mysql-server 5.7.22

STEP 1 On old gerrit node

Stop gerrit

Login to your gerrit server with the gerrit user or the user running gerrit. Navigate to /gerrit/bin and run

sudo ./gerrit.sh stop

Backup gerrit database

Login to your old gerrit node and backup your gerrit data base. In this case the database name is reviewdb. I use mysqldump to backup the database to a file.

mysqldum -u gerrit -p database  reviewdb > reviewdb_backup.sql

If prompt, enter you mysql password. This will backup your database reviewdb to a file called reviewdb_backup.sql

Copy the .sql file to the MYSQL server node

You have 2 options to accomplish this:

  • Option 1 : Use scp
  • Option 2 : User rsync

For this tutorial we are going to use option 1.

The syntax of the command is :

scp path_to file_to_copy remote_usernmane@remote_server:path_to_copy_the_file

To make it go faster, I create a directory on the mysql server node called files. From the old gerrit server a copy the .sql file to the mysql server node using the command below.

sudo scp /home/gerrit/reviewdb_backup.sql pp@db2007.dfw.ppnet:/home/pp/files

STEP 2: On the MYSQL server

I am not going to convert the installation of MYSQL server in this tutorial. I assume, you have already MYSQL server running on your node. login to mysql and create the database reviewdb and the user gerrit, grant all privileges to gerrit user.

Create the database and user

Login to mysql and run

mysql> CREATE DATABASE reviewdb;
mysql> CREATE USER gerrit@gerrit_hostname IDENTIFIED BY 'gerrit_password';
mysql> GRANT ALL PRIVILEGES ON reviewdb.* TO 'gerrit'@'gerrit_hostname';
mysql> FLUSH PRIVILEGES;

gerrit_password = your gerrit user password

gerrit_hostname = your new gerrit host-name or IP address

The gerrit hostname in my case is gerrit2001.dfw.ppnet, since i am using a DNS server in my environment. If you do not have a DNS server you can update your /etc/hosts or use IP address

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| reviewdb           |
+--------------------+
2 rows in set (0.00 sec)

Now we are going to make sure that the database is empty with no tables.

mysql> use  reviewdb;
Database changed
mysql> show tables;
Empty set (0.00 sec)

Check to see that the user gerrti@gerrit2001.dfw.ppnet exist and have All privileges on database reviewdb

mysql> show grants for gerrit@gerrit2001.dfw.ppnet;
+-------------------------------------------------------------------------+
| Grants for gerrit@gerrit2001.dfw.ppnet                                  |
+-------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'gerrit'@'gerrit2001.dfw.ppnet'                   |
| GRANT ALL PRIVILEGES ON `reviewdb`.* TO 'gerrit'@'gerrit2001.dfw.ppnet' |
+-------------------------------------------------------------------------+
2 rows in set (0.00 sec)

Import data to the database

Navigate to the dircectory where you saved your reviewdb_backup.sql file. I my case /home/pp/files/

Run the command below to restore data to the reviewdb database

mysql reviewdb < /home/pp/files/reviewdb_backup.sql

check that we now have the data in the database reviewdb

mysql> use reviewdb
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
+-----------------------------+
| Tables_in_reviewdb          |
+-----------------------------+
| account_external_ids        |
| account_group_by_id         |
| account_group_by_id_aud     |
| account_group_id            |
| account_group_members       |
| account_group_members_audit |
| account_group_names         |
| account_groups              |
| account_id                  |
| account_project_watches     |
| accounts                    |
| change_id                   |
| change_message_id           |
| change_messages             |
| changes                     |
| patch_comments              |
| patch_set_approvals         |
| patch_sets                  |
| schema_version              |
| system_config               |
+-----------------------------+
20 rows in set (0.00 sec)

We see we have all the data from the old mysql server imported to the new mysql server

Modify the my.cnf file

Open /etc/mysql/my.cnf make sure under [mysqld] bind-address = ip_address_of_your_mysql_node and not 127.0.0.1

bind_address = 10.192.16.32

STEP 3: On new gerrit node

Installation

Make sure that you have Ubuntu 16.04 installed on you new gerrit node and the node is up to date.

Create a file call gerrit_install.sh and copy and past the content of the script below to it.

#!/bin/bash
file="gerrit.config"
##Installating updates
sudo apt-get update
sudo apt-get -y upgrade
##create a user called gerrit
sudo adduser gerrit --gecos "First Last,RoomNumber,WorkPhone,HomePhone" $
echo "gerrit:your_gerrit_user_password" | sudo chpasswd
##Add the user gerrit to sudo group
sudo adduser gerrit sudo
##Crete a directory named gerrit
sudo mkdir /home/gerrit/gerrit
##install git and java
sudo apt-get -y install git-all
sudo apt-get -y install default-jdk
##Install Apache server
sudo apt-get -y install apache2
#install php7
sudo apt-get -y install php7.0 libapache2-mod-php7.0
#Install mysql-client
sudo apt-get -y install mysql-client
#Insalling Gerrit
cd /tmp/
wget https://www.gerritcodereview.com/download/gerrit-2.15.2.war
sudo java -jar gerrit-2.15.2.war init -d /home/gerrit/gerrit
cd /home/gerrit/gerrit/etc
cat > new_gerrit.config <<EOF
[gerrit]
 basePath = git
       serverId = 836442ec-5c53-4e68-be8a-1080673f5e21
       canonicalWebUrl = http://gerrit2001.dfw.ppnet:8080/
[database]
       type = mysql
       hostname = db2007.dfw.ppnet
       database = reviewdb
       username = gerrit
[auth]
 type = LDAP
[ldap]
       server = ldap://ldapsrv.dfw.ppnet
       referral = follow
       accountBase = ou=users,DC=dfw,DC=ppnet
       groupBase = ou=groups,DC=dfw,DC=ppnet
[receive]
       enableSignedPush = false
[sendemail]
       smtpServer = localhost
[container]
       user = root
       javaHome = /usr/lib/jvm/java-8-openjdk-amd64/jre
[sshd]
       listenAddress = *:29418 
[httpd]
listenUrl = http://*:8080/
[cache]
       directory = cache
EOF
ln -f gerrit.config gerrit.config.old
mv -f new_gerrit.config $file
cd /home/gerrit/gerrit/bin/
sudo ./gerrit.sh stop
sudo java -jar /home/gerrit/gerrit/bin/gerrit.war init -d /home/gerrit/gerrit
cd /home/gerrit/gerrit/bin
sudo ./gerrit.sh start


Save the file and close it.

Make the file executable

sudo chmod +x gerrit_install.sh

Run the executable

sudo ./gerrit_install.sh

Seat back and relax until Gerrit starts asking some configuration questions. The first one will be:

Create '/home/gerrit/gerrit'   [Y/n]?

Just hit enter on your keyboard for all the questions and move to the next step of the tutorial (Configuration)

Configuation

Once the script gets at

sudo java -jar /home/gerrit/gerrit/bin/gerrit.war init -d /home/gerrit/gerrit

It will reconfigure gerrit to use the mysql database backup. The only thing you need to do at this step is to enter the user gerrit password to connnect to the remote mysql server node. On all the others questions, just hit enter on your keyboard.

Testing login

open a broswer and type in

your_gerrit_server_Canonical Web URL:8080

You will see the page below

Gerrit home.png

click on sign in at the rght of the page. You should get the page below.

Gerrit home2.png

Since I am using LDAP, All my users from the old gerrit server should be able to login to the new gerrit server

Gerrit projects.png

You can see that in the image above, there are not projects listed on the page or on the old gerrit I had some project. How to fix this? See next session.

Step 4: Rsync GIT repos

Copy your GIT repos from old gerrit server to new gerrit server.

On your new gerrit server create a directory called files. I create mine at /home/pp/files and make it 777

sudo mkidr files
sudo chmod 777 files
  • On old gerrit server

Login to your old gerrit server. navigate to /home/gerrit/gerrit/git

cd /home/gerrit/gerrit/git
gerrit@gerritsrv:~/gerrit/git$ ll
total 24
drwxr-xr-x  6 root root 4096 May 26  2017 ./
drwxr-xr-x 14 root root 4096 Feb  9  2017 ../
drwxr-xr-x  7 root root 4096 Feb  9  2017 All-Projects.git/
drwxr-xr-x  7 root root 4096 Feb  9  2017 All-Users.git/
drwxr-xr-x  7 root root 4096 Feb  9  2017 dns.git/
drwxr-xr-x  3 root root 4096 May 26  2017 operations/

we see that we have a total of 4 git repos. We are going to sync all 4 git repos to our new gerrit server. We are going to use the rsync command this time. Note: you need to delete first the content of /home/gerrit/gerrit/git/ on the new server

sudo rsync -uav --partial --progress /home/gerrit/gerrit/git/* pp@gerrit2001.dfw.ppnet:/home/pp/files/

This command will copy everything under the git repertory to the new gerrit server under the user pp in the repertory files.

  • On New gerrit server

login to your new gerrit server. If gerrit is running, stop gerrit.

cd /home/gerrit/gerrit/bin
sudo ./gerrit.sh stop

Navigate to the directory where you copied the files. In my case /home/pp/files.

Copy or move the files from that location to /home/gerrit/gerrit/git/

sudo cp -r * /home/gerrit/gerrit/get

Start back gerrit

cd /home/gerrit/gerrit/bin
sudo ./gerrit.sh start

Log back to gerrit WEB GUI you will see now all projects listed. (see image below)

Gerrit projeect2.png

STEP 5: Open/merged code and Users SSH keys

on the old gerrit server I have no open code but I do have some codes that were already merged but on the new gerrit server those codes are not showing under the "status:merged" session. (see image below) When login to the reviewdb database all the data about all merged code are there but there are not showing in the web GUI.

How to fix this?

Gerrit merged code.png

On old gerrit server

login to your server and navigate to /home/gerrit/gerrit/index and copy the repertory changes_00XX (in my case XX=32) to the new gerrit server

sudo rsync -uav --partial --progress /home/gerrit/gerrit/index/changes_0032/ pp@gerrit2001.dfw.ppnet:/home/pp/files/changes_0032

On new gerrit server

login to new server and navigate to /home/gerrit/gerrit/index and delete the repertory changes_00XX (in my case XX=48)

sudo rm -rf /home/gerrit/gerrit/index/changes_0048

Move the new changes_00XX from the old gerrit server to the same location

sudo mv /home/pp/files/changes_003 /home/gerrit/gerrit/index/

Now on our web GUI we can see all merged codes

Gerrit merged.png

This step also takes care of showing all user's SSH keys on the WEB GUI

Gerrit ssh.png

Conclusion

In this tutorial we convert the migration of gerrit 2.13 to gerrit 2.15 from one server to another server. The old server was running gerrit and mysql database on the same server. For the new install, we separate gerrit and mysql database. At the end we sync the data from the old server with the new server.