Migrate Gitlab to new server


gitlab-logoWhen migrating gitlab to a new server, you might face much problems of in-compatible versions, different OS (so different latest gitlab version), etc. The best way is to upgrade the old server to the same latest gitlab version, then backup gitlab, and then transfer the backup to the new server, install same latest gitlab version in the new server, and restore it. However if you run different OSes (such as my case, the old server is Ubuntu and the new one is CentOS 7, so the current latest gitlab version at the old server is 8.5.5, while the according version at CentOS 7 is 8.8.1), then you’ll need a different approach. This short tutorial will guide you step-by-step to migrate gitlab to the new server with different OS and gitlab version.

  1. First, we’ll need to backup the gitlab at the old server:

    [bash]gitlab-rake gitlab:backup:create[/bash]

  2. Transfer it to the new server:

    [bash]scp /var/opt/gitlab/backups/XXXXXXXXX_gitlab_backup.tar root@NEW_SERVER_IP:/root/[/bash]

  3. At the new server, install exact version as in the old server. This case, it is 8.5.5. We can easily find the way to install it at gitlab repository as https://packages.gitlab.com/gitlab/gitlab-ce/packages/el/7/gitlab-ce-8.5.5-ce.0.el7.x86_64.rpm
  4. Make necessary change to your gitlab config at /etc/gitlab/gitlab.rb
  5. Run gitlab reconfigure for the first time:

    [bash]gitlab-ctl reconfigure[/bash]

  6. After gitlab is started successfully, stop unicorn and sidekiq processes:

    [bash]gitlab-ctl stop unicorn
    gitlab-ctl stop sidekiq[/bash]

  7. Move the backup to the backup folder and run restore command:

    [bash]mv /root/XXXXXXXXX_gitlab_backup.tar /var/opt/gitlab/backups/
    gitlab-rake gitlab:backup:restore BACKUP=XXXXXXXXX[/bash]

  8. Restart gitlab and check:

    [bash]gitlab-ctl start
    gitlab-rake gitlab:check SANITIZE=true[/bash]

    . If there is any error appears, follow the guide in the screen to fix. For example:

    [bash]Uploads directory setup correctly? … no
    Try fixing it:
    sudo chown -R git /var/opt/gitlab/gitlab-rails/uploads
    sudo find /var/opt/gitlab/gitlab-rails/uploads -type f -exec chmod 0644 {} \;
    sudo find /var/opt/gitlab/gitlab-rails/uploads -type d -not -path /var/opt/gitlab/gitlab-rails/uploads -exec chmod 0700 {} \;
    For more information see:
    doc/install/installation.md in section "GitLab"
    Please fix the error above and rerun the checks.[/bash]

  9. After the migration step is finished, upgrade gitlab at the new server to the latest version:

    [bash]yum install -y gitlab-ce[/bash]

  10. Check your gitlab version:

    [bash]gitlab-rake gitlab:env:info[/bash]

  11. Enjoy 🙂

Some Gitlab Tips

  1. If you run gitlab on a low-end spec node (e.g. 768 – 1G RAM for example), you might often face the 502 error due to one process timeout error. In most case, gitlab cannot allocate enough memory for processes to respond in time. So one tip is to increasing the default timeout of gitlab’s processes.
    1. We’ll need to edit /etc/gitlab/gitlab.rb and change the following values (in the most case, we will see that we’ll need to increase the unicorn timeout value):

      [bash]gitlab_rails[‘git_timeout’] = 60 #Commit read timeout, default value is 10
      unicorn[‘worker_timeout’] = 300 # unicorn timeout, default value is 60
      [/bash]

    2. Then, run

      [bash]gitlab-ctl reconfigure[/bash]

  2. If you change URL, in the git client, just update it with git command line:

    [bash]git remote set-url origin https://your-new-url.com/your-repo-url.git[/bash]


About NhocConan

A super lazy guy who tries to write tech blog entries in English.He is lazy, so he can only write when he is in a good mood or when he is tired of coding.

Leave a comment

Your email address will not be published. Required fields are marked *