注意新建備份目錄是:/usr/local/src/repositories 屬主和屬組:
# ll -d repositories/ drwx------ 4 git root 4096 Feb 7 17:32 repositories/
修改配置文件:
vim /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml
## Backup settings backup: #path: "/var/opt/gitlab/backups" # Relative paths are relative to Rails.root (default: tmp/backups/) path: "/usr/local/src/repositories" # Relative paths are relative to Rails.root (default: tmp/backups/)
有些linux系統是需要改此文件:/etc/gitlab/gitlab.rb
重啟# gitlab-ctl restart
備份git:
# gitlab-rake gitlab:backup:create
恢復備份:
# gitlab-ctl stop unicorn # gitlab-ctl stop sidekiq # ls /usr/local/src/repositories/ 1484140459_gitlab_backup.tar # gitlab-rake gitlab:backup:restore BACKUP=1484140459 Unpacking backup ... #如果數據遷移的話一定要保持gitlab的版本是一至,不然會報錯!!! # gitlab-ctl start
親測:
# grep 'backup' -C 2 /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml ## Backup settings backup: path: "/var/opt/gitlab/backups" # Relative paths are relative to Rails.root (default: tmp/backups/) keep_time: # default: 0 (forever) (in seconds) #可以看到備份后的數據路徑為:/var/opt/gitlab/backups [root@GitLab backups]# pwd /var/opt/gitlab/backups [root@GitLab backups]# ls [root@GitLab backups]# gitlab-rake gitlab:backup:create Dumping database ... Dumping PostgreSQL database gitlabhq_production ... [DONE] done Dumping repositories ... * root/document ... [DONE] * root/document.wiki ... [SKIPPED] * ok/hx-it-doc ... [DONE] * ok/hx-it-doc.wiki ... [SKIPPED] done Dumping uploads ... done Creating backup archive: 1486695836_gitlab_backup.tar ... done Deleting tmp directories ... done Deleting old backups ... skipping [root@GitLab backups]# ls 1486695836_gitlab_backup.tar 數據還原: 把數據1486695836_gitlab_backup.tar 放到/var/opt/gitlab/backups中 [root@GitLab src]# gitlab-ctl stop unicorn ok: down: unicorn: 1s, normally up [root@GitLab src]# gitlab-ctl stop sidekiq ok: down: sidekiq: 0s, normally up [root@GitLab backups]# pwd /var/opt/gitlab/backups [root@GitLab backups]# ls 1486695836_gitlab_backup.tar#注意這個文件的名子是在備份的時修生成的不能改變!!!! [root@GitLab backups]# gitlab-rake gitlab:backup:restore BACKUP=1486695836 #數據版號1486695836_gitlab_backup.tar 下現在為止git數據恢復完成!!
