Migrating GitLab to Another Server

Didiet Agus Pambudiono
Jul 9 · 2 min read
Illustration of GitLab Server Migration

Because of the policy of GITS Indonesia, we have to migrate the GitLab server to another server. In this case, we used the Google Cloud Platform Compute Engine for the new server.

When migrating GitLab to a new server, we might face much problems of in-compatible versions; different operating system (so needs different latest GitLab version); etc. There are two ways to migrate the GitLab. First way is to upgrade the old version to the same latest GitLab version, backup GitLab, and we can migrate to new server. The second way is to install GitLab on a new server with the same version as the old server. We choose the second way for the safety.

So, this is how to do it.

First, we create a new server on GCP with Ubuntu Server 18.04, meanwhile the old server still use Ubuntu Server 14.04. And the GitLab version that we use is 11.4.5.

On Old Server

On the old server, do these steps.

  1. Shut down GitLab service
    sudo gitlab-ctl stop unicorn
    sudo gitlab-ctl stop sidekiq
  2. Back up GitLab on old server
    sudo gitlab-rake gitlab:backup:create
  3. Create a folder named gitlab-old on the server
    mkdir gitlab-old
  4. Copy the GitLab file configuration on folder /etc/gitlab (gitlab.rb and gitlab-secrets.json) and folder /etc/gitlab/ssl to ~/gitlab-old
    sudo cp /etc/gitlab/gitlab.rb ~/gitlab-old
    sudo cp /etc/gitlab/gitlab-secrets.json ~/gitlab-old
    sudo cp -R /etc/gitlab/ssl ~/gitlab-old
  5. Copy the backup file to folder ~/gitlab-old
    sudo cp /var/opt/gitlab/backups/XXXXXXXXXX_gitlab_backup.tar
  6. Change permission and ownership of ~/gitlab-old
    sudo chown user:user -R ~/gitlab-old
  7. Transfer gitlab-old folder to new server
    scp -r ~/gitlab-old user@<new_server_ip>:~

On New Server

On the new server, do these steps.

  1. Install the new server with GitLab 11.4.5.
    Add GitLab source with:
    curl -s https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash
    Update and install GitLab 11.4.5 with:
    sudo apt-get install gitlab-ce=11.4.5-ce.0
  2. Copy the configuration file to folder /etc/gitlab
    sudo cp gitlab-old/gitlab* /etc/GitLab
  3. Copy the ssl folder to folder /etc/gitlab
    sudo cp -R gitlab-old/ssl /etc/GitLab
  4. Run GitLab service for the first time
    sudo gitlab-ctl reconfigure
  5. Shut down GitLab service
    sudo gitlab-ctl stop unicorn
    sudo gitlab-ctl stop sidekiq
  6. Copy backup file to /var/opt/gitlab/backups, then change ownership and permission to git user
    sudo cp gitlab-old/XXXXXXXXXX_gitlab_backup.tar /var/opt/gitlab/backups
    sudo chown git:git /var/opt/gitlab/backups/XXXXXXXXXX_gitlab_backup.tar
  7. Run the GitLab restore process
    sudo gitlab-rake gitlab:backup:restore BACKUP=XXXXXXXXX
  8. Restart GitLab and check
    sudo gitlab-ctl start
    sudo gitlab-rake gitlab:check SANITIZE=true

That’s it! It should be running well. If you have further question, you can leave your comment below.

Didiet A. Pambudiono is a Cloud explorer, FOSS enthusiast and contributor, also DevOps engineer at GITS Indonesia.

GITS Apps Insight

Didiet Agus Pambudiono

Written by

Just Another Engineer

GITS Apps Insight

Journal about apps development for business and eCommerce from GITS Indonesia, a Google Certified Agency.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade