1. 程式人生 > >GIt的備份和恢復

GIt的備份和恢復

gitlab備份 恢復

1、GItlab備份

Gitlab默認的備份路徑都是在配置文件中指定的,所以我們可以去配置文件中查看

vim /etc/gitlab/gitlab.rb

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

我們需要修改配置如下,激活

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

創建備份目錄和授權

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

重新加載配置,讓配置生效

gitlab-cli reconfigure
gitlab-cli restart

備份:

gitlab的備份非常簡單,就是一條命令

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

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

這個壓縮包就是Gitlab整個的完整部分, 其中開頭的1494780002是備份創建的日期,可以通過date命令來查看這個uninx時間戳

[[email protected] app1]# ll /var/opt/gitlab/backups/
total 112
-rw------- 1 git git 112640 May 15 00:40 1494780002_gitlab_backup.tar
[[email protected] 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天,異地永久保存

2、GItlab恢復

恢復流程:

1、停止數據寫入任務

gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq

2、恢復數據

gitlab-rake gitlab:backup:restore BACKUP=1494780002

3、啟動服務

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

3、只備份代碼

如果只備份代碼可以在這個目錄下面去備份對應項目的代碼,用戶的關系不能備份走

[[email protected] app1]# cd /var/opt/gitlab/
[[email protected] gitlab]# ls
backups       gitlab-ci     gitlab-workhorse  postgresql
bootstrapped  gitlab-rails  logrotate         redis
git-data      gitlab-shell  nginx             trusted-certs-directory-hash
[[email protected] gitlab]# cd git-data/
[[email protected] git-data]# ls
repositories
[[email protected] git-data]# cd repositories/
[[email protected] 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
[[email protected] repositories]#







本文出自 “圈中一鳥” 博客,謝絕轉載!

GIt的備份和恢復