1. 程式人生 > 其它 >Gitlab備份、遷移、恢復和升級

Gitlab備份、遷移、恢復和升級

自建的Gitlab伺服器常常會因為使用時間的增長,其空間容量等硬體需求都需要升級,或者遷移至更高配置的伺服器上。備份、遷移、恢復、升級過程如下

1、gitlab備份

備份前gitlab的專案如圖所示

備份時需要保持gitlab處於正常執行狀態,直接執行gitlab-rake gitlab:backup:create進行備份

使用以上命令會在/var/opt/gitlab/backups目錄下建立一個名稱類似為1530156812_2018_06_28_10.8.4_gitlab_backup.tar的壓縮包, 這個壓縮包就是Gitlab整個的完整部分, 其中開頭的1530156812_2018_06_28_10.8.4是備份建立的日期

/etc/gitlab/gitlab.rb 配置檔案須備份

/var/opt/gitlab/nginx/conf nginx配置檔案

/etc/postfix/main.cfpostfix 郵件配置備份

1.1 修改備份檔案目錄

可以通過/etc/gitlab/gitlab.rb配置檔案來修改預設存放備份檔案的目錄

gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"

修改完成之後使用gitlab-ctl reconfigure命令過載配置檔案即可

1.2 設定備份過期時間

[root@gitlab ~]# vim /etc/gitlab/gitlab.rb

gitlab_rails['backup_keep_time'] = 604800#以秒為單位

1.3 gitlab自動備份

建立定時任務

[root@gitlab ~]# crontab -e

0 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create

2、gitlab遷移

遷移的整體思路是:

1、在新伺服器上安裝相同版本的gitlab

2、將備份生成的備份檔案傳送到新伺服器的相同目錄下

這裡在10.0.0.6的機器上安裝了相同版本的gitlab並能正常執行使用

在老伺服器上將備份檔案傳送至新伺服器的相應目錄下

[root@gitlab ~]# scp /var/opt/gitlab/backups/1530156812_2018_06_28_10.8.4_gitlab_backup.tar [email protected]:/var/opt/gitlab/backups/

3、gitlab恢復

[root@gitlab ~]# gitlab-ctl stop unicorn#停止相關資料連線服務

[root@gitlab ~]# gitlab-ctl stop sidekiq

[root@gitlab-new ~]# chmod 777 /var/opt/gitlab/backups/1530156812_2018_06_28_10.8.4_gitlab_backup.tar

#修改許可權,如果是從本伺服器恢復可以不修改

[root@gitlab ~]# gitlab-rake gitlab:backup:restore BACKUP=1530156812_2018_06_28_10.8.4

#從1530156812_2018_06_28_10.8.4編號備份中恢復

按照提示輸入兩次yes並回車

[root@gitlab ~]# gitlab-ctl start#啟動gitlab

瀏覽器訪問新伺服器的地址進行檢視,遷移成功

在實際情況中訪問gitlab可能是用域名訪問,我們可以修改gitlab配置檔案中的url再進行備份,這樣就不會影響遷移過程,恢復完成後需要進行的只是修改域名對應的dns解析ip地址

4、gitlab升級

[root@gitlab ~]# gitlab-ctl stop#關閉gitlab服務

[root@gitlab ~]# gitlab-rake gitlab:backup:create#備份

下載新版gitlab的rpm包安裝,安裝時選擇升級

安裝的過程中可能會出現報錯

Error executing action `run` on resource 'ruby_block[directory resource: /var/opt/gitlab/git-data/repositories]'

解決方法為

[root@gitlab ~]# chmod 2770 /var/opt/gitlab/git-data/repositories

安裝成功後重新載入配置並啟動

[root@gitlab ~]# gitlab-ctl reconfigure

[root@gitlab ~]# gitlab-ctl restart

5、gitlab更改預設的nginx

[root@gitlab ~]# vim /etc/gitlab/gitlab.rb

nginx['enable'] = false#不啟用nginx

檢查預設nginx配置檔案,並遷移至新Nginx服務

/var/opt/gitlab/nginx/conf/nginx.conf #nginx配置檔案,包含gitlab-http.conf檔案

/var/opt/gitlab/nginx/conf/gitlab-http.conf #gitlab核心nginx配置檔案

重啟 nginx、gitlab服務

[root@gitlab ~]# gitlab-ctl restart

[root@gitlab ~]# systemctl restart nginx.service

訪問可能出現報502。原因是nginx使用者無法訪問gitlab使用者的socket檔案。 重啟gitlab需要重新授權

[root@gitlab ~]# chmod -R o+x /var/opt/gitlab/gitlab-rails

參考來源:http://www.xuliangwei.com/xubusi/803.html