Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Vosmaer (GitLab) <jacob@gitlab.com>2018-05-28 12:58:14 +0300
committerDouwe Maan <douwe@gitlab.com>2018-05-28 12:58:14 +0300
commitb529d04b69c5fd8612bfa614a536d02574cb7f07 (patch)
tree3c6545b180d4d7d6dbfadab88c983a2c1d511471 /lib/backup
parenta45b9fc96ca568b19fd9d09a8b40846c2c8b5b36 (diff)
Use Gitaly's DeleteAllRepositories RPC during backup restore
Diffstat (limited to 'lib/backup')
-rw-r--r--lib/backup/repository.rb56
1 files changed, 36 insertions, 20 deletions
diff --git a/lib/backup/repository.rb b/lib/backup/repository.rb
index c3360c391af..84670d6582e 100644
--- a/lib/backup/repository.rb
+++ b/lib/backup/repository.rb
@@ -73,29 +73,40 @@ module Backup
end
def prepare_directories
- # TODO: Need to find a way to do this for gitaly
- # Gitaly discussion issue: https://gitlab.com/gitlab-org/gitaly/issues/1194
-
Gitlab.config.repositories.storages.each do |name, repository_storage|
- path = repository_storage.legacy_disk_path
- next unless File.exist?(path)
-
- # Move all files in the existing repos directory except . and .. to
- # repositories.old.<timestamp> directory
- bk_repos_path = File.join(Gitlab.config.backup.path, "tmp", "#{name}-repositories.old." + Time.now.to_i.to_s)
- FileUtils.mkdir_p(bk_repos_path, mode: 0700)
- files = Dir.glob(File.join(path, "*"), File::FNM_DOTMATCH) - [File.join(path, "."), File.join(path, "..")]
-
- begin
- FileUtils.mv(files, bk_repos_path)
- rescue Errno::EACCES
- access_denied_error(path)
- rescue Errno::EBUSY
- resource_busy_error(path)
+ delete_all_repositories(name, repository_storage)
+ end
+ end
+
+ def delete_all_repositories(name, repository_storage)
+ gitaly_migrate(:delete_all_repositories) do |is_enabled|
+ if is_enabled
+ Gitlab::GitalyClient::StorageService.new(name).delete_all_repositories
+ else
+ local_delete_all_repositories(name, repository_storage)
end
end
end
+ def local_delete_all_repositories(name, repository_storage)
+ path = repository_storage.legacy_disk_path
+ return unless File.exist?(path)
+
+ # Move all files in the existing repos directory except . and .. to
+ # repositories.old.<timestamp> directory
+ bk_repos_path = File.join(Gitlab.config.backup.path, "tmp", "#{name}-repositories.old." + Time.now.to_i.to_s)
+ FileUtils.mkdir_p(bk_repos_path, mode: 0700)
+ files = Dir.glob(File.join(path, "*"), File::FNM_DOTMATCH) - [File.join(path, "."), File.join(path, "..")]
+
+ begin
+ FileUtils.mv(files, bk_repos_path)
+ rescue Errno::EACCES
+ access_denied_error(path)
+ rescue Errno::EBUSY
+ resource_busy_error(path)
+ end
+ end
+
def restore_custom_hooks(project)
# TODO: Need to find a way to do this for gitaly
# Gitaly migration issue: https://gitlab.com/gitlab-org/gitaly/issues/1195
@@ -113,6 +124,7 @@ module Backup
def restore
prepare_directories
gitlab_shell = Gitlab::Shell.new
+
Project.find_each(batch_size: 1000) do |project|
progress.print " * #{project.full_path} ... "
path_to_project_bundle = path_to_bundle(project)
@@ -121,7 +133,6 @@ module Backup
restore_repo_success = nil
if File.exist?(path_to_project_bundle)
begin
- gitlab_shell.remove_repository(project.repository_storage, project.disk_path) if project.repository_exists?
project.repository.create_from_bundle path_to_project_bundle
restore_repo_success = true
rescue => e
@@ -146,7 +157,6 @@ module Backup
if File.exist?(path_to_wiki_bundle)
progress.print " * #{wiki.full_path} ... "
begin
- gitlab_shell.remove_repository(wiki.repository_storage, wiki.disk_path) if wiki.repository_exists?
wiki.repository.create_from_bundle(path_to_wiki_bundle)
progress.puts "[DONE]".color(:green)
rescue => e
@@ -224,5 +234,11 @@ module Backup
def display_repo_path(project)
project.hashed_storage?(:repository) ? "#{project.full_path} (#{project.disk_path})" : project.full_path
end
+
+ def gitaly_migrate(method, status: Gitlab::GitalyClient::MigrationStatus::OPT_IN, &block)
+ Gitlab::GitalyClient.migrate(method, status: status, &block)
+ rescue GRPC::NotFound, GRPC::BadStatus => e
+ raise Error, e
+ end
end
end