On this page

1. DB Copy - preparation phase2. DB Copy - execution phase

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, the SonarQube DB Copy Tool will help. DB Copy is preferred for database migration because it does SonarQube-specific checks, ensures data consistency, and outputs meaningful logs.

On this page, source refers to your current database and target refers to the database you are moving to.

1. DB Copy - preparation phase

DB Copy only copies data, not the schema. This is why the purpose of this step is to populate target with an empty SonarQube schema. For this, you have to install a temporary SonarQube instance.

  1. Make sure you can connect to your target database.
  2.  Download a SonarQube that matches the version and edition of your source instance.
  3. Unzip SonarQube and put it in a relevant place on the machine.
  4. Configure SonarQube to connect to your target database (ie. provide JDBC parameters in the $SONAR_HOME/conf/sonar.properties file).
  5. Start SonarQube using the script matching your operating system:
    • On Linux: $SONAR_HOME/bin/linux-x86-64/sonar.sh start
    • On macOS: $SONAR_HOME/bin/macosx-universal-64/sonar.sh start
    • On Windows: %SONAR_HOME\bin\windows-x86-64\StartSonar.bat
  6. Verify that the SonarQube schema was correctly created. To do this, look at the logs/web.log file to see the line "Executed DB migrations: success". Once this is done, it means that your target database had been populated with the SonarQube schema.
  7. Stop SonarQube:
    • On Linux: $SONAR_HOME/bin/linux-x86-64/sonar.sh stop
    • On macOS: $SONAR_HOME/bin/macosx-universal-64/sonar.sh stop
    • On Windows: terminate the StartSonar.bat script
  8. You can now delete this temporary SonarQube instance.

2. DB Copy - execution phase

Because this step is about copying data from source to target, the overall performance makes a difference. Make sure you execute this on a powerful machine that has fast network access to both database servers.

  1. Unzip the DB Copy package provided by SonarSource Support on the machine where it will be executed. Java is required.
  2. Stop the SonarQube instance connected to your source database. This is to ensure that we don't have records being inserted/updated while copying.
  3. Execute the base command with the correct parameters. See below how to do it.
  4. If you see something else other than the success message **THE COPY HAS FINISHED SUCCESSFULLY** please open a SonarSource Support ticket and provide the complete DB Copy logs for investigation (logs are just the standard output of the tool).

Base command and parameters

java -jar sonar-db-copy-1.5.0.1201-jar-with-dependencies.jar
ParameterDescriptionRequired
-helpPrint this help informationno
-urlSrc JDBC_URLJDBC URL of the source databaseyes
-userSrc USERNAMEUsername of the source databaseyes
-pwdSrc PASSWORDPassword of the source databaseyes
-urlDest JDBC_URLJDBC URL of the target databaseyes
-userDest USERNAMEUsername of the target databaseyes
-pwdDest PASSWORDPassword of the target databaseyes

Here is an example of a copy from an Oracle to a Postgres database. Note that each parameter is on one line and there are \ (backslash) characters to continue the command. While this works on most shell command-line interpreters, it is not necessarily the case. Use only one line and remove backslashes in that case.

java \
-jar sonar-db-copy-1.5.0.1201-jar-with-dependencies.jar \
-urlSrc jdbc:oracle:thin:@10.18.51.1:1521/XEPDB1 \
-userSrc sonar \
-pwdSrc 05xlAz1EhgQb9Pl8 \
-urlDest jdbc:postgresql://10.10.1.138/sonarqube \
-userDest sonar \
-pwdDest Ck23L1OpqF4BdwJv

© 2008-2022, SonarSource S.A, Switzerland. Except where otherwise noted, content in this space is licensed under a Creative Commons Attribution-NonCommercial 3.0 United States License. SONARQUBE is a trademark of SonarSource SA. All other trademarks and copyrights are the property of their respective owners.

Creative Commons License