Commit aa1dd6f5 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch '233430-design-repo-in-backup' into 'master'

Include Design repositories in GitLab backup

See merge request gitlab-org/gitlab!43947
parents ebdaeb78 b0127668
---
title: Include Design Management git repositories in GitLab Backup
merge_request: 43947
author:
type: fixed
......@@ -45,6 +45,7 @@ module Backup
Project.find_each(batch_size: 1000) do |project|
restore_repository(project, Gitlab::GlRepository::PROJECT)
restore_repository(project, Gitlab::GlRepository::WIKI)
restore_repository(project, Gitlab::GlRepository::DESIGN)
end
restore_object_pools
......@@ -118,6 +119,7 @@ module Backup
def dump_project(project)
backup_repository(project, Gitlab::GlRepository::PROJECT)
backup_repository(project, Gitlab::GlRepository::WIKI)
backup_repository(project, Gitlab::GlRepository::DESIGN)
end
def backup_repository(container, type)
......
......@@ -75,7 +75,7 @@ FactoryBot.define do
end
# Use this trait if you want versions in a particular history, but don't
# want to pay for gitlay calls.
# want to pay for gitaly calls.
trait :with_versions do
transient do
deleted { false }
......
......@@ -21,13 +21,15 @@ RSpec.describe Backup::Repositories do
RSpec.shared_examples 'creates repository bundles' do
specify :aggregate_failures do
# Add data to the wiki repository, so it will be included in the dump.
# Add data to the wiki and design repositories, so they will be included in the dump.
create(:wiki_page, container: project)
create(:design, :with_file, issue: create(:issue, project: project))
subject.dump(max_concurrency: 1, max_storage_concurrency: 1)
expect(File).to exist(File.join(Gitlab.config.backup.path, 'repositories', project.disk_path + '.bundle'))
expect(File).to exist(File.join(Gitlab.config.backup.path, 'repositories', project.disk_path + '.wiki' + '.bundle'))
expect(File).to exist(File.join(Gitlab.config.backup.path, 'repositories', project.disk_path + '.design' + '.bundle'))
end
end
......@@ -157,7 +159,8 @@ RSpec.describe Backup::Repositories do
it 'restores repositories from bundles', :aggregate_failures do
next_path_to_bundle = [
Rails.root.join('spec/fixtures/lib/backup/project_repo.bundle'),
Rails.root.join('spec/fixtures/lib/backup/wiki_repo.bundle')
Rails.root.join('spec/fixtures/lib/backup/wiki_repo.bundle'),
Rails.root.join('spec/fixtures/lib/backup/design_repo.bundle')
].to_enum
allow_next_instance_of(described_class::BackupRestore) do |backup_restore|
......@@ -170,12 +173,16 @@ RSpec.describe Backup::Repositories do
expect(collect_commit_shas.call(project.repository)).to eq(['393a7d860a5a4c3cc736d7eb00604e3472bb95ec'])
expect(collect_commit_shas.call(project.wiki.repository)).to eq(['c74b9948d0088d703ee1fafeddd9ed9add2901ea'])
expect(collect_commit_shas.call(project.design_repository)).to eq(['c3cd4d7bd73a51a0f22045c3a4c871c435dc959d'])
end
describe 'command failure' do
before do
expect(Project).to receive(:find_each).and_yield(project)
allow_next_instance_of(DesignManagement::Repository) do |repository|
allow(repository).to receive(:create_repository) { raise 'Fail in tests' }
end
allow_next_instance_of(Repository) do |repository|
allow(repository).to receive(:create_repository) { raise 'Fail in tests' }
end
......@@ -214,6 +221,9 @@ RSpec.describe Backup::Repositories do
end
it 'cleans existing repositories' do
expect_next_instance_of(DesignManagement::Repository) do |repository|
expect(repository).to receive(:remove)
end
expect(Repository).to receive(:new).twice.and_wrap_original do |method, *original_args|
repository = method.call(*original_args)
......
......@@ -326,6 +326,7 @@ RSpec.describe 'gitlab:app namespace rake task', :delete do
let!(:project_a) { create(:project, :repository) }
let!(:project_a_wiki_page) { create(:wiki_page, container: project_a) }
let!(:project_a_design) { create(:design, :with_file, issue: create(:issue, project: project_a)) }
let!(:project_b) { create(:project, :repository, repository_storage: 'test_second_storage') }
let!(:b_storage_dir) { File.join(test_second_storage_dir, File.dirname(project_b.disk_path)) }
......@@ -341,6 +342,7 @@ RSpec.describe 'gitlab:app namespace rake task', :delete do
expect(tar_contents).to include(
"repositories/#{project_a.disk_path}.bundle",
"repositories/#{project_a.disk_path}.wiki.bundle",
"repositories/#{project_a.disk_path}.design.bundle",
"repositories/#{project_b.disk_path}.bundle"
)
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment