SonarQube DB Copy Tool
The SonarQube DB Copy Tool is available to customers with Sonar commercial support.
We provide this tool to help you migrate your SonarQube database from one database vendor to another. For example, if you've been using your SonarQube instance with Oracle and want to migrate to PostgreSQL without losing your analysis history, the SonarQube DB Copy Tool can help.
Here's an overview of the general procedure:
- 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, and more, on the target database.
Installation
The SonarQube DB Copy Tool is provided as a standalone JAR file. You need to make sure you're meeting the following conditions:
- The JAR file must not be installed in your source or target SonarQube instances. You can put the JAR file anywhere on your machine as long as your machine is authorized to access your source and target SonarQube databases.
- You must be using at least version 1.3.3.627 of the JAR file.
DB Copy preparation phase
To prepare for the DB Copy Tool, you need to prepare the target instance by setting up a SonarQube schema and populating it with the necessary tables so that your source and target instances have the same database schema.
- Make sure your target database is up and running.
- On your target database, create the
sonar
schema. - 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 (indicating 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 the exact same list of tables in your source and target databases.
DB Copy run phase
To run the DB Copy Tool, perform the following steps:
- 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.
Base command
java -jar sonar-db-copy-1.3.3.627-jar-with-dependencies.jar
Parameters
Name | Description | Required |
-help | Print this help information | no |
-urlSrc | JDBC URL of the source database | yes |
-userSrc | Username of the source database | yes |
-pwdSrc | Password of the source database | yes |
-urlDest | JDBC URL of the target database | yes |
-userDest | Username of the target database | yes |
-pwdDest | Password of the target database | yes |
-driverDest | JDBC Driver of the target database | no |
-driverSrc | JDBC Driver of the source database | no |
-T | Comma-separated list of tables to migrate | no |
Execution examples
First, sonar-db-copy
verifies if URLs can be reached and the database versions:
When the versions are different, the application stops.
Sometimes when you have restarted the copy, the destination database version is 0
. This is not a problem, and the copy will continue.
Then it searches tables in the source and destination databases:
If there are missing tables, you will see this log:
Then, sonar-db-copy
truncates tables in the target database and indicates the number of tables purged. Of course, the tables missing can not be purged:
Next, sonar-db-copy
reproduces data from source to destination and adjusts the sequence of the destination database after the copy:
If there are some missing tables, you'll see the following warning:
If errors appear during the copy, the process does NOT stop but the errors are displayed:
Finally, sonar-db-copy
reiterates the difference between the source and destination databases. An error message is displayed if the databases are different.
Was this page helpful?