Introduction:
Migrating a GitLab server backup to a new server requires a systematic approach to ensure data integrity, minimal downtime, and a seamless transition. In this guide, we will cover every step in detail, from preparing the backup to configuring the new server and restoring the data. This process is done if the both the GitLab servers have same version and prerequisites.
1- Preparing for the Migration
Before performing migration activity, review the target server, such as installing GitLab version and system requirements.
- Access to the current GitLab server (old server).
- A newly set up server with the same or compatible operating system.
- Sufficient disk space to accommodate the backup.
- Proper user permissions and SSH access.
Check the GitLab Version
To prevent compatibility issues, ensure the new server has the same GitLab version as the old server. Run the following command on the old server:
sudo gitlab-rake gitlab:env:infoIf the GitLab versions are mismatched on both servers, then perform the necessary operations by upgrading or Downgrading Gitlab server versions. Then, the backup is transferred from the source server to the target server using secure file transfer methods.
2- Create a GitLab Backup on the Old Server
To create a backup on your current server, you can use the GitLab following command
$ sudo gitlab-rake gitlab:backup:create
By default, the backup is stored in /var/opt/gitlab/backups/1685286600_2023_05_28_15.9.3-ee_gitlab_backup.tar. dentify the latest backup file:

show the list of files available in backup folder
ls -lh /var/opt/gitlab/backups/Copy the backup file name, as you will need it later. Additionally, back up GitLab configuration files:
sudo cp /etc/gitlab/gitlab.rb /var/opt/gitlab/backups/
sudo cp /etc/gitlab/gitlab-secrets.json /var/opt/gitlab/backups/3- Transfer Backup Files to the New Server
Transfer Backup file to new Gitlab server.
The first step is to copy the backup from the source server. You can use various methods such as WinSCP, SFTP (Secure File Transfer Protocol), or a file synchronization tool like rsync. In my case I have used WinSCP to transfer file.

After successfully transferring the GitLab server backup to the target server, you need to place the backup file in a location where it is easily accessible during the migration process.
4- Install GitLab on the New Server
You can easily install gitLab server on Ubuntu server following ” How to install Gitlab on Ubuntu server“
5- Restore the GitLab Backup
Stop services
Now, stop the processes which are related to the database by using the below commands.
sudo gitlab-ctl stop unicorn
sudo gitlab-ctl stop sidekiqVerify Status
You can verify status of the GitLab services by using the below command
sudo gitlab-ctl statusconfigure Gitlab repository path as configured in previous server in /etc/gitlab/gitlab.rb
git_data_dirs ({
"default" => {"path" => "/var/opt/gitlab/git-data"},
"alternative" => { "path" => "/var/opt/gitlab/gitstorage" }
})Restore backup
Now, restore the backup by using the timestamp of the backup copy
sudo gitlab-rake gitlab:backup:restore BACKUP = 1685286600_2023_05_28_15.9.3-ee_gitlab_backup.tarCopy Gitlab Configuration Files
Once the restore completes, restore the configuration files:
sudo cp /etc/gitlab/gitlab.rb /etc/gitlab/
sudo cp /etc/gitlab/gitlab-secrets.json /etc/gitlab/Reconfigure GitLab:
sudo gitlab-ctl reconfigureRestart Gitlab services
Restart the GitLab components by using the below command
sudo gitlab-ctl restart
Now check the GitLab by sanitizing the database as shown below
sudo gitlab-rake gitlab:check SANITIZE = trueVerify that the migration was successful by accessing your GitLab web interface and checking repositories, users, and settings.
6- Post-Migration Tasks
Check Logs for Errors
Run the following command to check for any issues:
sudo gitlab-ctl tailReindex GitLab Data
To ensure search and repository indexing works properly, reindex GitLab data:
sudo gitlab-rake gitlab:elastic:reindexUpdate DNS and Firewall Rules
If the new server has a different IP address, update your DNS records accordingly. Also, check and update firewall rules:
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enableHow to Downgrade Gitlab Server from 16.0.1.ee to 15.9.3.ee: A step by step Guide.
Migrating your GitLab backup to a new server doesn’t have to be complicated. By following this step-by-step guide, you ensure data integrity, minimal downtime, and a seamless transition.
FAQs
1. Can I migrate GitLab to a server with a different OS?
Yes, but ensure the necessary dependencies and configurations match the original setup.
2. What happens if my backup is corrupted?
You may need to generate a new backup or restore from an older, verified backup.
3. How can I reduce downtime during migration?
Perform the migration during off-peak hours and use incremental backups.
4. Do I need to update GitLab after migration?
It is recommended to keep GitLab updated for security and performance improvements.