Back up and restore large reference architectures (FREE SELF)
This document describes how to:
- Configure daily backups
- Take a backup now (planned)
- Restore a backup
This document is intended for environments using:
- Linux package (Omnibus) and cloud-native hybrid reference architectures 3,000 users and up
- Amazon RDS for PostgreSQL data
- Amazon S3 for object storage
- Object storage to store everything possible, including blobs and container registry
Configure daily backups
Configure backup of PostgreSQL and object storage data
The backup command uses pg_dump
, which is not appropriate for databases over 100 GB. You must choose a PostgreSQL solution which has native, robust backup capabilities.
Object storage, (not NFS) is recommended for storing GitLab data, including blobs and Container registry.
- Configure AWS Backup to back up both RDS and S3 data. For maximum protection, configure continuous backups as well as snapshot backups.
- Configure AWS Backup to copy backups to a separate region. When AWS takes a backup, the backup can only be restored in the region the backup is stored.
- After AWS Backup has run at least one scheduled backup, then you can create an on-demand backup as needed.
Configure backup of Git repositories
NOTE: There is a feature proposal to add the ability to back up repositories directly from Gitaly to object storage. See epic 10077.
-
Linux package (Omnibus):
We will continue to use the backup command to back up Git repositories.
If utilization is low enough, you can run it from an existing GitLab Rails node. Otherwise, spin up another node.
-
Cloud native hybrid:
The
backup-utility
command in atoolbox
pod fails when there is a large amount of data. In this case, you must run the backup command to back up Git repositories, and you must run it in a VM running the GitLab Linux package:-
Spin up a VM with 8 vCPU and 7.2 GB memory. This node will be used to back up Git repositories. Note that a Praefect node cannot be used to back up Git data.
-
Configure the node as another GitLab Rails node as defined in your reference architecture. As with other GitLab Rails nodes, this node must have access to your main PostgreSQL database, Redis, object storage, and Gitaly Cluster.
-
Ensure the GitLab application isn't running on this node by disabling most services:
-
Edit
/etc/gitlab/gitlab.rb
to ensure the following services are disabled.roles(['application_role'])
disables Redis, PostgreSQL, and Consul, and is the basis of the reference architecture Rails node definition.roles(['application_role']) gitlab_workhorse['enable'] = false puma['enable'] = false sidekiq['enable'] = false gitlab_kas['enable'] = false gitaly['enable'] = false prometheus_monitoring['enable'] = false
-
Reconfigure GitLab:
sudo gitlab-ctl reconfigure
-
The only service that should be left is
logrotate
, you can verify with:gitlab-ctl status
There is a feature request for a role in the Linux package that meets these requirements.
-
-
To back up the Git repositories:
-
Ensure that the GitLab Rails node has enough attached storage to store Git repositories and an archive of the Git repositories. Additionally, the contents of forked repositories are duplicated into their forks during backup. For example, if you have 5 GB worth of Git repositories and two forks of a 1 GB repository, then you require at least 14 GB of attached storage to account for:
- 7 GB of Git data.
- A 7 GB archive file of all Git data.
-
SSH into the GitLab Rails node.
-
Configure AWS Backup for this bucket, or use a bucket in the same account and region as your production data object storage buckets, and ensure this bucket is included in your preexisting AWS Backup.
-
Run the backup command, skipping PostgreSQL data:
sudo gitlab-backup create SKIP=db
The resulting tar file will include only the Git repositories and some metadata. Blobs such as uploads, artifacts, and LFS do not need to be explicitly skipped, because the command does not back up object storage by default. The tar file will be created in the
/var/opt/gitlab/backups
directory and the file name will end in_gitlab_backup.tar
.Since we configured uploading backups to remote cloud storage, the tar file will be uploaded to the remote region and deleted from disk.
-
Note the backup ID of the backup file for the next step. For example, if the backup archive name is
1493107454_2018_04_25_10.6.4-ce_gitlab_backup.tar
, the backup ID is1493107454_2018_04_25_10.6.4-ce
. -
Run the backup command again, this time specifying incremental backup of Git repositories, and the backup ID of the source backup file. Using the example ID from the previous step, the command is:
sudo gitlab-backup create SKIP=db INCREMENTAL=yes PREVIOUS_BACKUP=1493107454_2018_04_25_10.6.4-ce
-
Check that the incremental backup succeeded and uploaded to object storage.
-
Configure cron to make daily backups. Edit the crontab for the
root
user:sudo su - crontab -e
-
There, add the following line to schedule the backup for everyday at 2 AM:
0 2 * * * /opt/gitlab/bin/gitlab-backup create SKIP=db INCREMENTAL=yes PREVIOUS_BACKUP=1493107454_2018_04_25_10.6.4-ce CRON=1
Configure backup of configuration files
If your configuration and secrets are defined outside of your deployment and then deployed into it, then the implementation of the backup strategy depends on your specific setup and requirements. As an example, you can store secrets in AWS Secret Manager with replication to multiple regions and configure a script to back up secrets automatically.
If your configuration and secrets are only defined inside your deployment:
- Storing configuration files describes how to extract configuration and secrets files.
- These files should be uploaded to a separate, more restrictive, object storage account.
Restore a backup
Restore a backup of a GitLab instance.
Prerequisites
Before restoring a backup:
-
Choose a working destination GitLab instance.
-
Ensure the destination GitLab instance is in a region where your AWS backups are stored.
-
Check that the destination GitLab instance uses exactly the same version and type (CE or EE) of GitLab on which the backup data was created. For example, CE 15.1.4.
-
Restore backed up secrets to the destination GitLab instance.
-
Ensure that the destination GitLab instance has the same repository storages configured. Additional storages are fine.
-
If the backed up GitLab instance had any blobs stored in object storage, ensure that object storage is configured for those kinds of blobs.
-
If the backed up GitLab instance had any blobs stored on the file system, ensure that NFS is configured.
-
To use new secrets or configuration, and to avoid unexpected configuration changes during restore:
-
Linux package installations on all nodes:
- Reconfigure the destination GitLab instance.
- Restart the destination GitLab instance.
-
Helm chart (Kubernetes) installations:
-
On all GitLab Linux package nodes, run:
sudo gitlab-ctl reconfigure sudo gitlab-ctl start
-
Make sure you have a running GitLab instance by deploying the charts. Ensure the Toolbox pod is enabled and running by executing the following command:
kubectl get pods -lrelease=RELEASE_NAME,app=toolbox
-
The Webservice, Sidekiq and Toolbox pods must be restarted. The safest way to restart those pods is to run:
kubectl delete pods -lapp=sidekiq,release=<helm release name> kubectl delete pods -lapp=webservice,release=<helm release name> kubectl delete pods -lapp=toolbox,release=<helm release name>
-
-
-
Confirm the destination GitLab instance still works. For example:
- Make requests to the health check endpoints.
- Run GitLab check Rake tasks.
-
Stop GitLab services which connect to the PostgreSQL database.
-
Linux package installations on all nodes running Puma or Sidekiq, run:
sudo gitlab-ctl stop
-
Helm chart (Kubernetes) installations:
-
Note the current number of replicas for database clients for subsequent restart:
kubectl get deploy -n <namespace> -lapp=sidekiq,release=<helm release name> -o jsonpath='{.items[].spec.replicas}{"\n"}' kubectl get deploy -n <namespace> -lapp=webservice,release=<helm release name> -o jsonpath='{.items[].spec.replicas}{"\n"}' kubectl get deploy -n <namespace> -lapp=prometheus,release=<helm release name> -o jsonpath='{.items[].spec.replicas}{"\n"}'
-
Stop the clients of the database to prevent locks interfering with the restore process:
kubectl scale deploy -lapp=sidekiq,release=<helm release name> -n <namespace> --replicas=0 kubectl scale deploy -lapp=webservice,release=<helm release name> -n <namespace> --replicas=0 kubectl scale deploy -lapp=prometheus,release=<helm release name> -n <namespace> --replicas=0
-
-
Restore object storage data
Each bucket exists as a separate backup within AWS and each backup can be restored to an existing or new bucket.
-
To restore buckets, an IAM role with the correct permissions is required:
AWSBackupServiceRolePolicyForBackup
AWSBackupServiceRolePolicyForRestores
AWSBackupServiceRolePolicyForS3Restore
AWSBackupServiceRolePolicyForS3Backup
-
If existing buckets are being used, they must have Access Control Lists enabled.
-
You can move on to Restore PostgreSQL data while the restore job is running.
Restore PostgreSQL data
-
Restore the AWS RDS database using built-in tooling, which creates a new RDS instance.
-
Because the new RDS instance has a different endpoint, you must reconfigure the destination GitLab instance to point to the new database:
-
For Linux package installations, follow Using a non-packaged PostgreSQL database management server.
-
For Helm chart (Kubernetes) installations, follow Configure the GitLab chart with an external database.
-
-
Before moving on, wait until the new RDS instance is created and ready to use.
Restore Git repositories
Select or create a node to restore:
-
For Linux package installations, choose a Rails node, which is a node that normally runs Puma or Sidekiq.
-
For Helm chart (Kubernetes) installations, if you don't already have a Git repository backup node, create one now:
- Spin up a VM with 8 vCPU and 7.2 GB memory. This node is used to back up and restore Git repositories because a Praefect node cannot be used to back up Git data.
- Configure the node as another GitLab Rails node as defined in your reference architecture. As with other GitLab Rails nodes, this node must have access to your main PostgreSQL database as well as to Gitaly Cluster.
- Restore backed up secrets to the target GitLab.
To restore Git repositories:
-
Ensure the node has enough attached storage to store both the
.tar
file of Git repositories, and its extracted data. -
SSH into the GitLab Rails node.
-
As part of Restore object storage data, you should have restored a bucket containing the GitLab backup
.tar
file of Git repositories. -
Download the backup
.tar
file from its bucket into the backup directory described in thegitlab.rb
configurationgitlab_rails['backup_path']
. The default is/var/opt/gitlab/backups
. The backup file must be owned by thegit
user.sudo cp 11493107454_2018_04_25_10.6.4-ce_gitlab_backup.tar /var/opt/gitlab/backups/ sudo chown git:git /var/opt/gitlab/backups/11493107454_2018_04_25_10.6.4-ce_gitlab_backup.tar
-
Restore the backup, specifying the ID of the backup you wish to restore:
WARNING: The restore command requires additional parameters when your installation is using PgBouncer, for either performance reasons or when using it with a Patroni cluster.
# This command will overwrite the contents of your GitLab database! # NOTE: "_gitlab_backup.tar" is omitted from the name sudo gitlab-backup restore BACKUP=11493107454_2018_04_25_10.6.4-ce
If there's a GitLab version mismatch between your backup tar file and the installed version of GitLab, the restore command aborts with an error message. Install the correct GitLab version, and then try again.
-
Restart and check GitLab:
-
Linux package installations:
-
In all Puma or Sidekiq nodes, run:
sudo gitlab-ctl restart
-
In one Puma or Sidekiq node, run:
sudo gitlab-rake gitlab:check SANITIZE=true
-
-
Helm chart (Kubernetes) installations:
-
Start the stopped deployments, using the number of replicas noted in Prerequisites:
kubectl scale deploy -lapp=sidekiq,release=<helm release name> -n <namespace> --replicas=<original value> kubectl scale deploy -lapp=webservice,release=<helm release name> -n <namespace> --replicas=<original value> kubectl scale deploy -lapp=prometheus,release=<helm release name> -n <namespace> --replicas=<original value>
-
In the Toolbox pod, run:
sudo gitlab-rake gitlab:check SANITIZE=true
-
-
-
Check that database values can be decrypted especially if
/etc/gitlab/gitlab-secrets.json
was restored, or if a different server is the target for the restore:-
For Linux package installations, in a Puma or Sidekiq node, run:
sudo gitlab-rake gitlab:doctor:secrets
-
For Helm chart (Kubernetes) installations, in the Toolbox pod, run:
sudo gitlab-rake gitlab:doctor:secrets
-
-
For added assurance, you can perform an integrity check on the uploaded files:
-
For Linux package installations, in a Puma or Sidekiq node, run:
sudo gitlab-rake gitlab:artifacts:check sudo gitlab-rake gitlab:lfs:check sudo gitlab-rake gitlab:uploads:check
-
For Helm chart (Kubernetes) installations, because these commands can take a long time because they iterate over all rows, run the following commands the GitLab Rails node, rather than a Toolbox pod:
sudo gitlab-rake gitlab:artifacts:check sudo gitlab-rake gitlab:lfs:check sudo gitlab-rake gitlab:uploads:check
If missing or corrupted files are found, it does not always mean the back up and restore process failed. For example, the files might be missing or corrupted on the source GitLab instance. You might need to cross-reference prior backups. If you are migrating GitLab to a new environment, you can run the same checks on the source GitLab instance to determine whether the integrity check result is preexisting or related to the backup and restore process.
-
The restoration should be complete.