Migrate Gitlab CE to new server

by Daniel Pham
Published: Updated:
This entry is part 7 of 9 in the series Install Gitlab CE on Ubuntu 18

Migrate Gitlab CE to new server. In this article, I will guide you through migrating gitlab.

Server migration usually happens quite infrequently, every few months to every few years, even every decade. This depends on the conditions and operating requirements of the system.

For me, it’s simply because the virtual machine running the Gitlab system is located on a physical server that is about to fill up the hard drive. And I need to migrate it to a physical server with plenty of hard drive space.

Please do not ask questions about migrating entire virtual machines here. That depends a lot on infrastructure conditions.

Prepare the server

Here, I assume there are 2 servers in the relocation process.

  • old gitlab server.
  • new gitlab server.

The operating system used on both servers is Ubuntu server 18.04.

Note: I need to write this note down before you continue with the tasks below. You need to run the same version of gitlab on the new server as the version of gitlab on the old server. This means, either you upgrade the version on the old gitlab server to the latest, or you downgrade/install a low version on the new gitlab server.

Migrate Gitlab CE to new server
Migrate Gitlab CE to new server.

Migrate Gitlab CE to new server.

First you will do it on the old gitlab server.

On old gitlab server

If the gitlab version on your old server is not the latest version. Please update it before performing the migration, you can do this separately.

Recommended Reading: Instructions for updating Gitlab CE version

Please note to update Gitlab according to minor version and reference documents.

apt-get update
apt-get install gitlab-ce -y

When gitab version has been updated to the latest. Next, you stop the services on the old gitlab server.

gitlab-ctl stop unicorn
gitlab-ctl stop puma
gitlab-ctl stop sidekiq

Create a folder containing backup data.

mkdir /tmp/migrate_gitlab

Create a backup of gitlab data, note that you need to check the available disk space before backing up.

gitlab-backup create

Copy gitlab backup data to the migrate_gitlab directory.

cp /var/opt/gitlab/backups/xxxxxxxxxx_yyyy_mm_dd_13.2.2_gitlab_backup.tar /tmp/migrate_gitlab
cp -rp /etc/gitlab /tmp/migrate_gitlab

Move the migrate_gitlab folder to the new gitlab server.

scp -rp /tmp/migrate_gitlab [email protected]:/tmp/

On the new gitlab server

On the new gitlab server, by default you have installed the latest version of Gitlab CE and initial setup, and can access the system’s website.

Now, you also proceed to stop Gitlab’s database connection services.

gitlab-ctl stop unicorn
gitlab-ctl stop puma
gitlab-ctl stop sidekiq

Copy backup file from old gitlab server.

cp /tmp/migrate_gitlab/xxxxxxxxxx_yyyy_mm_dd_13.2.2_gitlab_backup.tar /var/opt/gitlab/backups/
chown git:git /var/opt/gitlab/backups/xxxxxxxxxx_yyyy_mm_dd_13.2.2_gitlab_backup.tar
mv /etc/gitlab /etc/gitlab.current_bk
cp -rp /tmp/migrate_gitlab/gitlab /etc/
chown -R root:root /etc/gitlab

Run the restore command.

gitlab-backup restore xxxxxxxxxx_yyyy_mm_dd_13.2.2

This restore step can take quite a long time, 15GB of backup data can take more than 30 minutes to restore. Therefore, you need to note the timeout time for the server’s SSH connection.

After completing the data restore step, reconfigure Gitlab so that the system applies the configurations from the old server.

gitlab-ctl reconfigure
gitlab-ctl restart

And finally, you verify the new Gitlab system again.

gitlab-rake gitlab:check SANITIZE=true


This article has guided you step by step to migrate Gitlab from an old server to a new server. In case the migration process to the new server fails, you can still use the old server because it will not affect anything.

5 1 vote
Article Rating
Series Navigation«« Previous part: Instructions to update Gitlab CE versionNext part: Common errors when using SSH keys on Gitlab »»

You may also like

Notify of
1 Comment
Oldest Most Voted
Inline Feedbacks
View all comments
3 years ago

Bai viet qua hay!
Cho e hoi giua migrate va backup/restore co nhung gi khac nhau vay admin?

Last edited 3 years ago by ndakhang

DevOps Lite is a personal blog specializing in technology with main topics about DevOps, DevSecOps, SRE and System Administrator. Articles are shared for free and contributed to the community.



Subscribe my Newsletter for new blog posts. Stay updated from your inbox!

© 2021-2024 DevOpsLite.com – All rights reserved.

Please write sources “DevOpsLite.com” when using articles from this website.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More

Would love your thoughts, please comment.x

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.