Term | Description |
---|---|
PG | PostgreSQL database, used by SonarQube to store core data |
ES | Elasticsearch search engine, used by SonarQube for searching |
This document applies to SonarQube 9.9.5 and above versions.
This document has been verified with SonarQube 9.9.5. While the procedures should theoretically work with version 25.1.0, they have not yet been practically validated with this version. Please test in a non-production environment first if you're using SonarQube 25.1.0.
SonarQube data primarily consists of two parts:
Since Elasticsearch data can be regenerated from the database, we only need to backup the PostgreSQL database to ensure data security.
Based on the type of PostgreSQL database you use, there are two backup methods:
If you are using a PostgreSQL instance provided by the platform, you can directly use the platform's backup feature:
Backup and Recovery
tabThe platform PG instance supports automatic backup, which can be enabled during the backup configuration process. For specific operation methods, refer to the Platform PG Backup and Recovery documentation.
After completing the backup configuration, you can:
Create Backup
to perform an immediate backupIf using a self-built database, you need to use the pg_dump
tool for backup. Here are the basic operation steps:
Parameter description:
Parameter | Description |
---|---|
-U postgres | Database username |
-h 127.0.0.1 | Database address |
-p 5432 | Database port |
-d sonar | Database name |
-f sonar.dump | Backup filename |
Tip: You can use crontab
to implement automatic scheduled backups.
Data recovery requires two steps:
Important note: It is recommended to create a new SonarQube instance rather than modifying the database configuration of the original instance, which can avoid data loss due to misoperation.
Backup and Recovery
tabDatabase Recovery
wizard to complete the restorationNote: The recovery operation will create a new database instance.
Self-built PG instances need to complete the recovery operation on your own. The following recovery commands are for reference only:
Command parameter description:
Parameter | Description |
---|---|
-U postgres | Database username |
-h 127.0.0.1 | Database address |
-p 5432 | Database port |
-d sonar_new | New database name |
-f sonar.dump | Backup filename |
If you can see the list of data tables, the recovery is successful:
Refer to the SonarQube deployment documentation to create a new SonarQube instance.
Please note the following key points:
For methods to configure database access credentials, please refer to the SonarQube Deployment Documentation.