Gitalb migration and update

gitlab-logo-squareGitalb migration (v.8.2.4) from a source installation MySQL to omnibus PostgreSQL and update to the last version.

Could be used to all versions above 8.0.0.

New server.

Prepare new server, in my case, will centos7.

# mkdir /root/from_old/

# yum -y install epel-release

# yum install vim mc git ed iotop telnet htop curl policycoreutils openssh-server openssh-clients tmux

Old server.

To check gitlab version do on existing server:

# cat /home/git/gitlab/VERSION

in my case, I created backup manually (could be using automotive command)

dump mysql

# mysqldump –compatible=postgresql –default-character-set=utf8 -B gitlabhq_production > /root/gitlabhq_production.dump.sql

copy information to the new server:


#rsync -a /home/git/repositories

static files 

  • # rsync -a /home/git/gitlab/public/uploads


server  (this keys should be copied to avoid appear of the warning message of DNS spoofing detected)

archive directory /etc/ssh_conf (dot ant the end is important)

# tar -zcvf /root/ssh.tar.gz -C /etc/ssh .

# scp /root/ssh.tar.gz

users (keys of the gitlab’s users)

# scp /home/git/.ssh/authorized_keys

nginx ssl certs

# scp /etc/nginx/ssl/gitlab.*

db dump

# scp /root/gitlabhq_production.dump.sql

New server . Unpack and move data

# hostname

# vim /etc/hostname

# vim /etc/hosts

# yum install postfix

# systemctl enable postfix

# systemctl start postfix

# systemctl status postfix.service

change to your hostname myhostname =

# vim /etc/postfix/

# service postfix restart

# firewall-cmd –permanent –add-service=http

# systemctl reload firewalld

add gitlab source list

# curl -sS | sudo bash

install gitlab of the same version as in the old server (example 8.2.4).

# yum –showduplicates list gitlab-ce | expand |grep 8.2.4

# yum install gitlab-ce-8.2.4

# gitlab-ctl stop

# mkdir /root/from_old/

# vim /etc/gitlab/gitlab.rb

file gitlab.rb

# gitlab-ctl reconfigure

# gitlab-ctl stop

get database  converter

# git clone

convert gitlabhq_production.mysql

# python mysql-postgresql-converter/ /root/from_old/gitlabhq_production.dump.sql /root/from_old/pg_dump.psql

drop index

# ed -s /root/from_old/pg_dump.psql < mysql-postgresql-converter/move_drop_indexes.ed


# rsync -a /root/from_old/repositories/ /var/opt/gitlab/git-data/repositories

# chown -R git: /var/opt/gitlab/git-data/repositories

static files

# /bin/cp -rf /root/from_old/uploads/* /opt/gitlab/embedded/service/gitlab-rails/public/uploads/

# chown -R git: /opt/gitlab/embedded/service/gitlab-rails/public/uploads/



# tar -zxvf /root/from_old/ssh.tar.gz -C /etc/ssh/

rights should be like in the screenshot


users (keys of the users)

replace paths to the according to the new installation

# sed -i ‘s/\/home\/git\/gitlab-shell\/bin\/gitlab-shell/\/opt\/gitlab\/embedded\/service\/gitlab-shell\/bin\/gitlab-shell/’ /root/from_old/authorized_keys

# cat /root/from_old/authorized_keys >> /var/opt/gitlab/.ssh/authorized_keys

# gitlab-ctl start

change symlink in repository hooks

# cd /var/opt/gitlab/git-data/repositories/

# find . -lname /home/git/gitlab-shell/hooks -exec sh -c ‘ln -snf /opt/gitlab/embedded/service/gitlab-shell/hooks $0’ {} \;

db dump

# gitlab-ctl start postgresql

connect to postgresql and look who are the owner of gitlabhq_production db

# sudo -u gitlab-psql /opt/gitlab/embedded/bin/psql -h /var/opt/gitlab/postgresql -d gitlabhq_production

in the postgres prompt type \l


# ctrl + d

push dump to postgres db

# cp /root/from_old/pg_dump.psql /tmp/

# sudo -u gitlab-psql /opt/gitlab/embedded/bin/psql -h /var/opt/gitlab/postgresql -f /tmp/pg_dump.psql -d gitlabhq_production

change permission on tables and sequences to the respective user (amount and names could be different depending on version)

# for i in abuse_reports application_settings audit_events broadcast_messages ci_application_settings ci_builds ci_commits ci_events ci_jobs ci_projects ci_runner_projects ci_runners ci_services ci_sessions ci_taggings ci_tags ci_trigger_requests ci_triggers ci_variables ci_web_hooks deploy_keys_projects emails events forked_project_links identities issues keys label_links labels lfs_objects lfs_objects_projects members merge_request_diffs merge_requests milestones namespaces notes oauth_access_grants oauth_access_tokens oauth_applications project_import_data projects protected_branches releases schema_migrations sent_notifications services snippets subscriptions taggings tags users users_star_projects web_hooks; do sudo -u gitlab-psql /opt/gitlab/embedded/bin/psql -h /var/opt/gitlab/postgresql -d gitlabhq_production -c “alter table \”$i\” owner to gitlab”; done

# for i in abuse_reports_id_seq application_settings_id_seq audit_events_id_seq broadcast_messages_id_seq ci_application_settings_id_seq ci_builds_id_seq ci_commits_id_seq ci_events_id_seq ci_jobs_id_seq ci_projects_id_seq ci_runner_projects_id_seq ci_runners_id_seq ci_services_id_seq ci_sessions_id_seq ci_taggings_id_seq ci_tags_id_seq ci_trigger_requests_id_seq ci_triggers_id_seq ci_variables_id_seq ci_web_hooks_id_seq deploy_keys_projects_id_seq emails_id_seq events_id_seq forked_project_links_id_seq identities_id_seq issues_id_seq keys_id_seq label_links_id_seq labels_id_seq lfs_objects_id_seq lfs_objects_projects_id_seq members_id_seq merge_request_diffs_id_seq merge_requests_id_seq milestones_id_seq namespaces_id_seq notes_id_seq oauth_access_grants_id_seq oauth_access_tokens_id_seq oauth_applications_id_seq project_import_data_id_seq projects_id_seq protected_branches_id_seq releases_id_seq sent_notifications_id_seq services_id_seq snippets_id_seq subscriptions_id_seq taggings_id_seq tags_id_seq users_id_seq users_star_projects_id_seq web_hooks_id_seq; do sudo -u gitlab-psql /opt/gitlab/embedded/bin/psql -h /var/opt/gitlab/postgresql -d gitlabhq_production -c “alter sequence \”$i\” owner to gitlab”; done

# gitlab-ctl restart

# yum update gitlab-ce



If you get 500 status code entering via UI to some of the repo and you get this error:

Started GET "/user/repo" for at 2016-10-16 11:49:01 -0300
Processing by ProjectsController#show as HTML
 Parameters: {"namespace_id"=>"user", "id"=>"repo"}
Completed 500 Internal Server Error in 253ms (ActiveRecord: 35.7ms)

OpenSSL::Cipher::CipherError (bad decrypt):
 app/models/project.rb:419:in `import_url'
 app/models/project.rb:449:in `external_import?'
 app/models/project.rb:441:in `import?'
 app/models/project.rb:457:in `import_in_progress?'
 app/controllers/projects_controller.rb:93:in `show'
 lib/gitlab/middleware/go.rb:16:in `call'

in log /var/log/gitlab/gitlab-rails/production.log h, then you probably should copy from the old to the new server parameter ‘db_key_base‘ from file /etc/gitlab/gitlab-secrets.json (more info

Leave a comment