summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2018-12-13 11:06:20 +0000
committerDouwe Maan <douwe@gitlab.com>2018-12-13 11:06:20 +0000
commitfc897f0860103522db9c6c316156064f1c78b01d (patch)
treec906b1ca7e5c95add9e55ba5232b62cda7ee6b3a
parent42f45ed2d93baa5b2b2f2c51f5bd8527acf1df95 (diff)
parent89a407dc3bea38b60e06eb825991cbea0c87b85a (diff)
downloadgitlab-ce-fc897f0860103522db9c6c316156064f1c78b01d.tar.gz
Merge branch 'zj-backup-restore-object-pools' into 'master'
Restore Object Pools when restoring an object pool Closes gitaly#1355 See merge request gitlab-org/gitlab-ce!23682
-rw-r--r--app/models/pool_repository.rb4
-rw-r--r--changelogs/unreleased/zj-backup-restore-object-pools.yml5
-rw-r--r--doc/raketasks/backup_restore.md1
-rw-r--r--lib/backup/repository.rb16
-rw-r--r--spec/lib/backup/repository_spec.rb13
-rw-r--r--spec/tasks/gitlab/backup_rake_spec.rb1
6 files changed, 39 insertions, 1 deletions
diff --git a/app/models/pool_repository.rb b/app/models/pool_repository.rb
index dbde00b5584..47da0209c2f 100644
--- a/app/models/pool_repository.rb
+++ b/app/models/pool_repository.rb
@@ -84,6 +84,10 @@ class PoolRepository < ActiveRecord::Base
source_project.repository.raw)
end
+ def inspect
+ "#<#{self.class.name} id:#{id} state:#{state} disk_path:#{disk_path} source_project: #{source_project.full_path}>"
+ end
+
private
def correct_disk_path
diff --git a/changelogs/unreleased/zj-backup-restore-object-pools.yml b/changelogs/unreleased/zj-backup-restore-object-pools.yml
new file mode 100644
index 00000000000..26e1d49aa04
--- /dev/null
+++ b/changelogs/unreleased/zj-backup-restore-object-pools.yml
@@ -0,0 +1,5 @@
+---
+title: Restore Object Pools when restoring an object pool
+merge_request: 23682
+author:
+type: added
diff --git a/doc/raketasks/backup_restore.md b/doc/raketasks/backup_restore.md
index a63656fafef..57bc71d2903 100644
--- a/doc/raketasks/backup_restore.md
+++ b/doc/raketasks/backup_restore.md
@@ -657,6 +657,7 @@ Restoring database tables:
- Loading fixture wikis...[SKIPPING]
Restoring repositories:
- Restoring repository abcd... [DONE]
+- Object pool 1 ...
Deleting tmp directories...[DONE]
```
diff --git a/lib/backup/repository.rb b/lib/backup/repository.rb
index c8a5377bfa0..184c7418e75 100644
--- a/lib/backup/repository.rb
+++ b/lib/backup/repository.rb
@@ -4,6 +4,7 @@ require 'yaml'
module Backup
class Repository
+ include Gitlab::ShellAdapter
attr_reader :progress
def initialize(progress)
@@ -75,7 +76,6 @@ module Backup
def restore
prepare_directories
- gitlab_shell = Gitlab::Shell.new
Project.find_each(batch_size: 1000) do |project|
progress.print " * #{project.full_path} ... "
@@ -118,6 +118,8 @@ module Backup
end
end
end
+
+ restore_object_pools
end
protected
@@ -159,5 +161,17 @@ module Backup
def display_repo_path(project)
project.hashed_storage?(:repository) ? "#{project.full_path} (#{project.disk_path})" : project.full_path
end
+
+ def restore_object_pools
+ PoolRepository.includes(:source_project).find_each do |pool|
+ progress.puts " - Object pool #{pool.disk_path}..."
+
+ pool.source_project ||= pool.member_projects.first.root_of_fork_network
+ pool.state = 'none'
+ pool.save
+
+ pool.schedule
+ end
+ end
end
end
diff --git a/spec/lib/backup/repository_spec.rb b/spec/lib/backup/repository_spec.rb
index fdeea814bb2..5ace5c5b1a2 100644
--- a/spec/lib/backup/repository_spec.rb
+++ b/spec/lib/backup/repository_spec.rb
@@ -67,6 +67,19 @@ describe Backup::Repository do
end
end
end
+
+ context 'restoring object pools' do
+ it 'schedules restoring of the pool' do
+ pool_repository = create(:pool_repository, :failed)
+ pool_repository.delete_object_pool
+
+ subject.restore
+
+ pool_repository.reload
+ expect(pool_repository).not_to be_failed
+ expect(pool_repository.object_pool.exists?).to be(true)
+ end
+ end
end
describe '#prepare_directories', :seed_helper do
diff --git a/spec/tasks/gitlab/backup_rake_spec.rb b/spec/tasks/gitlab/backup_rake_spec.rb
index 8c4360d4cf0..3b8f7f5fe7d 100644
--- a/spec/tasks/gitlab/backup_rake_spec.rb
+++ b/spec/tasks/gitlab/backup_rake_spec.rb
@@ -74,6 +74,7 @@ describe 'gitlab:app namespace rake task' do
it 'invokes restoration on match' do
allow(YAML).to receive(:load_file)
.and_return({ gitlab_version: gitlab_version })
+
expect(Rake::Task['gitlab:db:drop_tables']).to receive(:invoke)
expect(Rake::Task['gitlab:backup:db:restore']).to receive(:invoke)
expect(Rake::Task['gitlab:backup:repo:restore']).to receive(:invoke)