GIt的備份和恢復

一、GItlab備份node

Gitlab默認的備份路徑都是在配置文件中指定的,因此咱們能夠去配置文件中查看
linux

vim /etc/gitlab/gitlab.rb
nginx

# gitlab_rails['manage_backup_path'] = true
# gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"
#在配置文件中咱們須要注意這兩條,定義備份位置

咱們須要修改配置以下,激活git

gitlab_rails['backup_keep_time'] = 604800 #這個是秒,7天的時間
gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"

建立備份目錄和受權
redis

 mkdir -p /var/opt/gitlab/backups
 chown -R git.git /var/opt/gitlab/backups

從新加載配置,讓配置生效sql

gitlab-cli reconfigure
gitlab-cli restart

備份:shell

gitlab的備份很是簡單,就是一條命令bootstrap

 /usr/bin/gitlab-rake gitlab:backup:create

執行完上面的備份命令後,會在備份目錄下面生成一個相似這樣的文件1494780002_gitlab_backup.tarvim

這個壓縮包就是Gitlab整個的完整部分, 其中開頭的1494780002是備份建立的日期,能夠經過date命令來查看這個uninx時間戳bash

[root@linux-node1 app1]# ll /var/opt/gitlab/backups/
total 112
-rw------- 1 git git 112640 May 15 00:40 1494780002_gitlab_backup.tar
[root@linux-node1 app1]# date -d @1494780002
Mon May 15 00:40:02 CST 2017

須要備份的文件有:

/etc/gitlab/gitlab.rb 配置文件須備份 
/var/opt/gitlab/nginx/conf nginx配置文件 
/etc/postfix/main.cfpostfix 郵件配置備份

系統自動備份,設置定時任務

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

建議,本地保留7天,異地永久保存

二、GItlab恢復

恢復流程:

一、中止數據寫入任務

gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq

二、恢復數據

gitlab-rake gitlab:backup:restore BACKUP=1494780002

三、啓動服務

gitlab-ctl restart
或者啓動上面關閉的那兩個服務

三、只備份代碼

若是隻備份代碼能夠在這個目錄下面去備份對應項目的代碼,用戶的關係不能備份走

[root@linux-node1 app1]# cd /var/opt/gitlab/
[root@linux-node1 gitlab]# ls
backups       gitlab-ci     gitlab-workhorse  postgresql
bootstrapped  gitlab-rails  logrotate         redis
git-data      gitlab-shell  nginx             trusted-certs-directory-hash
[root@linux-node1 gitlab]# cd git-data/
[root@linux-node1 git-data]# ls
repositories
[root@linux-node1 git-data]# cd repositories/
[root@linux-node1 repositories]# ll
total 0
drwxrwx--- 2 git git  6 May  7 14:09 dev1
drwxrwx--- 2 git git  6 May  7 15:12 dev2
drwxrwx--- 4 git git 41 May 14 21:19 Group1
drwxrwx--- 2 git git  6 May 14 21:12 GYH
drwxrwx--- 2 git git  6 May  7 15:12 pm
drwxrwx--- 2 git git  6 May  7 14:05 proje1
drwxrwx--- 4 git git 43 May  7 14:03 root
drwxrwx--- 2 git git  6 May 14 21:11 YH01
drwxrwx--- 2 git git  6 May 14 21:11 YH02
[root@linux-node1 repositories]#
相關文章
相關標籤/搜索