Migrate GitLab Server

· ☕ 3 min read · 🤖 jfdesignnet
🏷️
  • #gitlab
  • Introduction

    Due to server management changes and preservation, we had to move the ongoing production GitLab server to another virtual cloud server. Other than that reason, the old server that using proxmox is already really outdated and imposible to upgrade due to hardware spec limitation, so this is a good time to move to another cloud server with latest proxmox virtualization.

    However, migrating or moving any production server always have an own risk. Especially, if the running production server version is outdated and the system administrator never or cannot update them due to company policy or else. The other problem is the OS version, sometimes the old GitLab version cannot installed to new OS version due to package dependencies librares or else.

    So, there are 2 possibility here :

    1. Upgrade the GitLab version on old server so it have the same version with on the new server, then use the backup/restore function to migrate the data. This is a high risk method, especially if the GitLab version is too old and there are problem during upgrading.
    2. Use the same old GitLab version on new server. This is safer for the data but it's not easy if the GitLab version is no longer supported on the new OS version server.

    Fortunately on this case, I am their system administrator. I always update the GitLab version on the old server to the latest stable version, so on this case I'm using possibility number 1.

    Migration steps

    On OLD server :

    1. Shutdown GitLab services

       sudo gitlab-ctl stop unicorn
       sudo gitlab-ctl stop sidekiq
       sudo gitlab-ctl stop puma
      
    2. Run the GitLab backup

       sudo gitlab-rake gitlab:backup:create
      
    3. create folder migration and backup all the necessary data :

       etc/gitlab/gitlab.rb
       etc/gitlab/gitlab-secrets.json
       etc/gitlab/ssl/*
       etc/gitlab/config_backup/*
       var/opt/gitlab/backup/*
      
    4. scp those backup data to new server

    On NEW server :

    1. install gitlab-ce

       curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash
       apt-get install gitlab-ce
      
    2. copy all the old data from folder migration back to etc/gitlab

       gitlab.rb gitlab-secrets.json ssl/* config_backup/*
      
    3. run gitlab configure to initialize installation

       sudo gitlab-ctl reconfigure
      

      it will finish without problem and tell you something about the root password should empty, and you should change on the next login and so on, just ignore it

    4. shutdown the service

       sudo gitlab-ctl stop unicorn
       sudo gitlab-ctl stop sidekiq
       sudo gitlab-ctl stop puma
      
    5. copy the backup repo

       sudo cp gitlab-old/XXXXXXXXXX_gitlab_backup.tar /var/opt/gitlab/backups
      
    6. change the owner to git

       sudo chown git.git /var/opt/gitlab/backups/XXXXXXXXXX_gitlab_backup.tar
      
    7. run the GitLab restore

       sudo gitlab-rake gitlab:backup:restore BACKUP=XXXXXXXXX
      

      (remember to only supply the backupname XXXX only, without _gitlab_backup.tar)
      this should be a long wait depends on the repo size.

    8. start the service again

       sudo gitlab-ctl start
      
    9. check all

       sudo gitlab-rake gitlab:check SANITIZE=true
      
    10. done

    Wrapping up

    That's it.
    The new gitlab server is running perfectly now. oh no ! anyway, back to code. see you.