-
Notifications
You must be signed in to change notification settings - Fork 7
iii. Using Sonar Data Migrator
When you extract Data migrator tool zip file, you will see below structure.
The sonar data migrator tool need first setup of source and target sonar database and need some temp table created on target database for tracking migrated data.
- sourceDriver: JDBC Driver class for source sonar database. e.g. for oracle oracle.jdbc.driver.OracleDriver for postgres org.postgresql.Driver
- sourceConnectionString: JDBC connection string for source sonar database. e.g. for oracle jdbc:oracle:thin:@localhost:1521/xe for postgres jdbc:postgresql://localhost:5432/sonar_new
- sourceUserName: DB username for source sonar database
- sourcePassword: DB password for source sonar database
- targetDriver: JDBC Driver class for target sonar database
- targetConnectionString: JDBC connection string for target sonar database
- targetUserName: DB username for target sonar database
- targetPassword: DB password for target sonar database
In order to track migrated data and allow resume functionality, some tables needed to be available on target sonar database. Execute init.sql file on target database to create those tables. You can drop them and recreate again on every new report migration or you may continue with same tables for all migration. However, you should not drop them till all data for any sonar report is migrated.
There are readymade scripts for windows and linux environment available to execute tool. You might need to configure full path for java executable in case it is not defined in PATH environment variable.
Windows
java -classpath .;sonar-data-migrator-1.0.0.jar com.worldline.awltech.sonar.SonarMigrationUtil %1 %2
Linux
java -classpath .:sonar-data-migrator-1.0.0.jar com.worldline.awltech.sonar.SonarMigrationUtil $1 $2
Once setup is done, run the tool by calling script. If you run without passing any argument, it will show you usage message.
Usage: java -classpath .;sonar-db-migration-<version>.jar com.worldline.awltech.sonar.SonarMigrationUtil <migration Type either users/data> <project key>
OR
Usage: ./script.sh <migration Type either users/data> <project key>
There are basically 2 arguments
- Run the bat/sh script passing users as argument for migration of users. This is required only one time as it will migrate all users from old sonar server to new sonar server.
- Run the bat/sh script passing data as first argument and project key as per "Key" value in sonar report as second argument. If key is not passed, it will work for all projects in db (after confirmation).
![Sonar Project Info](https://github.com/awltech/resources/raw/master/sonar-data-migrator/Sonar Project Info.png)
e.g.
[www@myserver /home/user]$ ./script.sh users
and
[www@myserver /home/user]$ ./script.sh data com.worldline.awltech:myBranch
Note that script is idempotent meaning that running it multiple times doesn't create any issue as data already migrated won't migrate again.
All logs are by default generated under logs folder. It can be configured under log4j.xml file provided in zip.
Once sonar data migration tools run successfully, new sonar server data will be updated. However, the sonar dashboard will still refer old data, even after refresh. This is because, the statistic shown on dashboard is calculated only during analysis and it's not dynamic data. In order to get updated data, you need to run sonar analysis again on new sonar server. It is ok if by this time code is changed. On running fresh analysis, sonar will consider all false positives we have marked during data migration and you can see updated dashboard.
Now you have new sonar server ready for your project and can continue analysis on it.