Disaster Recovery
Geo replicates your database, your Git repositories, and few other assets. We will support and replicate more data in the future, that will enable you to failover with minimal effort, in a disaster situation.
See Geo current limitations for more information.
CAUTION: Warning: Disaster recovery for multi-secondary configurations is in Alpha. For the latest updates, check the multi-secondary Disaster Recovery epic.
Promoting secondary Geo replica in single-secondary configurations
We don't currently provide an automated way to promote a Geo replica and do a
failover, but you can do it manually if you have root
access to the machine.
This process promotes a secondary Geo replica to a primary. To regain geographical redundancy as quickly as possible, you should add a new secondary immediately after following these instructions.
Step 1. Allow replication to finish if possible
If the secondary is still replicating data from the primary, follow the planned failover docs as closely as possible in order to avoid unnecessary data loss.
Step 2. Permanently disable the primary
CAUTION: Warning: If a primary goes offline, there may be data saved on the primary that has not been replicated to the secondary. This data should be treated as lost if you proceed.
If an outage on your primary 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.
-
SSH into your primary to stop and disable GitLab, if possible:
sudo gitlab-ctl stop
Prevent GitLab from starting up again if the server unexpectedly reboots:
sudo systemctl disable gitlab-runsvdir
CentOS only: In CentOS 6 or older, there is no easy way to prevent GitLab from being started if the machine reboots isn't available (see gitlab-org/omnibus-gitlab#3058). It may be safest to uninstall the GitLab package completely:
yum remove gitlab-ee
Ubuntu 14.04 LTS: If you are using an older version of Ubuntu or any other distro based on the Upstart init system, you can prevent GitLab from starting if the machine reboots by doing the following:
initctl stop gitlab-runsvvdir echo 'manual' > /etc/init/gitlab-runsvdir.override initctl reload-configuration
-
If you do not have SSH access to your primary, take the machine offline and prevent it from rebooting by any means at your disposal. Since there are many ways you may prefer to accomplish this, we will avoid a single recommendation. You may need to:
- Reconfigure the load balancers
- Change DNS records (e.g., point the primary DNS record to the secondary node in order to stop usage of the primary)
- Stop the virtual servers
- Block traffic through a firewall
- Revoke object storage permissions from the primary
- Physically disconnect a machine
Step 3. Promoting a secondary Geo replica
-
SSH in to your secondary and login as root:
sudo -i
-
Edit
/etc/gitlab/gitlab.rb
to reflect its new status as primary by removing the following line:## REMOVE THIS LINE geo_secondary_role['enable'] = true
A new secondary should not be added at this time. If you want to add a new secondary, do this after you have completed the entire process of promoting the secondary to the primary.
-
Promote the secondary to primary. Execute:
gitlab-ctl promote-to-primary-node
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.
Promoting a node with HA
The gitlab-ctl promote-to-primary-node
command cannot be used yet in conjunction with
High Availability or with multiple machines, as it can only perform changes on
a single one.
The command above does the following changes:
- Promotes the PostgreSQL secondary to primary
- Executes
gitlab-ctl reconfigure
to apply the changes in/etc/gitlab/gitlab.rb
- Runs
gitlab-rake geo:set_secondary_as_primary
You need to make sure all the affected machines no longer have geo_secondary_role['enable'] = true
in
/etc/gitlab/gitlab.rb
, that you execute the database promotion on the required database nodes
and you execute the gitlab-rake geo:set_secondary_as_primary
in a machine running the application server.
Step 4. (Optional) Updating the primary domain DNS record
Updating the DNS records for the primary domain to point to the secondary will prevent the need to update all references to the primary domain to the secondary domain, like changing Git remotes and API URLs.
-
SSH into your secondary 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, edit
/etc/gitlab/gitlab.rb
on the secondary to reflect the new URL:# Change the existing external_url configuration external_url 'https://gitlab.example.com'
-
Reconfigure the secondary node for the change to take effect:
gitlab-ctl reconfigure
-
Execute the command below to update the newly promoted primary node URL:
gitlab-rake geo:update_primary_node_url
This command will use the changed
external_url
configuration defined in/etc/gitlab/gitlab.rb
. Verify you can connect to the newly promoted primary using the primary 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.
Step 5. (Optional) Add secondary Geo replicas to a promoted primary
Promoting a secondary to primary using the process above does not enable Geo on the new primary.
To bring a new secondary online, follow the Geo setup instructions.
Promoting secondary Geo replica in multi-secondary configurations
CAUTION: Warning: Disaster Recovery for multi-secondary configurations is in Alpha development. Do not use this as your only Disaster Recovery strategy as you may lose data.
Disaster Recovery does not yet support systems with multiple secondary Geo replicas (e.g., one primary and two or more secondaries). We are working on it, see gitlab-org/gitlab-ee#4284 for details.
Troubleshooting
I followed the disaster recovery instructions and now two-factor auth is broken!
The setup instructions for Geo prior to 10.5 failed to replicate the
otp_key_base
secret, which is used to encrypt the two-factor authentication
secrets stored in the database. If it differs between primary and secondary
nodes, users with two-factor authentication enabled won't be able to log in
after a failover.
If you still have access to the old primary node, you can follow the instructions in the Upgrading to GitLab 10.5 section to resolve the error. Otherwise, the secret is lost and you'll need to reset two-factor authentication for all users.