doc/administration/backup_restore/backup_cli.md
{{< details >}}
{{< /details >}}
{{< history >}}
{{< /history >}}
This tool is under development and is ultimately meant to replace the Rake tasks used for backing up and restoring GitLab. You can follow the development of this tool in the epic: Next Gen Scalable Backup and Restore.
Feedback on the tool is welcome in the feedback issue.
To take a backup of the current GitLab installation:
sudo gitlab-backup-cli backup all
Only Google Cloud is supported. See epic 11577 for the plan to add more vendors.
gitlab-backup-cli creates and runs jobs with the Google Cloud Storage Transfer Service to copy GitLab data to a separate backup bucket.
Prerequisites:
To create a backup:
role.yaml with the following definition:---
description: Role for backing up GitLab object storage
includedPermissions:
- storagetransfer.jobs.create
- storagetransfer.jobs.get
- storagetransfer.jobs.run
- storagetransfer.jobs.update
- storagetransfer.operations.get
- storagetransfer.projects.getServiceAccount
stage: GA
title: GitLab Backup Role
Apply the role:
gcloud iam roles create --project=<YOUR_PROJECT_ID> <ROLE_NAME> --file=role.yaml
Create a service account for backups, and add it to the role:
gcloud iam service-accounts create "gitlab-backup-cli" --display-name="GitLab Backup Service Account"
# Get the service account email from the output of the following
gcloud iam service-accounts list
# Add the account to the role created previously
gcloud projects add-iam-policy-binding <YOUR_PROJECT_ID> --member="serviceAccount:<SERVICE_ACCOUNT_EMAIL>" --role="roles/<ROLE_NAME>"
To authenticate with a service account, see service account credentials. The credentials can be saved to a file, or stored in a predefined environment variable.
Create a destination bucket to backup to in Google Cloud Storage. The options here are highly dependent on your requirements.
Run the backup:
sudo gitlab-backup-cli backup all --backup-bucket=<BUCKET_NAME>
If you want to backup the container registry bucket, add the option --registry-bucket=<REGISTRY_BUCKET_NAME>.
The backup creates a backup under backups/<BACKUP_ID>/<BUCKET> for each of the object storage types in the bucket.
Example backup directory structure:
backups
└── 1714053314_2024_04_25_17.0.0-pre
├── artifacts.tar.gz
├── backup_information.json
├── builds.tar.gz
├── ci_secure_files.tar.gz
├── db
│ ├── ci_database.sql.gz
│ └── database.sql.gz
├── lfs.tar.gz
├── packages.tar.gz
├── pages.tar.gz
├── registry.tar.gz
├── repositories
│ ├── default
│ │ ├── @hashed
│ │ └── @snippets
│ └── manifests
│ └── default
├── terraform_state.tar.gz
└── uploads.tar.gz
The db directory is used to back up the GitLab PostgreSQL database using pg_dump to create an SQL dump. The output of pg_dump is piped through gzip in order to create a compressed SQL file.
The repositories directory is used to back up Git repositories, as found in the GitLab database.
Backup IDs identify individual backups. You need the backup ID of a backup archive if you need to restore GitLab and multiple backups are available.
Backups are saved in a directory set in backup_path, which is specified in the config/gitlab.yml file.
/var/opt/gitlab/backups.backup_id's where <backup-id> identifies the time when the backup was created and the GitLab version.For example, if the backup directory name is 1714053314_2024_04_25_17.0.0-pre, the time of creation is represented by 1714053314_2024_04_25 and the GitLab version is 17.0.0-pre.
backup_information.json){{< history >}}
{{< /history >}}
backup_information.json is found in the backup directory, and it stores metadata about the backup. For example:
{
"metadata_version": 2,
"backup_id": "1714053314_2024_04_25_17.0.0-pre",
"created_at": "2024-04-25T13:55:14Z",
"gitlab_version": "17.0.0-pre"
}
{{< history >}}
{{< /history >}}
Prerequisites:
gitlab-backup-cli.To restore a backup of the current GitLab installation:
Run the following command:
sudo gitlab-backup-cli restore all <backup_id>
You can restore data from Google Cloud Storage. Epic 11577 proposes to add support for other vendors.
Prerequisites:
gitlab-backup-cli.gitlab.rb or gitlab.yml file, and matches the backup environment.To restore object storage data:
Run the following command:
sudo gitlab-backup restore <backup_id>
The restore process:
Always monitor your system resources during a restore. Keep your original files until you verify the restoration was successful.
When working with gitlab-backup-cli, you might encounter the following issues.
If you use the gitlab-backup-cli tool on architectures other than the 1K architecture, you might experience issues. This tool is supported only on 1K architecture and is recommended only for relevant environments.
Changes to existing files during backup might cause issues on the GitLab instance. This issue occurs because the tool's initial version does not use the copy strategy.
A workaround of this issue, is either to:
We're investigating an alternative to the copy strategy, see issue 428520.
Secrets and Configurations
Transient and Cache Data
Instead of using the same credentials, you should create a separate user account specifically with only the necessary permissions to perform backups. Running backups with the same credentials as the application is a poor security practice for several reasons: