Commit 3d6e880f authored by Zeger-Jan van de Weg's avatar Zeger-Jan van de Weg Committed by Bob Van Landuyt

Remove DeleteAllRepositories RPC

Introduced in COMMIT ID,
parent 18049a7c
......@@ -41,12 +41,6 @@ module Backup
end
end
def prepare_directories
Gitlab.config.repositories.storages.each do |name, _repository_storage|
Gitlab::GitalyClient::StorageService.new(name).delete_all_repositories
end
end
def backup_project(project)
path_to_project_bundle = path_to_bundle(project)
Gitlab::GitalyClient::RepositoryService.new(project.repository)
......@@ -75,13 +69,13 @@ module Backup
end
def restore
prepare_directories
Project.find_each(batch_size: 1000) do |project|
progress.print " * #{project.full_path} ... "
path_to_project_bundle = path_to_bundle(project)
project.repository.remove rescue nil
restore_repo_success = nil
if File.exist?(path_to_project_bundle)
begin
project.repository.create_from_bundle(path_to_project_bundle)
......
# frozen_string_literal: true
module Gitlab
module GitalyClient
class StorageService
def initialize(storage)
@storage = storage
end
# Delete all repositories in the storage. This is a slow and VERY DESTRUCTIVE operation.
def delete_all_repositories
request = Gitaly::DeleteAllRepositoriesRequest.new(storage_name: @storage)
GitalyClient.call(@storage, :storage_service, :delete_all_repositories, request, timeout: GitalyClient.long_timeout)
end
end
end
end
......@@ -83,30 +83,6 @@ describe Backup::Repository do
end
end
describe '#prepare_directories', :seed_helper do
before do
allow(FileUtils).to receive(:mkdir_p).and_call_original
allow(FileUtils).to receive(:mv).and_call_original
end
after(:all) do
ensure_seeds
end
it' removes all repositories' do
# Sanity check: there should be something for us to delete
expect(list_repositories).to include(File.join(SEED_STORAGE_PATH, TEST_REPO_PATH))
subject.prepare_directories
expect(list_repositories).to be_empty
end
def list_repositories
Dir[File.join(SEED_STORAGE_PATH, '*.git')]
end
end
describe '#empty_repo?' do
context 'for a wiki' do
let(:wiki) { create(:project_wiki) }
......
......@@ -2254,7 +2254,7 @@ describe Gitlab::Git::Repository, :seed_helper do
end
describe '#remove' do
let(:project) { create(:project, :repository)}
let(:project) { create(:project, :repository) }
let(:repository) { project.repository }
it 'removes the repository' do
......@@ -2264,5 +2264,17 @@ describe Gitlab::Git::Repository, :seed_helper do
expect(repository.raw_repository.exists?).to be false
end
context 'when the repository does not exist' do
let(:repository) { create(:project).repository }
it 'is idempotent' do
expect(repository.exists?).to be false
repository.remove
expect(repository.raw_repository.exists?).to be false
end
end
end
end
require 'spec_helper'
describe Gitlab::GitalyClient::StorageService do
describe '#delete_all_repositories' do
let!(:project) { create(:project, :repository) }
it 'removes all repositories' do
described_class.new(project.repository_storage).delete_all_repositories
expect(project.repository.exists?).to be(false)
end
end
end
......@@ -117,6 +117,45 @@ describe 'gitlab:app namespace rake task' do
expect(raw_repo.empty?).to be(true)
end
end
context 'when the backup is restored' do
let!(:included_project) { create(:project, :repository) }
before do
expect { run_rake_task('gitlab:backup:create') }.to output.to_stdout
backup_tar = Dir.glob(File.join(Gitlab.config.backup.path, '*_gitlab_backup.tar')).last
allow(Dir).to receive(:glob).and_return([backup_tar])
allow(File).to receive(:exist?).and_return(true)
allow(Kernel).to receive(:system).and_return(true)
allow(FileUtils).to receive(:cp_r).and_return(true)
allow(FileUtils).to receive(:mv).and_return(true)
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)
expect(Rake::Task['gitlab:backup:builds:restore']).to receive(:invoke)
expect(Rake::Task['gitlab:backup:uploads:restore']).to receive(:invoke)
expect(Rake::Task['gitlab:backup:artifacts:restore']).to receive(:invoke)
expect(Rake::Task['gitlab:backup:pages:restore']).to receive(:invoke)
expect(Rake::Task['gitlab:backup:lfs:restore']).to receive(:invoke)
expect(Rake::Task['gitlab:backup:registry:restore']).to receive(:invoke)
expect(Rake::Task['gitlab:shell:setup']).to receive(:invoke)
# We only need a backup of the repositories for this test
stub_env('SKIP', 'db,uploads,builds,artifacts,lfs,registry')
end
it 'restores the data' do
expect { run_rake_task('gitlab:backup:restore') }.to output.to_stdout
raw_repo = included_project.repository.raw
expect(raw_repo.empty?).to be(false)
end
end
end # backup_restore task
describe 'backup' do
......
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