一.gitlab的備份
1.1 建立備份目錄,並受權
1
2
3
4
|
[root@linux-node1 ~]
# mkdir /data/backups/gitlab -p
[root@linux-node1 ~]
# chown -R git.git /data/
[root@linux-node1 ~]
# ll /data/ -d
drwxr-xr-x 3 git git 20 Dec 20 16:21
/data/
|
1.2 修改gitlab配置
1
2
3
4
5
6
7
8
9
|
設置備份路徑
[root@7mini-node1 ~]
# vim /etc/gitlab/gitlab.rb
201 gitlab_rails[
'backup_path'
] =
"/data/backups/gitlab"
#備份路徑
204 gitlab_rails[
'backup_keep_time'
] = 604800
#備份7天
[root@7mini-node1 ~]
# mkdir -p /data/backups/gitlab
[root@7mini-node1 ~]
# gitlab-ctl reconfigure
[root@7mini-node1 ~]
# gitlab-ctl restart
|
1.3.定時任務備份html
1
2
|
[root@7mini-node1 ~]
# crontab -l
0 2 * * *
/usr/bin/gitlab-rake
gitlab:backup:create
|
1.4.手動執行腳本進行備份java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
/usr/bin/gitlab-rake
gitlab:backup:create
Dumping database ...
Dumping PostgreSQL database gitlabhq_production ... [DONE]
done
Dumping repositories ...
* java
/app1
... [DONE]
* java
/app1
.wiki ... [SKIPPED]
[root@7mini-node1 ~]
# cd /data/backups/gitlab/
[root@7mini-node1 gitlab]
# ls
1525934310_gitlab_backup.
tar
[root@7mini-node1 gitlab]
# ll
total 80
-rw------- 1 git git 81920 May 10 14:38 1525934310_gitlab_backup.
tar
[root@7mini-node1 gitlab]
# date -d @1525934310
Thu May 10 14:38:30 CST 2018
|
1.5 恢復備份
node
刪除gitlab中的app1的項目,再恢復
中止數據寫入服務:linux
1
2
3
4
|
[root@7mini-node1 ~]
# gitlab-ctl stop unicorn
ok: down: unicorn: 1s, normally up
[root@7mini-node1 ~]
# gitlab-ctl stop sidekiq
ok: down: sidekiq: 0s, normally up
|
恢復數據
1
2
|
[root@7mini-node1 ~]
# gitlab-rake gitlab:backup:restore BACKUP=1525934310
[root@7mini-node1 ~]
# gitlab-ctl restart
|
丟失的文件又還原了 nginx
二.gitlab遷移git
遷移如同備份與恢復的步驟同樣, 只須要將老服務器/var/opt/gitlab/backups
目錄下的備份文件拷貝到新服務器上的/var/opt/gitlab/backups
便可(若是你沒修改過默認備份目錄的話).
可是須要注意的是新服務器上的Gitlab的版本必須與建立備份時的Gitlab版本號相同.(注意必須相同,不然會出現問題的)vim
好比新服務器安裝的是最新的9.52版本的Gitlab, 那麼遷移以前, 能夠將老服務器的Gitlab 升級爲9.52在進行備份ruby
1
2
|
/etc/gitlab/gitlab
.rb gitlab 配置文件須遷移,遷移後須要調整數據存放目錄
/var/opt/gitlab/nginx/conf
nginx配置文件目錄須遷移
|
還原bash
1
2
3
4
5
6
|
[root@linux-node1 ~]
# gitlab-ctl stop unicorn
ok: down: unicorn: 0s, normally up
[root@linux-node1 ~]
# gitlab-ctl stop sidekiq
ok: down: sidekiq: 0s, normally up
[root@linux-node1 ~]
# chmod 777 /var/opt/gitlab/backups/1481598919_gitlab_backup.tar
[root@linux-node1 ~]
# gitlab-rake gitlab:backup:restore BACKUP=1481598919
|
三.gitlab升級與出現問題解決辦法服務器
下載gitlab的RPM包並進行升級
1
2
|
官網下載最新版本 gitlab對應軟件包 [gitlab官網](https:
//packages
.gitlab.com
/gitlab/gitlab-ce/packages/el/7/gitlab-ce-8
.12.13-ce.0.el7.x86_64.rpm)
使用 rpm -Uvh gitlab-ce-8.12.13-ce.0.el7.x86_64
|
若是直接升級出現以下報錯
1
2
3
4
|
報錯.
Error executing action `run` on resource
'ruby_block[directory resource: /var/opt/gitlab/git-data/repositories]'
解決方法:
sudo
chmod
2770
/var/opt/gitlab/git-data/repositories
|
查看版本信息
1
2
|
[root@localhost backups]
# head -1 /opt/gitlab/version-manifest.txt
gitlab-ce 9.5.2
|
更換gitlab自帶Nginx,使用自行編譯Nginx來管理gitlab服務。
編輯gitlab配置文件禁用自帶Nignx服務器
1
2
3
4
5
|
vi
/etc/gitlab/gitlab
.rb
...
#設置nginx爲false,關閉自帶Nginx
nginx[
'enable'
] =
false
...
|
檢查默認nginx配置文件,並遷移至新Nginx服務
1
2
|
/var/opt/gitlab/nginx/conf/nginx
.conf
#nginx配置文件,包含gitlab-http.conf文件
/var/opt/gitlab/nginx/conf/gitlab-http
.conf
#gitlab核心nginx配置文件
|
重啓 nginx、gitlab服務
1
2
|
gitlab-ctl reconfigure
service nginx restart
|
出現502報錯
1
|
chmod
-R o+x
/var/opt/gitlab/gitlab-rails
|
1
2
3
4
5
6
7
8
9
10
11
12
|
126郵件配置:
gitlab_rails[
'time_zone'
] =
'Asia/Shanghai'
gitlab_rails[
'gitlab_email_enabled'
] =
true
gitlab_rails[
'gitlab_email_from'
] =
'xiaoming@126.com'
#發件郵箱設置
gitlab_rails[
'gitlab_email_display_name'
] =
'gitlab'
gitlab_rails[
'smtp_enable'
] =
true
gitlab_rails[
'smtp_address'
] =
"smtp.126.com"
gitlab_rails[
'smtp_port'
] = 25
gitlab_rails[
'smtp_user_name'
] =
"xiaoming"
gitlab_rails[
'smtp_password'
] =
"your password"
gitlab_rails[
'smtp_domain'
] =
"126.com"
gitlab_rails[
'smtp_authentication'
] =
"login"
|
本篇博客轉載:https://www.cnblogs.com/jimmy-xuli/p/9019894.html