gitlab備份與恢復

shaonbean發表於2017-09-08

1、gitlab備份與恢復

參考:https://docs.gitlab.com/ce/ra…

# 建立系統備份
sudo gitlab-rake gitlab:backup:create
# 備份檔案存在/var/opt/gitlab/backups,可編輯/etc/gitlab/gitlab.rb修改
# 原始碼安裝使用下面命令備份
sudo -u git -H bundle exec rake gitlab:backup:create RAILS_ENV=production

# docker安裝使用下面命令備份
docker exec -t <container name:gitlab> gitlab-rake gitlab:backup:create

# 將備份上傳到遠端儲存(暫無)
# 將備份檔案儲存到本地
gitlab_rails[`backup_upload_connection`] = {
  :provider => `Local`,
  :local_root => `/mnt/backups`
}
  • The directory inside the mounted folder to copy backups to Use `.` to store them in the root directory

gitlab_rails[`backup_upload_remote_directory`] = `gitlab_backups`

備份檔案許可權

# In /etc/gitlab/gitlab.rb, for omnibus packages
gitlab_rails[`backup_archive_permissions`] = 0644 
# Makes the backup archives world-readable 備份配置檔案 針對(Omnibus)備份:/etc/gitlab/gitlab.rb 、/etc/gitlab/gitlab-secrets.json,新增定時備份
# 每天凌晨兩點備份

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

# 保留備份30天,單位秒
gitlab_rails[`backup_keep_time`] = 2592000

2、Omnibus安裝恢復

# 確認備份檔案放到gitlab.rb定義的備份目錄(預設/var/opt/gitlab/backups)
sudo cp 1504793137_2017_09_07_9.5.3_gitlab_backup.tar /var/opt/gitlab/backups/
# 停止連線資料庫的程式
sudo gitlab-ctl stop unicorn
sudo gitlab-ctl stop sidekiq
# Verify
sudo gitlab-ctl status
# 恢復備份檔案,指定時間戳
sudo gitlab-rake gitlab:backup:restore BACKUP=1504793137_2017_09_07_9.5.3
> Unpacking backup ... tar: 1504796591_2017_09_07_9.5.3_gitlab_backup.tar: Cannot open: Permission denied
chmod git:git 1504796591_2017_09_07_9.5.3_gitlab_backup.tar
# 重啟並檢查恢復情況
sudo gitlab-ctl restart
sudo gitlab-rake gitlab:check SANITIZE=true

相關文章