This is an archived version of the documentation for SonarQube-7.3.
See the Latest Documentation for current functionality.

Sonar DB Copy Tool

The Sonar DB Copy Tool is a commercial tool available to Enterprise Editionimages/download/attachments/11641549/onde-sonar-16.png customers. The goal of this tool is to help you on the migration process from one DB vendor to another one. Let's imagine you used to have your SonarQube instance running on Oracle and you want to migrate to MySQL without loosing all your historical analysis. In that context the Sonar DB Copy Tool is there for you. In the following lines we will talk about source and target SonarQube database instances. The source instance is the one running the DB vendor you want to discard and the target the one running the new DB.

The Sonar DB Copy Tool will basically run as follows:

  • connect to the source and target databases

  • read the data of the source database table by table

  • save the data into the target database table by table

  • recreate the sequences, indexes, ... on the target database

Installation

The Sonar DB Copy Tool is provided as a standalone JAR file. It must not be installed on your source or target SonarQube instance. Put the JAR wherever your want in your machine, the only prerequisites is that this machine must be authorized to access your both source and target SonarQube databases.

The version of the JAR to use must be at least 1.3.2.560

DB Copy Preparation Phase

The goal is to ask your SonarQube Server to create for you the tables (without content) and to have at the end a database schema equals on the source and target database.

  1. Your source and target database must be up and running

  2. Your SonarQube instance must be temporary stopped during the preparation and the running phase

  3. On your target database, create an empty schema (without the tables)

  4. Configure your SonarQube instance so it connects to the target database. (change properties in your conf/sonar.properties)

  5. Start your SonarQube that is going to connect to your empty target database

  6. Once your instance is up and running, you MUST stop it and delete the ElasticSearch index under <sonar_install_dir>/data/es5

  7. At this step, you have on your source and target database the exact same list of tables.

  8. Refresh the Database Statistics on the target database before restarting SonarQube

SonarQube version

If using a separate SonarQube instance for steps #4, #5 and #6, make sure it runs the same SonarQube version as the original one.

DB Copy Running Phase

Execute the Command :

java -jar sonar-db-copy-1.3.2.560-jar-with-dependencies.jar

Parameters:

Name

Value

Required ?

Description

-driverDest

<jdbc driver>

OPTIONAL

JDBC Driver of the target database

-driverSrc

<jdbc driver>

OPTIONAL

JDBC Driver of the source database

-help

Print this parameters help

-urlSrc

<jdbc url>

REQUIRED

JDBC URL of the source database

-userSrc

<login>

REQUIRED

Username of the source database

-pwdSrc

<password>

REQUIRED

Password of the source database

-urlDest

<jdbc url>

REQUIRED

JDBC URL of the target database

-userDest

<login>

REQUIRED

Username of the target database

-pwdDest

<password>

REQUIRED

Password of the target database

-T

OPTIONAL

Comma separated list of tables to migrate

Example of Execution

First sonar-db-copy verifies if URLs can be reached and the database versions :

images/download/attachments/6954416/image2015-11-219-32-9.png

When the versions are different: the application stops.

images/download/attachments/6954416/image2015-11-219-32-27.png

Sometime when you have restarted the copy, the destination database version is 0 : this is not a problem, the copy will continue.

images/download/attachments/6954416/image2015-11-219-32-41.png

Then it searches tables in source and destination database:

images/download/attachments/6954416/image2015-11-219-32-59.png

If there are missing tables, you will read this log:

images/download/attachments/6954416/image2015-11-219-33-21.png

Second sonar-db-copy truncates tables in target database and indicates the number of tables purged:

images/download/attachments/6954416/image2015-11-219-34-7.png

Of course, the tables missing can not be purged:

images/download/attachments/6954416/image2015-11-219-34-7.png

Third, sonar-db-copy reproduces data from source to destination and adjusts the sequence of destination database after the copy:

images/download/attachments/6954416/image2015-11-219-34-31.png

If there are some missing tables:

images/download/attachments/6954416/image2015-11-219-34-44.png

If some errors appears during the copy it will NOT stop but displays:

images/download/attachments/6954416/image2015-11-219-35-3.png

At the end sonar-db-copy resume the difference between source and destination database.

images/download/attachments/6954416/image2015-11-219-35-21.png