iPhoneで Grafanaの グラフを 参照できる アプリ Grafanizer 作ってます。 詳しくは こちらへ

GitLabを他のマシンに載せ替える方法

Jan 21, 2014  
#gitlab #env

遊んでるサーバーにテスト的に導入してみた GitLab が思いの外使えるので本格的に使用すべく性能が良いサーバーに格上げするためにデータ移行するという、よくあるパターンの作業メモ。

元ネタはこちらから拝借したのだけど、Debのパッケージ使ってたり内容が古かったりしたので簡単にまとめてみる。 (参考)Gitlabの移行作業

全体の流れとしては、

  1. 移行元で GitLab を最新版にあげておく
  2. 移行先で最新版の GitLab をインストールしておく
  3. 移行元の /home/git を 移行先の /home/git にコピー
  4. MySQLのデータを移行元から mysqldump で取り出し、移行先のMySQLに突っ込む

だけでいける。簡単に言うと。 移行先と移行元で「git」ユーザーが同じUIDなことが前提。

でも、ところどころハマるところがあるので、以下作業ログ。

まずはここらへんを参考にして、移行元の GitLab を最新版にアップデートさせる。

アップデート後の今回の環境は以下のとおり。基本的にインストールマニュアル通りにインストールして、アップデートマニュアル通りにアップデートさせてきた感じ。

# sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production

System information
System:         Ubuntu 13.04
Current User:   git
Using RVM:      no
Ruby Version:   1.9.3p392
Gem Version:    1.8.23
Bundler Version:1.3.5
Rake Version:   10.1.0

GitLab information
Version:        6.4.3
Revision:       38397db
Directory:      /home/git/gitlab
DB Adapter:     mysql2
URL:            http://git.example.net
HTTP Clone URL: http://git.example.net/some-project.git
SSH Clone URL:  git@git.example.net:some-project.git
Using LDAP:     yes
Using Omniauth: no

GitLab Shell
Version:        1.8.0
Repositories:   /home/git/repositories/
Hooks:          /home/git/gitlab-shell/hooks/
Git:            /usr/bin/git

次にここらへんを参考にして、移行先に最新版の GitLab をインストールする。最終的には移行元のファイルで上書きするんだけど、ライブラリのインストールとかも含めて全部やっておくと安心。

これで移行元と移行先の環境が整ったので、実際のデータの移行を始める。今回は古いサーバーの方にWebDAVサーバーを立ててあったので、そこ経由でデータをやりとりすることにした。USBメモリとかあればそっちのほうが楽だと思うので、その場合は curl コマンドを無視してください。

まずは移行元サーバーでの作業。

cd /home

# gitlab-satellitesは後から再作成するしbundle/rubyは移行先の環境で入れなおすんで不要
sudo tar zPcvf git.tar.gz --exclude gitlab-satellites --exclude bundle/ruby git
sudo mysqldump -u gitlab -p -n gitlabhq_production > ~/dump

# WebDAV以外でデータをやりとりする場合は不要
curl --upload git.tar.gz http://example.net/dav/
curl --upload ~/dump http://example.net/dav/

次は移行先サーバーでの作業

# WebDAV以外でデータをやりとりする場合は不要
curl -O http://example.net/dav/git.tar.gz
curl -O http://example.net/dav/dump

cd /home

# 新しく作ったGitLabの環境に移行元の環境を上書き
sudo tar zxvfp ~/git.tar.gz
# MySQLにダンプを突っ込む
cat ~/dump | mysql -u root -p gitlabhq_production

# Rubyライブラリの入れなおし
sudo -u git -H bundle install --deployment --without development test postgres aws
# gitlab-satellitesの再作成
sudo -u git -H bundle exec rake gitlab:satellites:create RAILS_ENV=production

# インストールマニュアル通りにやってきたのだが、途中でユーザー名が「git」から「gitlab」に変わったみたい
mysql -u root -p
create user 'gitlab'@'localhost' identified by 'XXXXX';
grant select, lock tables, insert, update, delete, create, drop, index, alter on `gitlabhq_production`.* to 'gitlab'@'localhost';

# 環境確認と再起動
sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
/etc/init.d/gitlab restart
/etc/init.d/nginx restart
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production

うまく行けばこれで移行完了なはず。

ちなみに移行後の環境はこんな感じ。

# sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production

System information
System:         Debian 7.3
Current User:   git
Using RVM:      no
Ruby Version:   2.0.0p353
Gem Version:    2.0.14
Bundler Version:1.5.1
Rake Version:   10.1.0

GitLab information
Version:        6.4.3
Revision:       38397db
Directory:      /home/git/gitlab
DB Adapter:     mysql2
URL:            http://git.example.net
HTTP Clone URL: http://git.example.net/some-project.git
SSH Clone URL:  git@git.example.net:some-project.git
Using LDAP:     yes
Using Omniauth: no

GitLab Shell
Version:        1.8.0
Repositories:   /home/git/repositories/
Hooks:          /home/git/gitlab-shell/hooks/
Git:            /usr/bin/git

UbuntuからDebian、Rubyのバージョンも1.9から2.0へアップグレードで問題なく移行できた。 思ったより簡単!Gitlab素晴らしい!

オリジナルポストは こちら