0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

dockerで構築したgitlabの移行作業

Posted at

はじめに

docker上で構築しているgitlabについて移行する必要が出てきたのですが、意外と苦戦したので移行手順をまとめます。
今回はgitlabサーバーを立ち上げているvm(centos)を新しいvm(ubuntu)に移行する形です。

前提条件

Docker,GitLabの導入が実施済みであること。

gitlabの構築の仕方などは省略します、基本的には移行前と同じように構築していけば問題ないはずです。。。
また、作業は基本的にvscode内で行なっています。

データ移行

事前準備

  • 複数ファイルをアーカイブする(移行前vm内)
    gitlab内の設定などを新規vmに移行するため、圧縮処理を行います

    sudo tar -cvf gitlab_config_backup.tar.gz /srv/gitlab/config
    

  

  • 新規vmへ移行(旧vmコンテナ->新vmコンテナ)
    場所はどこでもokです

    sudo scp /home/<user名>/gitlab_config_backup.tar.gz <user名>@<サーバーipアドレス>:/home/<user名>
    

  

  • ディレクトリの解凍(移行後vm内)

    sudo tar xvf gitlab_config_backup.tar.gz -C /srv/gitlab/
    

  

  • 移行前vmの/srv/gitlab/config/gitlab.rbと/srv/gitlab/config/gitlab-secret.jsonを移行後vmの同場所に転送する

    sudo scp /srv/gitlab/config/gitlab.rb <user名>@<サーバーipアドレス>:/srv/gitlab/config
    sudo scp /srv/gitlab/config/gitlab-secret.json <user名>@<サーバーipアドレス>:/srv/gitlab/config
    

  

  • GitLabを再構成する

    gitlab-ctl reconfigure
    

  

  • ファイルを転送できるように権限を設定する(移行後vm内)

    sudo chown <user名> /srv/gitlab/backups
    
新しいサーバーの準備
  • コンテナ内部に入る(docker execコマンドやvscodeの機能から入れます)

  • /etc/gitlab/gitlab.rbにnginxの設定を追加する

    nginx['custom_gitlab_server_config'] = "location /api/v4/jobs/request {\n deny all;\n return 503;\n}\n"
    

  

  • GitLabを再設定する
    gitlab-ctl reconfigure
    

  

  • GitLabを停止する
    gitlab-ctl stop
    

  

  • RedisデータベースとGitLabバックファイルを受信できるように設定
    rm -f /var/opt/gitlab/redis/dump.rdb
    chown root /var/opt/gitlab/redis /var/opt/gitlab/backups
    
古いサーバーの準備
  • コンテナ内部に入る

  • /etc/gitlab/gitlab.rbにnginxの設定を追加する

    nginx['custom_gitlab_server_config'] = "location /api/v4/jobs/request {\n deny all;\n return 503;\n}\n"
    

  

  • GitLabを再設定する
    gitlab-ctl reconfigure
    

  

  • 定期的なバックグラウンドジョブを無効にする(参考資料 4.Disable periodic background jobs)
      
  • マイグレーションに必要なサービス以外のGitLabを停止する
    /opt/gitlab/embedded/bin/redis-cli -s /var/opt/gitlab/redis/redis.socket save && gitlab-ctl stop && gitlab-ctl start postgresql && gitlab-ctl start gitaly
    

  

  • GitLabのバックアップを作成する
    gitlab-backup create
    

  

  • gitlab.rbに設定を追加
    alertmanager['enable'] = false
    gitlab_exporter['enable'] = false
    gitlab_pages['enable'] = false
    gitlab_workhorse['enable'] = false
    grafana['enable'] = false
    logrotate['enable'] = false
    gitlab_rails['incoming_email_enabled'] = false
    nginx['enable'] = false
    node_exporter['enable'] = false
    postgres_exporter['enable'] = false
    postgresql['enable'] = false
    prometheus['enable'] = false
    puma['enable'] = false
    redis['enable'] = false
    redis_exporter['enable'] = false
    registry['enable'] = false
    sidekiq['enable'] = false
    

  

  • GitLabを再設定する
    gitlab-ctl reconfigure
    

  

  • 実行中のサービスがないことを確認する
    gitlab-ctl status
    

  

  • dump.rdbとバックアップを新しいサーバーに転送する(dump.rdbは軽いのでローカルに落としてから転送でも問題なし)
    sudo scp /srv/gitlab/backups/<your-backup>.tar <user名>@<サーバーipアドレス>:/srv/gitlab/backups
    
新しいサーバーのリストア
  • 適切なファイルシステム権限を復元する
    sudo chown root /srv/gitlab/backups
    

  

  • コンテナ内部に入る

  • 適切なファイルシステム権限を復元する(コンテナ内部)

    chown gitlab-redis /var/opt/gitlab/redis
    chown gitlab-redis:gitlab-redis /var/opt/gitlab/redis/dump.rdb
    chown git:root /var/opt/gitlab/backups
    chown git:git /var/opt/gitlab/backups/your-backup.tar
    

  

  • コンテナを再起動する

    docker restart <コンテナ名>
    
  • Dockerのリストアを行う

    gitlab-ctl stop puma
    gitlab-ctl stop sidekiq
    gitlab-ctl status
    gitlab-backup restore BACKUP=<バックアップ名>
    docker restart <コンテナ名>
    

  

最後に

容量によっては、リストアやバックアップに時間がかかるので注意(100GB以上だとそれぞれ1時間程度はかかります)

参考資料

Back up and restore GitLab

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?