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

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

自建的Gitlab服務器經常會由於使用時間的增加,其空間容量等硬件需求都須要升級,或者遷移至更高配置的服務器上。備份、遷移、恢復、升級過程以下 nginx

一、gitlab備份 git

備份前gitlab的項目如圖所示 vim

備份時須要保持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是備份建立的日期 ruby

/etc/gitlab/gitlab.rb 配置文件須備份 服務器

/var/opt/gitlab/nginx/conf nginx配置文件 socket

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

1.1 修改備份文件目錄 gitlab

能夠經過/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

 

二、gitlab遷移

遷移的總體思路是:

一、在新服務器上安裝相同版本的gitlab

二、將備份生成的備份文件發送到新服務器的相同目錄下

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

在老服務器上將備份文件發送至新服務器的相應目錄下

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

 

三、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地址

 

四、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

 

五、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

相關文章
相關標籤/搜索