Commit 2bcc324f authored by DJ Mountney's avatar DJ Mountney Committed by Ahmad Hassan

Add back some of the non-gitaly restore functionality behind gates

parent 0734da16
...@@ -68,6 +68,9 @@ module Backup ...@@ -68,6 +68,9 @@ module Backup
def prepare_directories def prepare_directories
Gitlab.config.repositories.storages.each do |name, repository_storage| Gitlab.config.repositories.storages.each do |name, repository_storage|
gitaly_migrate(:remove_repositories) do |is_enabled|
# TODO: Need to find a way to do this for gitaly
unless is_enabled
path = repository_storage.legacy_disk_path path = repository_storage.legacy_disk_path
next unless File.exist?(path) next unless File.exist?(path)
...@@ -86,22 +89,49 @@ module Backup ...@@ -86,22 +89,49 @@ module Backup
end end
end end
end end
end
end
def restore def restore
prepare_directories prepare_directories
gitlab_shell = Gitlab::Shell.new
Project.find_each(batch_size: 1000) do |project| Project.find_each(batch_size: 1000) do |project|
path_to_project_bundle = path_to_bundle(project) path_to_project_bundle = path_to_bundle(project)
path_to_project_repo = path_to_repo(project)
project.ensure_storage_path_exists
restore_repo_status = nil
if File.exist?(path_to_project_bundle) if File.exist?(path_to_project_bundle)
begin begin
project.repository.create_from_bundle path_to_project_bundle unless project.repository_exists? gitlab_shell.remove_repository(project.repository_storage, project.disk_path) if project.repository_exists?
progress.puts "[DONE] restoring #{project.name} repository".color(:green) project.repository.create_from_bundle path_to_project_bundle
rescue StandardError => e restore_repo_status = true
progress.puts "[Failed] restoring #{project.name} repository".color(:red) rescue => e
restore_repo_status = false
progress.puts "Error: #{e}".color(:red) progress.puts "Error: #{e}".color(:red)
end end
else else
progress.puts "[Failed] bundle file #{path_to_project_bundle} does not exist" restore_repo_status = gitlab_shell.create_repository(project.repository_storage, project.disk_path)
end
if restore_repo_status
progress.puts "[DONE] restoring #{project.name} repository".color(:green)
else
progress.puts "[Failed] restoring #{project.name} repository".color(:red)
end
gitaly_migrate(:restore_custom_hooks) do |is_enabled|
# TODO: Need to find a way to do this for gitaly
unless is_enabled
in_path(path_to_tars(project)) do |dir|
cmd = %W(tar -xf #{path_to_tars(project, dir)} -C #{path_to_project_repo} #{dir})
output, status = Gitlab::Popen.popen(cmd)
unless status.zero?
progress_warn(project, cmd.join(' '), output)
end
end
end
end end
wiki = ProjectWiki.new(project) wiki = ProjectWiki.new(project)
...@@ -109,6 +139,7 @@ module Backup ...@@ -109,6 +139,7 @@ module Backup
if File.exist?(path_to_wiki_bundle) if File.exist?(path_to_wiki_bundle)
begin begin
gitlab_shell.remove_repository(project.wiki.repository_storage, project.wiki.disk_path) if project.wiki_repository_exists?
project.repository.create_from_bundle(path_to_wiki_bundle) project.repository.create_from_bundle(path_to_wiki_bundle)
progress.puts "[DONE] restoring #{project.name} wiki".color(:green) progress.puts "[DONE] restoring #{project.name} wiki".color(:green)
rescue StandardError => e rescue StandardError => e
...@@ -116,6 +147,13 @@ module Backup ...@@ -116,6 +147,13 @@ module Backup
progress.puts "Error #{e}".color(:red) progress.puts "Error #{e}".color(:red)
end end
end end
gitaly_migrate(:create_hooks) do |is_enabled|
# TODO: Need to find a way to do this for gitaly
unless is_enabled
Gitlab::Git::Repository.create_hooks(path_to_project_repo, Gitlab.config.gitlab_shell.hooks_path)
end
end
end end
end end
# rubocop:enable Metrics/AbcSize # rubocop:enable Metrics/AbcSize
...@@ -190,5 +228,13 @@ module Backup ...@@ -190,5 +228,13 @@ module Backup
def display_repo_path(project) def display_repo_path(project)
project.hashed_storage?(:repository) ? "#{project.full_path} (#{project.disk_path})" : project.full_path project.hashed_storage?(:repository) ? "#{project.full_path} (#{project.disk_path})" : project.full_path
end 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
# Old Popen code returns [Error, output] to the caller, so we
# need to do the same here...
raise Error, e
end
end end
end 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