Gitlab 升級備份遷移

公司老的服務(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

原文鏈接

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末败潦,一起剝皮案震驚了整個濱河市本冲,隨后出現(xiàn)的幾起案子准脂,更是在濱河造成了極大的恐慌,老刑警劉巖眼俊,帶你破解...
    沈念sama閱讀 218,204評論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件意狠,死亡現(xiàn)場離奇詭異,居然都是意外死亡疮胖,警方通過查閱死者的電腦和手機(jī)环戈,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,091評論 3 395
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來澎灸,“玉大人院塞,你說我怎么就攤上這事⌒哉眩” “怎么了拦止?”我有些...
    開封第一講書人閱讀 164,548評論 0 354
  • 文/不壞的土叔 我叫張陵,是天一觀的道長糜颠。 經(jīng)常有香客問我汹族,道長,這世上最難降的妖魔是什么其兴? 我笑而不...
    開封第一講書人閱讀 58,657評論 1 293
  • 正文 為了忘掉前任顶瞒,我火速辦了婚禮,結(jié)果婚禮上元旬,老公的妹妹穿的比我還像新娘榴徐。我一直安慰自己,他們只是感情好匀归,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,689評論 6 392
  • 文/花漫 我一把揭開白布坑资。 她就那樣靜靜地躺著,像睡著了一般穆端。 火紅的嫁衣襯著肌膚如雪袱贮。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,554評論 1 305
  • 那天体啰,我揣著相機(jī)與錄音攒巍,去河邊找鬼。 笑死狡赐,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的钦幔。 我是一名探鬼主播枕屉,決...
    沈念sama閱讀 40,302評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼鲤氢!你這毒婦竟也來了搀擂?” 一聲冷哼從身側(cè)響起西潘,我...
    開封第一講書人閱讀 39,216評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎哨颂,沒想到半個月后喷市,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,661評論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡威恼,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,851評論 3 336
  • 正文 我和宋清朗相戀三年品姓,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片箫措。...
    茶點(diǎn)故事閱讀 39,977評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡腹备,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出斤蔓,到底是詐尸還是另有隱情植酥,我是刑警寧澤,帶...
    沈念sama閱讀 35,697評論 5 347
  • 正文 年R本政府宣布弦牡,位于F島的核電站友驮,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏驾锰。R本人自食惡果不足惜卸留,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,306評論 3 330
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望稻据。 院中可真熱鬧艾猜,春花似錦、人聲如沸捻悯。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,898評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽今缚。三九已至算柳,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間姓言,已是汗流浹背瞬项。 一陣腳步聲響...
    開封第一講書人閱讀 33,019評論 1 270
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留何荚,地道東北人囱淋。 一個月前我還...
    沈念sama閱讀 48,138評論 3 370
  • 正文 我出身青樓,卻偏偏與公主長得像餐塘,于是被迫代替她去往敵國和親妥衣。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,927評論 2 355

推薦閱讀更多精彩內(nèi)容