Backup and Recovery
TOC
TerminologyScopeOverviewBackupMethod 1: Backing up Platform-Provided PostgreSQL Instance (Recommended)Method 2: Backing up Self-Built PostgreSQL InstanceRecoveryDatabase RecoveryRestoring Platform PostgreSQL InstanceRestoring Self-Built PostgreSQL InstanceDeploying a New SonarQube InstanceTerminology
Scope
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.
Overview
SonarQube data primarily consists of two parts:
- PostgreSQL database data (core data)
- Elasticsearch data (search data)
Since Elasticsearch data can be regenerated from the database, we only need to backup the PostgreSQL database to ensure data security.
Backup
Based on the type of PostgreSQL database you use, there are two backup methods:
- If using the PG instance provided by the platform (recommended when deploying SonarQube instances):
- You can directly use the platform's built-in database backup feature
- Supports manual and scheduled automatic backups
- Simple operation with good user experience
- If using a self-built PG instance, you need to complete the backup yourself
Method 1: Backing up Platform-Provided PostgreSQL Instance (Recommended)
If you are using a PostgreSQL instance provided by the platform, you can directly use the platform's backup feature:
- Go to the Data Services view
- Find your PostgreSQL instance
- Open the
Backup and Recoverytab - Follow the page prompts to configure the backup
The 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:
- Click
Create Backupto perform an immediate backup - Check the backup status in the backup records
Method 2: Backing up Self-Built PostgreSQL Instance
If using a self-built database, you need to use the pg_dump tool for backup. Here are the basic operation steps:
Parameter description:
Tip: You can use crontab to implement automatic scheduled backups.
Recovery
Data recovery requires two steps:
- Restore the PostgreSQL database
- Deploy a new SonarQube instance and connect it to the restored database
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.
Database Recovery
Restoring Platform PostgreSQL Instance
- Go to the Data Services view
- Find the target PostgreSQL instance
- Open the
Backup and Recoverytab - Follow the
Database Recoverywizard to complete the restoration
Note: The recovery operation will create a new database instance.
Restoring Self-Built PostgreSQL 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:
-
Create a new database:
-
Import backup data:
-
Verify recovery results:
If you can see the list of data tables, the recovery is successful:
Deploying a New SonarQube Instance
Refer to the SonarQube deployment documentation to create a new SonarQube instance.
Please note the following key points:
- The newly deployed SonarQube version must be the same version as the original instance
- When deploying, you need to correctly configure the database connection information, which is the database you created in the database recovery step
For methods to configure database access credentials, please refer to the SonarQube Deployment Documentation.