LoginSignup
1

More than 5 years have passed since last update.

GitLab で OpenStack Swift 上にバックアップ

Posted at

GitLabのバックアップ先をOpenStack Swift(オブジェクトストレージ)に設定してみました。

動作環境

  • CentOS 7.2
  • GitLab 8.4.4

OpenStackのSwiftにアクセスできるユーザとコンテナを作成

省略

gitlabの設定ファイル変更

/etc/gitlab/gitlab.rb

gitlab_rails['backup_upload_connection'] = {
  'provider' => 'OpenStack',
  'openstack_auth_url' => 'https://xxxxxx/v2.0/tokens',
  'openstack_username' => 'gitlab',
  'openstack_api_key' => 'password',
  'openstack_tenant' => 'test',
}
gitlab_rails['backup_upload_remote_directory'] = 'gitlab'

gitlabの設定更新とバックアップ

gitlab-ctl reconfigure
gitlab-rake gitlab:backup:create

OpenStack Swift上にtarで固められたファイルを確認できます。

cronに登録

省略

GitLabでバックアップ先に指定できるクラウドストレージ

GitLabはfogというライブラリを利用しています。
fogのサポートしているクラウドストレージを下記から確認できます。
http://fog.io/about/supported_services.html

バックアップの保持期間

backup_keep_timeはローカルバックアップだけでしか機能しません。
このままでは、クラウドストレージの容量が圧迫されてしまうため、削除さるように変更してみました。

/opt/gitlab/embedded/service/gitlab-rails/lib/backup/manager.rb
77c77
<       $progress.print "Deleting old backups ... \n"
---
>       $progress.print "Deleting old backups ... "
83,91d82
<         remote_directory = Gitlab.config.backup.upload.remote_directory
<         connection_settings = Gitlab.config.backup.upload.connection
<         if connection_settings.blank?
<           $progress.puts "skipped".yellow
<           return
<         end
<         connection = ::Fog::Storage.new(connection_settings)
<         directory = connection.directories.get(remote_directory)
<
98,102d88
<               if directory.files.get("#{timestamp}_gitlab_backup.tar").destroy
<                 puts "#{timestamp}_gitlab_backup.tar removed".red
<               else
<                 puts "#{timestamp}_gitlab_backup.tar failed".red
<               end

設定ファイルに下記を追記します。(保存期間1週間)

gitlab_rails['backup_keep_time'] = 7 * 24 * 60 * 60

再度gitlab-ctl reconfigureします。

参考

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1