gitlab 升級
背景
現在的gitlab版本是13.0.1,目標是 14.9.5 因爲,這個版本及以後支持禪道集成。
升級過程
- 先備份數據
gitlab-rake gitlab:backup:create
#有兩個文件需要手工備份
#gitlab.rb路徑:/etc/gitlab/gitlab.rb
#gitlab-secrets.json路徑:/etc/gitlab/gitlab-secrets.json
#備份文件名稱爲1681869286_2023_04_19_13.0.1_gitlab_backup.tar
#運行備份數據到命令,備份文件默認在/var/opt/gitlab/backups ,如果沒有請查找/etc/gitlab/gitlab.rb backup相關配置 容器的話也可以在對應的目錄下找到 如 /usr/local/src/lyy/gitlab/data/backups
- 先升級到最近的主版本,之後再依次進行升級,在docker hub找到對應版本的鏡像 然後修改docker-compose.yaml文件
image: 'gitlab/gitlab-ce:13.0.14-ce.0'
- 然後執行升級命令
docker-compose down && docker-compose up -d
- 啓動成功,確認正常進行下一個版本更新,版本順序
docker pull gitlab/gitlab-ce:13.0.14-ce.0
docker pull gitlab/gitlab-ce:13.8.8-ce.0
docker pull gitlab/gitlab-ce:13.12.15-ce.0
docker pull gitlab/gitlab-ce:14.0.12-ce.0
docker pull gitlab/gitlab-ce:14.3.6-ce.0
docker pull gitlab/gitlab-ce:14.9.5-ce.0
docker pull gitlab/gitlab-ce:14.10.5-ce.0
docker pull gitlab/gitlab-ce:15.0.5-ce.0
docker pull gitlab/gitlab-ce:15.1.6-ce.0
遇到的問題
- 按照直覺上來就升級到目錄版本,無法啓動,提示請按照流程升級。
- 權限問題 執行如下命令
docker exec -it gitlab update-permissions
- 問題如下
gitlab | ActiveRecord::StatementInvalid (PG::UndefinedTable: ERROR: relation "services" does not exist
gitlab | LINE 8: WHERE a.attrelid = '"services"'::regclass
首先參考鏈接5,執行了如下語句
gitlab-rake gitlab:check SANITIZE=true
# 不能登錄了 error 500
gitlab-rake db:migrate:status
然後參考鏈接6 使用gitlab-psql執行了修改sql語句
gitlab-psql
ALTER TABLE Integrations RENAME TO Services;
- 問題如下
gitlab | ==> /var/log/gitlab/gitlab-exporter/current <==
gitlab | 2023-04-19_06:22:49.46623 E, [2023-04-19T06:22:49.466177 #796] ERROR -- : Error connecting to the database: ERROR: column ci_builds.commands does not exist
gitlab | 2023-04-19_06:22:49.46624 LINE 30: ci_builds.commands
執行參考原來的升能,進行了小版本的替換,換成了14.1.8-ce.0。官方給的是此版本修復了這個問題。
- 問題如下
gitlab | ==> /var/log/gitlab/gitlab-rails/production.log <==
gitlab |
gitlab | ActionView::Template::Error (PG::UndefinedTable: ERROR: relation "integrations" does not exist
gitlab | LINE 8: WHERE a.attrelid = '"integrations"'::regclass
受第四個問題的影響,和查了相關的資料,就是把之前改過的表再手動改回來
gitlab-psql
ALTER TABLE Services RENAME TO Integrations;
- 問題如下
StandardError: An error has occurred, all later migrations canceled:
Expected batched background migration for the given configuration to be marked as 'finished', but it is 'active':
{:job_class_name=>"CopyColumnUsingBackgroundMigrationJob", :table_name=>"push_event_payloads", :column_name=>"event_id", :job_arguments=>[["event_id"], ["event_id_convert_to_bigint"]]}
參考鏈接8,9 執行如下語句
# 此命令是報錯提示要執行的
sudo gitlab-rake gitlab:background_migrations:finalize[CopyColumnUsingBackgroundMigrationJob,push_event_payloads,event_id,'[["event_id"]\, ["event_id_convert_to_bigint"]]']
sudo gitlab-rake db:migrate
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart
參考文章
- https://docs.gitlab.com/ee/update/
- https://www.cnblogs.com/faberbeta/p/16341131.html
- https://www.cnblogs.com/faberbeta/p/16341131.html
- https://www.cnblogs.com/colder/p/16650365.html
- https://gitlab.com/gitlab-org/omnibus-gitlab/-/issues/6352
- https://stackoverflow.com/questions/71927588/gitlab-ce-500-error-after-upgrade-downgrade
- https://docs.gitlab.com/ee/update/plan_your_upgrade.html
- https://forum.gitlab.com/t/upgrading-gitlab-from-14-0-to-14-3-2-fails-due-to-migration-issues/59479/8
- https://docs.gitlab.com/ee/update/background_migrations.html#database-migrations-failing-because-of-batched-background-migration-not-finished
- https://gitlab.com/gitlab-org/gitlab/-/issues/26845