Disaster Recovery (Geo)

Geo replicates your database, your Git repositories, and few other assets, but there are some limitations.

caution
Disaster recovery for multi-secondary configurations is in Alpha. For the latest updates, check the Disaster Recovery epic for complete maturity. Multi-secondary configurations require the complete re-synchronization and re-configuration of all non-promoted secondaries and causes downtime.

Promoting a secondary Geo site 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 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.

Step 1. Allow replication to finish if possible

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.

Step 2. Permanently disable the primary site

caution
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:

    1. SSH into the primary site to stop and disable GitLab:

      sudo gitlab-ctl stop
      
    2. 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:

    • Reconfigure the load balancers.
    • Change DNS records (for example, point the primary DNS record to the secondary site to stop usage of the primary site).
    • Stop the virtual servers.
    • Block traffic through a firewall.
    • Revoke object storage permissions from the primary site.
    • Physically disconnect a machine.

    If you plan to update the primary domain DNS record, you may wish to lower the TTL now to speed up propagation.

Step 3. Promoting a secondary site

caution
In GitLab 13.2 and 13.3, promoting a secondary site to a primary while the secondary is paused fails. Do not pause replication before promoting a secondary. If the secondary site is paused, be sure to resume before promoting. This issue has been fixed in GitLab 13.4 and later.

Note the following when promoting a secondary:

  • If replication was paused on the secondary site (for example as a part of upgrading, while you were running a version of GitLab earlier than 13.4), you must enable the site by using the database before proceeding. If the secondary site has been paused, the promotion 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.
  • 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.
  • If you encounter an ActiveRecord::RecordInvalid: Validation failed: Name has already been taken error message during this process, for more information, see this troubleshooting advice.
  • If you run into errors when using --force or --skip-preflight-checks before 13.5 during this process, for more information, see this troubleshooting advice.

Promoting a secondary site running on a single node running GitLab 14.5 and later

  1. 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
      
  2. Verify you can connect to the newly-promoted primary site using the URL used previously for the secondary site.
  3. If successful, the secondary site is now promoted to the primary site.

Promoting a secondary site running on a single node running GitLab 14.4 and earlier

caution
The gitlab-ctl promote-to-primary-node and gitlab-ctl promoted-db commands are deprecated in GitLab 14.5 and later, and removed in GitLab 15.0. Use gitlab-ctl geo promote instead.
  1. SSH in to your secondary site and login as root:

    sudo -i
    
  2. If you’re using GitLab 13.5 and later, skip this step. If not, edit /etc/gitlab/gitlab.rb and remove any of the following lines that might be present:

    geo_secondary_role['enable'] = true
    roles ['geo_secondary_role']
    
  3. Promote the secondary site to the primary site:

    • To promote the secondary site to primary along with preflight checks:

      gitlab-ctl promote-to-primary-node
      
    • If you have already run the preflight checks separately or don’t want to run them, you can skip them with:

      gitlab-ctl promote-to-primary-node --skip-preflight-checks
      
      note
      In GitLab 13.7 and earlier, if you have a data type with zero items to sync and don’t skip the preflight checks, promoting the secondary reports ERROR - Replication is not up-to-date even if replication is actually up-to-date. If replication and verification output shows that it is complete, you can skip the preflight checks to make the command complete promotion. This bug was fixed in GitLab 13.8 and later.
    • To promote the secondary site to primary without any further confirmation, even when preflight checks fail:

      gitlab-ctl promote-to-primary-node --force
      
  4. Verify you can connect to the newly-promoted primary site using the URL used previously for the secondary site.
  5. If successful, the secondary site is now promoted to the primary site.

Promoting a secondary site with multiple nodes running GitLab 14.5 and later

  1. SSH to every Sidekiq, PostgresSQL, 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
      
  2. 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
      
  3. Verify you can connect to the newly-promoted primary site using the URL used previously for the secondary site.
  4. If successful, the secondary site is now promoted to the primary site.

Promoting a secondary site with multiple nodes running GitLab 14.4 and earlier

caution
The gitlab-ctl promote-to-primary-node and gitlab-ctl promoted-db commands are deprecated in GitLab 14.5 and later, and removed in GitLab 15.0. Use gitlab-ctl geo promote instead.

The gitlab-ctl promote-to-primary-node command cannot be used yet in conjunction with multiple nodes, as it can only perform changes on a secondary with only a single node. Instead, you must do this manually.

  1. SSH in to the database node in the secondary site and trigger PostgreSQL to promote to read-write:

    sudo gitlab-ctl promote-db
    

    In GitLab 12.8 and earlier, see Message: sudo: gitlab-pg-ctl: command not found.

  2. Edit /etc/gitlab/gitlab.rb on every node in the secondary site to reflect its new status as primary by removing any of the following lines that might be present:

    geo_secondary_role['enable'] = true
    roles ['geo_secondary_role']
    

    After making these changes, reconfigure GitLab on each machine so the changes take effect.

  3. Promote the secondary to primary. SSH into a single