gitlab備份與恢復操作方法


 

 

github私有倉庫是收費的,有些代碼不方便托管到外面的git倉庫,因此就產生了自己搭建git服務器的需求。

好在有廣大的開源人士的貢獻,有了gitlab這一神器。

手動配置較多,直接用集成包: bitnami-gitlab-6.4.3-1-linux-x64-installer.run

=============================

假定gitlab安裝路徑為: /opt/gitlab-6.4.3-1/

全程以root用戶操作。
1.設定備份目錄:
/opt/gitlab-6.4.3-1/apps/gitlab/htdocs/config/gitlab.yml

2.備份:

有些時候會報錯: You have already activated rake 0.9.2.2,but our Gemfile requires rake 10.1.0,Using bundle exec may solve this.

原因是默認的path路徑不對,需要執行下bitnami自帶的環境變量設置腳本: use_gitlab 即可解決。


cd /opt/gitlab-6.4.3-1/
./use_gitlab
cd /opt/gitlab-6.4.3-1/apps/gitlab/htdocs
bundle exec bin/rake gitlab:backup:create RAILS_ENV=production

 

3.恢復:
BACKUP=timestamp_of_backup  #(required if more than one backup exists):

cd /opt/gitlab-6.4.3-1/
./use_gitlab
cd /opt/gitlab-6.4.3-1/apps/gitlab/htdocs
bundle exec bin/rake  gitlab:backup:restore RAILS_ENV=production   BACKUP=1405247282
chown git:git -R /opt/gitlab-6.4.3-1/apps/gitlab/repositories

 

4.crontab定時備份腳本參考:

 use_gitlab使用了exec,腳本會重新打開一個進程,沒有上下文,所以需要單獨提出path.

腳本需要使用root賬戶運行。腳本包含了rsync遠程同步到nas相應目錄中,按照自己實際修改即可(預先生成ssh證書,免密碼登錄)。

 

#!/bin/bash if [ `id -u` -ne 0 ];then echo "this backup script must be exec as root." exit fi date PATH="/opt/gitlab-6.4.3-1/apps/gitlabci/gitlabci-runner/bin:/opt/gitlab-6.4.3-1/apps/gitlab/gitlab-shell/bin:/opt/gitlab-6.4.3-1/redis/bin:/opt/gitlab-6.4.3-1/sqlite/bin:/opt/gitlab-6.4.3-1/python/bin:/opt/gitlab-6.4.3-1/perl/bin:/opt/gitlab-6.4.3-1/git/bin:/opt/gitlab-6.4.3-1/ruby/bin:/opt/gitlab-6.4.3-1/mysql/bin:/opt/gitlab-6.4.3-1/apache2/bin:/opt/gitlab-6.4.3-1/common/bin:$PATH" echo "backup gitlab to local storage begin.. " cd /opt/gitlab-6.4.3-1/apps/gitlab/htdocs bundle exec bin/rake gitlab:backup:create RAILS_ENV=production echo "rsync -avzP --delete /data/backups_gitlab xxx@xxx.com:/mnt/disk1/docs/rsync_gitlab_backup" rsync -avzP --delete /data/backups_gitlab xxx@xxx.com:/mnt/disk1/docs/rsync_gitlab_backup/ date echo "this job is end."

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM