SonarQube DB Copy Tool
The SonarQube DB Copy Tool is available to customers with SonarSource support.
This tool is provided to help you migrate your SonarQube database from one DB vendor to another. If, for instance, you've been using your SonarQube instance with Oracle and you want to migrate to PostgreSQL without loosing your analysis history, the SonarQube DB Copy Tool is what you need.
In the following lines we will talk about "source" and "target" SonarQube database instances. The source instance is the database you want to discard and the target is the one you want to move to.
The procedure is basically as follows:
- connect to both the source and target databases
- read the data from the source database table by table
- save the data into the target database table by table
- recreate the sequences, index, ... on the target database
The SonarQube DB Copy Tool is provided as a standalone JAR file. It must not be installed in your source or target SonarQube instances. Put the JAR wherever your want on your machine, the only prerequisite is that this machine must be authorized to access your source and target SonarQube databases.
The version of the JAR to use must be at least 184.108.40.2067
DB Copy Preparation Phase
In the preparation phase, you ready the target database by setting up SonarQube schema and populating it with the necessary tables so that you end up with the same database schema in the source and the target.
- Make sure your target database is up and running
- On your target database, create the
- Download and expand a copy of SonarQube that exactly matches the version you're running.
- Configure your SonarQube copy to connect to the target database. (If you've placed your SonarQube copy on the same server that runs your primary SonarQube instance, you'll also need to configure non-default ports for your copy SonarQube instance.)
- Start your copy SonarQube instance. It will connect to your empty target and populate the schema.
- Once your copy instance is up and running (this indicates that the schema is fully populated), you can stop and delete it.
- Refresh the Database Statistics on the target database before restarting SonarQube
At this point, you have in your source and target databases the exact same lists of tables.
DB Copy Run Phase
There are only four steps in this phase:
- Stop your primary SonarQube instance.
- Execute the base command jar with the correct parameters.
- Update your primary SonarQube instance's configuration to point to the target DB
- Restart your primary SonarQube instance.
java -jar sonar-db-copy-220.127.116.117-jar-with-dependencies.jar
|Print this parameters help||no|
|JDBC URL of the source database||yes|
|Username of the source database||yes|
|Password of the source database||yes|
|JDBC URL of the target database||yes|
|Username of the target database||yes|
|Password of the target database||yes|
|JDBC Driver of the target database||no|
|JDBC Driver of the source database||no|
|Comma separated list of tables to migrate||no|
First sonar-db-copy verifies if URLs can be reached and the database versions:
When the versions are different, the application stops.
Sometime when you have restarted the copy, the destination database version is 0. This is not a problem, the copy will continue.
Then it searches tables in source and destination database:
If there are missing tables, you will read this log:
Second sonar-db-copy truncates tables in target database and indicates the number of tables purged:
Of course, the tables missing can not be purged:
Third, sonar-db-copy reproduces data from source to destination and adjusts the sequence of destination database after the copy:
If there are some missing tables:
If errors appear during the copy, the process does NOT stop but the errors are displayed:
At the end sonar-db-copy reiterates the difference between source and destination database. An error message is displayed if the databases are different.