How to Migrate GitLab Repositories to a New Server
Just a quick post for me to refer back to in the future. I used the steps below to migrate all GitLab repositories and database from version 3.1 to 4.1.
Migrate Database
In this case, I’m using MySQL.
-
Use mysqldump to create dump of old database, then create a new database on the new server and import this.
-
On old: mysqldump gitlab gzip > gitlab.sql.gz -
On new: gunzip < gitlab.sql.gz mysql gitlab
-
-
Run the db migrate command to make sure the schema is updated to the latest version.
- sudo -u gitlab -H bundle exec rake db:migrate RAILS_ENV=production
Migrate Repositories
- Rather than creating a new SSH key on the new server, copy over the old SSH key pair to the new server. Also copy of the authorized_keys file.
- Set up gitolite on the new server using the old SSH key
- Copy contents of /home/git/.gitolite/keydir/ from old to new server so that users don’t have to add their SSH keys again and change ownership to git:git.
- Copy repositories from old to new
- sudo chmod -R ug+rwXs,o-rwx /home/git/repositories/
- sudo chown -R git:git /home/git/repositories/
- sudo -u gitlab -H bundle exec rake gitlab:gitolite:update_keys RAILS_ENV=production
- sudo -u gitlab -H bundle exec rake gitlab:gitolite:update_repos RAILS_ENV=production
-
Update projects to use namespaces. This will move any projects that are in groups to a namespace. bundle exec rake gitlab:enable_namespaces RAILS_ENV=production
I could not get this working, easier to remove all projects from groups on the old install before migrating.
- Run the rake:check command and see if it complains about anything. You may need to run the create satellites command or the run the script to update the hooks.
bundle exec rake gitlab:check RAILS_ENV=production
sudo -u git -H /home/gitlab/lib/support/rewrite-hooks.sh
Troubleshooting
-
If you get:
FATAL: split conf set, gl-conf not present for ‘gitolite-admin’
fatal: The remote end hung up unexpectedly
Then you need to re-run the gitolite setup. This I think is because gitolite-admin is still in version 2 format.
- If you get an error “cannot load such file – rb-inotify”, you need to add gem “ib-notify” to the bottom of the gemfile and run bundle install again.
- If you get an error about invalid SSH keys, keep deleting the offending keys until the errors go away.