公司老的服務(wù)器即將到期,且不準(zhǔn)備續(xù)期(打算在公司賬號下新買ECS服務(wù)器,舊的服務(wù)器是在個人賬號下購買的),舊服務(wù)器上的gitlab服務(wù)需要遷移到新的服務(wù)器上坎匿。
由于Gitlab自身的兼容性問題待侵,高版本的Gitlab無法恢復(fù)低版本gitlab備份的數(shù)據(jù)胶滋。要么新服務(wù)器安裝和舊服務(wù)器一樣版本的gitlab,部署好環(huán)境后開始備份和數(shù)據(jù)遷移;要么舊服務(wù)器上的gitlab按步驟升級到最新版本后再備份,新服務(wù)器上直接安裝最新版本皆的,并恢復(fù)對應(yīng)版本的數(shù)據(jù)覆履。
強(qiáng)迫癥用戶肯定選擇升級到最新版啊。gitlab的版本升級也比較個性费薄,下邊請看我慢慢道來:
安全起見硝全,舊服務(wù)器升級Gitlab前,建議先備份數(shù)據(jù)(雖然是老版本的楞抡,但總比丟失了的好)伟众。
查詢版本及備份
查看gitlab版本(二選一):
cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
gitlab-rake gitlab:env:info
備份10.3.3版本數(shù)據(jù)
gitlab-rake gitlab:backup:create RAILS_ENV=production
備份后的文件一般是位于/var/opt/gitlab/backups下, 自動生成文件名文件名如1541739348_2018_11_09_10.3.3_gitlab_backup.tar
升級路線 10.3.3 ---> 10.8.7 ---> 11.4.5 (10.8.7是版本10中的最后一個版本)
創(chuàng)建升級所需文件 touch /etc/gitlab/skip-auto-migrations
yum install gitlab-ce
#直接升級最新版本報(bào)錯如下
gitlab preinstall: It seems you are upgrading from 10.x version series
gitlab preinstall: to 11.x series. It is recommended to upgrade
gitlab preinstall: to the last minor version in a major version series first before
gitlab preinstall: jumping to the next major version.
gitlab preinstall: Please follow the upgrade documentation at https://docs.gitlab.com/ee/policy/maintenance.html#upgrade-recommendations
gitlab preinstall: and upgrade to 10.8 first.
error: %pre(gitlab-ce-11.4.5-ce.0.el7.x86_64) scriptlet failed, exit status 1
Error in PREIN scriptlet in rpm package gitlab-ce-11.4.5-ce.0.el7.x86_64
gitlab-ce-10.3.3-ce.0.el7.x86_64 was supposed to be removed but is not!
Verifying : gitlab-ce-10.3.3-ce.0.el7.x86_64 1/2
Verifying : gitlab-ce-11.4.5-ce.0.el7.x86_64 2/2
Failed:
gitlab-ce.x86_64 0:10.3.3-ce.0.el7 gitlab-ce.x86_64 0:11.4.5-ce.0.el7
Complete!
舊服務(wù)器上安裝的gitlab版本是10.3.3,最新的gitlab版本是11.4.5召廷,要從10.版本升級到11.版本需要先升級到10.*的最后一個版本官方是這么規(guī)定的凳厢。
yum install gitlab-ce-10.8.7
#從10.3.3先升級到10.8.7 升級成功 信息如下
Running handlers:
Running handlers complete
Chef Client finished, 0/1 resources updated in 07 seconds
Checking PostgreSQL executables: OK
Found /etc/gitlab/skip-auto-migrations, exiting...
_______ __ __ __
/ ____(_) /_/ / ____ _/ /_
/ / __/ / __/ / / __ `/ __ \
/ /_/ / / /_/ /___/ /_/ / /_/ /
\____/_/\__/_____/\__,_/_.___/
Upgrade complete! If your GitLab server is misbehaving try running
sudo gitlab-ctl restart
before anything else.
If you need to roll back to the previous version you can use the database
backup made during the upgrade (scroll up for the filename).
Verifying : gitlab-ce-10.8.7-ce.0.el7.x86_64 1/2
Verifying : gitlab-ce-10.3.3-ce.0.el7.x86_64 2/2
Updated:
gitlab-ce.x86_64 0:10.8.7-ce.0.el7
Complete!
升級到10.8.7后重新初始化一下配置并重啟gitlab
gitlab-ctl reconfigure
gitlab-ctl restart
訪問重啟后的gitlab,查看是否成功;繼而升到最新版本(11.4.5)
yum install gitlab-ce
#10.8.7升級11.4.5 成功 信息如下
Running handlers:
Running handlers complete
Chef Client finished, 0/1 resources updated in 10 seconds
Checking PostgreSQL executables: OK
Found /etc/gitlab/skip-auto-reconfigure, exiting...
_______ __ __ __
/ ____(_) /_/ / ____ _/ /_
/ / __/ / __/ / / __ `/ __ \
/ /_/ / / /_/ /___/ /_/ / /_/ /
\____/_/\__/_____/\__,_/_.___/
Upgrade complete! If your GitLab server is misbehaving try running
sudo gitlab-ctl restart
before anything else.
If you need to roll back to the previous version you can use the database
backup made during the upgrade (scroll up for the filename).
Verifying : gitlab-ce-11.4.5-ce.0.el7.x86_64 1/2
Verifying : gitlab-ce-10.8.7-ce.0.el7.x86_64 2/2
Updated:
gitlab-ce.x86_64 0:11.4.5-ce.0.el7
Complete!
升級到11.4.5 執(zhí)行gitlab-ctl reconfigure
再次初始化配置,報(bào)錯如下
Deprecations:
== Prometheus ==
Detected Prometheus version 1.x. Version 1.x has been deprecated and support will be removed in GitLab version 12.0.
To upgrade to Promtheus 2.x, use `gitlab-ctl prometheus-upgrade` command.
Running this command will migrate all your existing data to format supported by Prometheus 2.x.
This can be a time consuming operation. To skip migrating the data, and instead remove and start fresh, run `gitlab-ctl prometheus-upgrade --skip-data-migration`.
Check https://docs.gitlab.com/omnibus/update/gitlab_11_changes.html#11-4 for details.
---
gitlab Reconfigured!
按照給出的信息升級gitlab-ctl prometheus-upgrade
并重啟gitlab-ctl restart
,應(yīng)該就可正常訪問11.4.5版本的gitlab了竞慢。
gitlab-rake gitlab:backup:create RAILS_ENV=production
#再次備份最新版本的數(shù)據(jù)先紫,并查看相應(yīng)文件
ll /var/opt/gitlab/backups
total 152K
-rw------- 1 git git 80K Nov 8 19:51 1541677863_2018_11_08_11.4.5_gitlab_backup.tar
-rw-r--r-- 1 root root 70K Nov 8 18:56 1541739348_2018_11_09_10.3.3_gitlab_backup.tar
數(shù)據(jù)遷移
新的服務(wù)器上安裝最新(11.4.5)版本的gitlab,CentOS7安裝請參考。
scp -pr 1541677863_2018_11_08_11.4.5_gitlab_backup.tar root@10.211.55.12:/var/opt/gitlab/backups
#把對應(yīng)版本的數(shù)據(jù)從舊服務(wù)器上拷貝到新服務(wù)器的gitlab備份目錄里
#新服務(wù)器執(zhí)行恢復(fù)命令
chown -R git.git /var/opt/gitlab/backups/
gitlab-rake gitlab:backup:restore RAILS_ENV=production BACKUP=1541677863_2018_11_08_11.4.5
注意:這里沒有后面的_gitlab_backup.tar名字
一路yes筹煮,恢復(fù)是會先刪除新服務(wù)器上所有g(shù)itlab數(shù)據(jù)的遮精。
恢復(fù)完數(shù)據(jù)后gitlab-ctl restart
重啟,即可正常訪問到原有的gitlab數(shù)據(jù)了
參考1
參考2