GitLab Official Backup and Restore
This solution is based on GitLab's official backup and restore approach. For detailed information, please refer to the GitLab official documentation.
TOC
Applicability
This solution is only applicable to GitLab instances running version 17.8 or later that are configured with object storage.
If your GitLab instance has not been configured with object storage, GitLab provides a data migration solution. You can refer to this solution to migrate your data first, then use this solution for backup and restore.
How to Check if Object Storage is Configured
If the enabled field is true and the connection field is not empty, it indicates that the instance has object storage configured.
Terminology
Prerequisites
- Deploy MinIO Object Storage: The official backup and restore solution relies on object storage to save backup data, requiring a pre-deployed MinIO instance. ACP provides
MinIO Object Storagefor . - Install mc Command-Line Tool: mc is MinIO's command-line tool for managing MinIO instances. For installation instructions, refer to the MinIO official documentation.
- Install kubectl Command-Line Tool: kubectl is Kubernetes' command-line tool for managing Kubernetes clusters. For installation instructions, refer to the Kubernetes official documentation.
For convenience in subsequent operations, please set the environment variables first:
Execute the following commands to configure the mc command-line tool and test the connection:
If you can successfully ping the MinIO instance, it indicates that mc is configured correctly.
Backup
Prerequisites
Create Buckets
You need to create two buckets:
- Bucket for storing backup data, named:
gitlab-backups - Bucket for storing temporary data during backup, named:
gitlab-backups-tmp
Execute the following commands to create the buckets:
Execute the following command to verify that the buckets were created successfully:
Manual Backup
Deploy Toolbox Component
To perform an official GitLab backup, you must run the backup command inside the toolbox pod. During this process, backup files will be uploaded to object storage. Therefore, you need to prepare an object storage configuration file in advance. Run the following script to generate the required configuration file:
Execute the following command in the cluster where GitLab is located to edit the GitLab instance CR:
Edit the following yaml configuration first according to the comments, then add it to the CR:
After updating the GitLab CR, it will automatically deploy a new toolbox component. Use the following command to check if the toolbox component is deployed successfully:
If the pod status is Running, it indicates that the toolbox component is deployed successfully.
Execute Backup
Use the following command to enter the terminal environment of the toolbox pod:
Execute backup:
Backup process takes some time, use the following command to check backup log to confirm backup progress:
When the program completes successfully, the backup process ends.
Backup file name is dynamically generated based on backup time and version information, for example 1751272314_2025_06_30_17.11.4_gitlab_backup.tar. The 1751272314_2025_06_30_17.11.4 is the unique identifier (backup ID) of this backup. When executing restore operation, you need to provide the corresponding backup ID.
Scheduled Backup
GitLab scheduled backup is completed through the toolbox component. Unlike manual backup, scheduled backup uses Crontab to implement periodic backup.
Execute the following command in the cluster where GitLab is located to edit the GitLab instance CR:
Edit the following yaml configuration first according to the comments, then add it to the CR:
How to Configure Backup Cycle
Crontab rule consists of five time fields, separated by spaces, from left to right:
- Minute (Minute): Which minute of the hour to execute the task, range 0-59
- Hour (Hour): Which hour of the day to execute the task, range 0-23
- Day of the month (Day of the month): Which day of the month to execute the task, range 1-31
- Month (Month): Which month of the year to execute the task, range 1-12 (You can also use abbreviated month names like Jan, Feb, Mar, etc.)
- Weekday (Day of the week): Which day of the week to execute the task, range 0-7 (0 and 7 both represent Sunday, 1 represents Monday, and so on. You can also use abbreviated weekday names like Sun, Mon, Tue, etc.)
Example:
- Execute at 3:00
AM every day:
0 3 * * * - Execute at 3:00
AM on the 1st and 15th of each month:
0 3 1,15 * * - Execute every 10 minutes:
*/10 * * * *
Wait for GitLab to trigger a backup, then you can verify backup files.
Verify Backup Files
Execute the following command to check if backup files have been uploaded to object storage:
If you can successfully list backup files, it indicates that backup is successful.
Restore
Prerequisites
Select a Backup to Restore
Use the mc command to get the backup file list:
Based on the date information in the backup file name, select a backup you want to restore, and copy the backup ID from the backup file name for later use, such as 1751272314_2025_06_30_17.11.4.
Determine GitLab Instance Restore Method
There are two choices for restoration:
- Directly restore on the source instance, which will overwrite the instance data with the backup data
- (Recommended) Deploy a new instance to restore data, the new instance needs to meet the following requirements:
- The new instance must have object storage enabled
- The new instance should deploy toolbox component, and configure the object storage configuration same as the source instance
Restore Operations
The following operations are all performed on the target instance.
Please set the following environment variables first:
Stop Workloads
To ensure the restore operation proceeds smoothly, you need to stop the sidekiq and webservice components during restoration.
Execute Restore
Use the following command to enter the terminal of the toolbox pod:
Before restoring the database, all existing tables will be removed to avoid future upgrade problems. Be aware that if you have custom tables in the GitLab database, these tables and all data will be removed.
Enter the following command in the terminal to execute the restore, where backup ID needs to be replaced with the desired backup ID, such as 1751272314_2025_06_30_17.11.4:
When the program completes successfully, the restore process ends.
Notes for Restoring from New Instance
If restoring in a newly deployed instance, after completing the above steps, you need to perform the following additional steps:
Restore Rails Secrets
You need to update the Rails secrets of the new instance to match those of the source instance.
Get the Rails secrets content from the source instance:
Update the Rails secrets of the new instance. Please refer to How to Set Rails Secrets.
Switch Domain Name
If the source instance was deployed using a domain name, after restoring from the new instance, you need to switch the domain name of the new instance to that of the source instance to restore business access. Please refer to Configure Instance Network Access to modify the instance access domain name.
Restore Workloads
The sidekiq and webservice components were stopped during restoration and need to be restarted after recovery.
Verify Restore
After waiting for the instance status to return to normal, log in to GitLab to check if the data has been restored successfully. Check items include but are not limited to:
- Groups
- Repositories
- Users
- Merge Requests