doc/administration/geo/disaster_recovery/_index.md
{{< details >}}
{{< /details >}}
Geo replicates your database, your Git repositories, and other assets. Some known issues exist.
[!warning]
- Multi-secondary configurations require the complete re-synchronization and re-configuration of all non-promoted secondaries and causes downtime.
- After the secondary site is promoted, the primary site is detached entirely. If you wish to restore the primary site, you must add it as a new secondary site.
Promoting a secondary site with selective synchronization enabled results in permanent data loss
for all data that was not replicated to that secondary site. For more information, see
Promoting a secondary site with selective synchronization enabled.
gitlab-cluster.json fileWhen you promote a secondary site to a primary site with gitlab-ctl geo promote,
the command automatically creates a /etc/gitlab/gitlab-cluster.json file on each node
where it executes. In most circumstances, you don't need to manually edit this file.
The gitlab-cluster.json file allows the promotion command to automate configuration
changes without modifying /etc/gitlab/gitlab.rb directly. Programmatically editing
gitlab.rb is error-prone, so gitlab-cluster.json serves as a machine-managed
override layer.
When both files exist, values in gitlab-cluster.json take precedence over the
corresponding values in gitlab.rb when gitlab-ctl reconfigure executes. When you run this command,
you see a warning similar to:
The 'geo_primary_role' is defined in /etc/gitlab/gitlab-cluster.json as 'true' and overrides the setting in the /etc/gitlab/gitlab.rb
The 'geo_secondary_role' is defined in /etc/gitlab/gitlab-cluster.json as 'false' and overrides the setting in the /etc/gitlab/gitlab.rb
This warning is expected after promotion.
A typical gitlab-cluster.json file looks like:
{
"primary": true,
"secondary": false,
"geo_secondary": {
"enable": false
}
}
| Key | Description |
|---|---|
primary | When true, enables geo_primary_role, which configures the node as a Geo primary. |
secondary | When true, enables geo_secondary_role, which configures the node as a Geo secondary. |
geo_secondary | Contains settings related to the Geo secondary configuration, such as the tracking database. "enable": false disables secondary-specific services. |
The primary and secondary keys map to the geo_primary_role and geo_secondary_role
respectively. These roles are a convenience for single-node setups and should not be
used in multi-node configurations where individual service roles are configured
explicitly in gitlab.rb.
After a successful promotion, you can keep gitlab-cluster.json in place. However,
you should remove it in the following situations:
If you bring a demoted primary back
as a new secondary site, you must delete gitlab-cluster.json from every
Sidekiq, PostgreSQL, Gitaly, and Rails node.
After you update gitlab.rb to set a Geo role (for example, roles(['geo_primary_role'])), and you want
gitlab.rb to be the sole configuration source.
After you recover from a partial failover.
See Recovering from a partial failover for details on when the file is manually created during recovery.
To remove the file:
Run these commands:
sudo rm /etc/gitlab/gitlab-cluster.json
sudo gitlab-ctl reconfigure
In a multi-node setup, repeat these commands on every node in the site.
For technical details about how gitlab-cluster.json interacts with the
reconfigure process, see the
Omnibus reconfigure documentation.
While you can't automatically promote a Geo replica and do a failover,
you can promote it manually if you have root access to the machine.
This process promotes a secondary Geo site to a primary site. To regain geographic redundancy as quickly as possible, you should add a new secondary site immediately after following these instructions.
If the secondary site is still replicating data from the primary site, follow the planned failover docs as closely as possible in order to avoid unnecessary data loss.
[!warning] If the primary site goes offline, there may be data saved on the primary site that have not been replicated to the secondary site. This data should be treated as lost if you proceed.
If an outage on the primary site happens, you should do everything possible to avoid a split-brain situation where writes can occur in two different GitLab instances, complicating recovery efforts. So to prepare for the failover, we must disable the primary site.
If you have SSH access:
SSH into the primary site to stop and disable GitLab:
sudo gitlab-ctl stop
Prevent GitLab from starting up again if the server unexpectedly reboots:
sudo systemctl disable gitlab-runsvdir
If you do not have SSH access to the primary site, take the machine offline and prevent it from rebooting by any means at your disposal. You might need to:
If you plan to update the primary domain DNS record, you may wish to maintain a low TTL to ensure fast propagation of DNS changes.
[!note] The primary site's
/etc/gitlab/gitlab.rbfile is not copied to the secondary sites automatically during this process. Make sure that you back up the primary's/etc/gitlab/gitlab.rbfile, so that you can later restore any needed values on your secondary sites.
Note the following when promoting a secondary:
ActiveRecord::StatementInvalid: PG::ReadOnlySqlTransaction: ERROR: cannot execute DELETE in a read-only transaction error message during this process, see this knowledge base article: Geo promotion fails with read-only transaction error or timeout after unexpected primary shutdown.ActiveRecord::RecordInvalid: Validation failed: Name has already been taken
error message during this process, for more information, see this
troubleshooting advice.gitlab-ctl promotion-preflight-checks on the secondary to check the Geo sync status and perform final validation checks.SSH in to your secondary site and execute:
To promote the secondary site to primary:
sudo gitlab-ctl geo promote
To promote the secondary site to primary without any further confirmation:
sudo gitlab-ctl geo promote --force
Verify you can connect to the newly-promoted primary site using the URL used previously for the secondary site.
If successful, the secondary site is now promoted to the primary site.
When you run gitlab-ctl geo promote, a gitlab-cluster.json
file is created on the node. The file overrides Geo role settings in gitlab.rb
when you reconfigure.
If you have any geo_secondary[] configuration options enabled in your /etc/gitlab/gitlab.rb
file, comment them out or remove them, and then reconfigure GitLab
for the changes to take effect.
At this point, your promoted site is the new primary GitLab site. Optionally, if you wish to set up Geo again as a new secondary site, you can bring the old site back as a secondary.
SSH to every Sidekiq, PostgreSQL, and Gitaly node in the secondary site and run one of the following commands:
To promote the node on the secondary site to primary:
sudo gitlab-ctl geo promote
To promote the secondary site to primary without any further confirmation:
sudo gitlab-ctl geo promote --force
SSH into each Rails node on your secondary site and run one of the following commands:
To promote the secondary site to primary:
sudo gitlab-ctl geo promote
To promote the secondary site to primary without any further confirmation:
sudo gitlab-ctl geo promote --force
Verify you can connect to the newly-promoted primary site using the URL used previously for the secondary site.
If successful, the secondary site is now promoted to the primary site.
When you run gitlab-ctl geo promote, a gitlab-cluster.json
file is created on the node. The file overrides Geo role settings in gitlab.rb
when you reconfigure.
SSH to every Sidekiq, PostgreSQL, and Gitaly node in the secondary site and run one of the following commands:
To promote the secondary site to primary:
sudo gitlab-ctl geo promote
To promote the secondary site to primary without any further confirmation:
sudo gitlab-ctl geo promote --force
SSH into each Rails node on your secondary site and run one of the following commands:
To promote the secondary site to primary:
sudo gitlab-ctl geo promote
To promote the secondary site to primary without any further confirmation:
sudo gitlab-ctl geo promote --force
Verify you can connect to the newly-promoted primary site using the URL used previously for the secondary site.
If successful, the secondary site is now promoted to the primary site.
The gitlab-ctl geo promote command can be used in conjunction with an external PostgreSQL database.
In this case, you must first manually promote the replica database associated
with the secondary site:
Promote the replica database associated with the secondary site. This sets the database to read-write. The instructions vary depending on where your database is hosted:
For other external PostgreSQL databases, save the following script in your
secondary site, for example /tmp/geo_promote.sh, and modify the connection
parameters to match your environment. Then, execute it to promote the replica:
#!/bin/bash
PG_SUPERUSER=postgres
# The path to your pg_ctl binary. You may need to adjust this path to match
# your PostgreSQL installation
PG_CTL_BINARY=/usr/lib/postgresql/16/bin/pg_ctl
# The path to your PostgreSQL data directory. You may need to adjust this
# path to match your PostgreSQL installation. You can also run
# `SHOW data_directory;` from PostgreSQL to find your data directory
PG_DATA_DIRECTORY=/etc/postgresql/16/main
# Promote the PostgreSQL database and allow read/write operations
sudo -u $PG_SUPERUSER $PG_CTL_BINARY -D $PG_DATA_DIRECTORY promote
SSH to every Sidekiq, PostgreSQL, and Gitaly node in the secondary site and run one of the following commands:
To promote the secondary site to primary:
sudo gitlab-ctl geo promote
To promote the secondary site to primary without any further confirmation:
sudo gitlab-ctl geo promote --force
SSH into each Rails node on your secondary site and run one of the following commands:
To promote the secondary site to primary:
sudo gitlab-ctl geo promote
To promote the secondary site to primary without any further confirmation:
sudo gitlab-ctl geo promote --force
Verify you can connect to the newly-promoted primary site using the URL used previously for the secondary site.
If successful, the secondary site is now promoted to the primary site.
Update DNS records for the primary domain to point to the secondary site. This removes the need to update all references to the primary domain, for example changing Git remotes and API URLs.
SSH into the secondary site and login as root:
sudo -i
Update the primary domain's DNS record. After updating the primary domain's
DNS records to point to the secondary site, edit /etc/gitlab/gitlab.rb on the
secondary site to reflect the new URL:
# Change the existing external_url configuration
external_url 'https://<new_external_url>'
[!note] Changing
external_urldoes not prevent access through the old secondary URL, as long as the secondary DNS records are still intact.
Update the secondary's SSL certificate:
If you use the Let's Encrypt integration, the certificate updates automatically.
If you had manually set up, the secondary's certificate, copy the certificate from the primary to the secondary. If you don't have access to the primary, issue a new certificate and make sure it contains both the primary and secondary URLs in the subject alternative names. You can check with:
/opt/gitlab/embedded/bin/openssl x509 -noout -dates -subject -issuer \
-nameopt multiline -ext subjectAltName -in /etc/gitlab/ssl/new-gitlab.new-example.com.crt
Reconfigure the secondary site for the change to take effect:
gitlab-ctl reconfigure
Execute the command below to update the newly promoted primary site URL:
gitlab-rake geo:update_primary_node_url
This command uses the changed external_url configuration defined
in /etc/gitlab/gitlab.rb.
Verify you can connect to the newly promoted primary using its URL. If you updated the DNS records for the primary domain, these changes may not have yet propagated depending on the previous DNS records TTL.
To bring a new secondary site online, follow the Geo setup instructions.
If you have more than one secondary site and you need to promote one of them, we suggest you follow Promoting a secondary Geo site in single-secondary configurations and after that you also need two extra steps.
SSH into the new primary site and login as root:
sudo -i
Edit /etc/gitlab/gitlab.rb:
## Enable a Geo Primary role (if you haven't yet)
roles ['geo_primary_role']
##
# Allow PostgreSQL client authentication from the primary and secondary IPs. These IPs may be
# public or VPC addresses in CIDR format, for example ['198.51.100.1/32', '198.51.100.2/32']
##
postgresql['md5_auth_cidr_addresses'] = ['<primary_site_ip>/32', '<secondary_site_ip>/32']
# Every secondary site needs to have its own slot so specify the number of secondary sites you're going to have
# postgresql['max_replication_slots'] = 1 # Set this to be the number of Geo secondary nodes if you have more than one
##
## Disable automatic database migrations temporarily
## (until PostgreSQL is restarted and listening on the private address).
##
gitlab_rails['auto_migrate'] = false
(For more details about these settings you can read Configure the primary server)
Save the file and reconfigure GitLab for the database listen changes and the replication slot changes to be applied:
gitlab-ctl reconfigure
Restart PostgreSQL for its changes to take effect:
gitlab-ctl restart postgresql
Re-enable migrations now that PostgreSQL is restarted and listening on the private address.
Edit /etc/gitlab/gitlab.rb and change the configuration to true:
gitlab_rails['auto_migrate'] = true
Save the file and reconfigure GitLab:
gitlab-ctl reconfigure
Now we need to make each secondary site listen to changes on the new primary site. To do that you need to initiate the replication process again but this time for another primary site. All the old replication settings are overwritten.
Existing secondary sites will all have populated databases so you may see a message like this:
Found data inside the gitlabhq_production database! If you are sure you are in the secondary server, override with --force
After you have confirmed that you are on the appropriate secondary site, initiate the replication with --force.
[!warning] Using
--forcecauses all existing data in the database on that secondary server to be deleted.
When updating a cloud-native Geo deployment, the process for updating any node that is external to the secondary Kubernetes cluster does not differ from the non cloud-native approach. As such, you can always defer to Promoting a secondary Geo site in single-secondary configurations for more information.
The following sections assume you are using the gitlab namespace. If you used a different namespace when setting up your cluster, you should also replace --namespace gitlab with your namespace.
[!warning] If the primary site goes offline, there may be data saved on the primary site that has not been replicated to the secondary site. This data should be treated as lost if you proceed.
If an outage on the primary site happens, you should do everything possible to avoid a split-brain situation where writes can occur in two different GitLab instances, complicating recovery efforts. So to prepare for the failover, you must disable the primary site:
If you have access to the primary Kubernetes cluster, connect to it and disable the GitLab webservice and Sidekiq pods:
kubectl --namespace gitlab scale deploy gitlab-geo-webservice-default --replicas=0
kubectl --namespace gitlab scale deploy gitlab-geo-sidekiq-all-in-1-v1 --replicas=0
If you do not have access to the primary Kubernetes cluster, take the cluster offline and prevent it from coming back online by any means at your disposal. You might need to:
[!warning] If the secondary site has been paused, this performs a point-in-time recovery to the last known state. Data that was created on the primary while the secondary was paused is lost.
For each node (such as PostgreSQL or Gitaly) outside of the secondary Kubernetes cluster using the Linux package, SSH into the node and run one of the following commands:
To promote the secondary site node external to the Kubernetes cluster to primary:
sudo gitlab-ctl geo promote
To promote the secondary site node external to the Kubernetes cluster to primary without any further confirmation:
sudo gitlab-ctl geo promote --force
Find the toolbox pod:
kubectl --namespace gitlab get pods -lapp=toolbox
Promote the secondary:
kubectl --namespace gitlab exec -ti gitlab-geo-toolbox-XXX -- gitlab-rake geo:set_secondary_as_primary
Environment variables can be provided to modify the behavior of the task. The available variables are:
| Name | Default value | Description |
|---|---|---|
ENABLE_SILENT_MODE | false | If true, enables Silent Mode before promotion (GitLab 16.4 and later) |
Update the existing cluster configuration.
You can retrieve the existing configuration with Helm:
helm --namespace gitlab get values gitlab-geo > gitlab.yaml
The existing configuration contains a section for Geo that should resemble:
geo:
enabled: true
role: secondary
nodeName: secondary.example.com
psql:
host: geo-2.db.example.com
port: 5431
password:
secret: geo
key: geo-postgresql-password
To promote the secondary cluster to a primary cluster, update role: secondary to role: primary.
If the cluster remains as a primary site, you can remove the entire psql section; it refers to the tracking database and is ignored while the cluster is acting as a primary site.
Update the cluster with the new configuration:
helm upgrade --install --version <current Chart version> gitlab-geo gitlab/gitlab --namespace gitlab -f gitlab.yaml
Verify you can connect to the newly promoted primary using the URL used previously for the secondary.
Success! The secondary has now been promoted to primary.
If you have GitLab Secrets Manager enabled, complete the following steps to promote the OpenBao High Availability (HA) cluster after promoting the Kubernetes cluster.
After the PostgreSQL replica is promoted to primary, restart the OpenBao pods so they reconnect to the database now that it's writable:
kubectl --namespace gitlab rollout restart deployment -l app=openbao
Skip this step if you've updated DNS records for the primary domain to point to the secondary site.
Using recovery keys, connect to OpenBao API to reconfigure JWT authentication for the secondary domain.
For more information, see Geo configuration.
The unseal key on the secondary cluster must be the same as the one on the primary key, otherwise OpenBao won't be able to unseal the vault on the secondary.
If there's a mismatch, restore the gitlab-openbao-unseal secret on the secondary cluster
from your secrets backup,
then restart the OpenBao pods:
kubectl --namespace gitlab rollout restart deployment -l app=openbao
Check that all OpenBao pods are running:
kubectl --namespace gitlab get pods -l app=openbao
Test OpenBao integration by running a CI pipeline that uses a Secrets Manager variable.
This section was moved to another location.