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:
    gitlab-rake gitlab:backup:create
  2. Transfer it to the new server:
    scp /var/opt/gitlab/backups/XXXXXXXXX_gitlab_backup.tar [email protected]_SERVER_IP:/root/
  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:
    gitlab-ctl reconfigure
  6. After gitlab is started successfully, stop unicorn and sidekiq processes:
    gitlab-ctl stop unicorn
    gitlab-ctl stop sidekiq
  7. Move the backup to the backup folder and run restore command:
    mv /root/XXXXXXXXX_gitlab_backup.tar /var/opt/gitlab/backups/
    gitlab-rake gitlab:backup:restore BACKUP=XXXXXXXXX
  8. Restart gitlab and check:
    gitlab-ctl start
    gitlab-rake gitlab:check SANITIZE=true

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

    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.
  9. After the migration step is finished, upgrade gitlab at the new server to the latest version:
    yum install -y gitlab-ce
  10. Check your gitlab version:
    gitlab-rake gitlab:env:info
  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):
      gitlab_rails['git_timeout'] = 60 #Commit read timeout, default value is 10
      unicorn['worker_timeout'] = 300 # unicorn timeout, default value is 60
      
    2. Then, run
      gitlab-ctl reconfigure
  2. If you change URL, in the git client, just update it with git command line:
    git remote set-url origin https://your-new-url.com/your-repo-url.git

Leave a Reply