How to move Quality Profiles, Quality Gates and Rules from one SOnarQube to another

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
  • what are you trying to achieve
  • what have you tried so far to achieve this

Hi All,
Can anyone please suggest how we can copy Quality Profiles, Quality Gates and Rules from one SonarQube setup to another? I understand we can go to each Quality Profile/Gate, do a backup and the restore it in the target SonarQube but since we have 100s of profiles and several gates, is there any API or automation which we can use?

Thanks.

Hi @Umang,

Backup/restore is possible with Quality Profiles, but not with Quality Gates; you’ll need to recreate the QG manually. For QP, you can use the Web API calls

  • api/qualityprofiles/backup and
  • api/qualityprofiles/restore

Full documentation by following the Web API link in the footer of any SonarQube page.

This might be a good opportunity to do some cleanup before you copy the data :slight_smile:

I hope this helps – let me know if you run into any problems.

Regards,

Cameron.

I used the following on my windows command prompt:
curl -i -u “admin:password” http://SonarServer/api/qualityprofiles/backup

This is what I get as result but no xml file created:
HTTP/1.1 200
Date: Tue, 01 Jun 2021 08:09:39 GMT
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Cache-Control: no-cache, no-store, must-revalidate
Content-Type: application/xml
Content-Length: 0

Please let me know if I am using the API incorrectly.

Also, is there any guide on what all do we need to backup/restore when we are shifting from one SonarQube setup to another (e.g. moving from DataCenter to AWS)?

Thanks.

Hi @Umang,

You’ll need some additional parameters, since QP are backed-up one at a time. So you’re going to want something like:

curl -u "admin:password" 'http://SonarServer/api/qualityprofiles/backup?language=java&qualityProfile=myQP'

Depending which OS you’re on, you’ll need to experiment with single and double quotes around the UR and some character escaping so your shell doesn’t misinterpret the ? and & characters.

If the goal is to shift your entire SonarQube instance, you could just backup then restore your database (assuming you’re moving to the same database type in AWS). This will be easier than trying to copy all your QP/QG anyway.

Regards,

Cameron.

Thanks Cameron.
We are changing DB from Oracle to postgres. Are there any recommended steps from SonarQube for the same?

Hi @Umang,

OK, that’s a little more complex. If you have a SonarSource support contract, you can request the DB Copy tool via our support team to move from Oracle to Postgres. If not, then you’ll need to create the Postgres version from scratch and use the API calls we discussed earlier in a script to export/import your QP.

Regards,

Cameron.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.