Table of Contents
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.
- 192.168.1.10: old gitlab server.
- 192.168.1.11: 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.
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 -yWhen 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 sidekiqCreate a folder containing backup data.
mkdir /tmp/migrate_gitlabCreate a backup of gitlab data, note that you need to check the available disk space before backing up.
gitlab-backup createCopy 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_gitlabMove 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 sidekiqCopy 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/gitlabRun the restore command.
gitlab-backup restore xxxxxxxxxx_yyyy_mm_dd_13.2.2This 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 restartAnd finally, you verify the new Gitlab system again.
gitlab-rake gitlab:check SANITIZE=trueConclusion
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.
Bai viet qua hay!
Cho e hoi giua migrate va backup/restore co nhung gi khac nhau vay admin?