Commit b1bbace1 authored by James Fargher's avatar James Fargher

Move snippets check to after restoring from backup

Once backups and restores are handled by gitaly-backup we will not be
able to modify the gitlab database during a backup or restore. To work
around this we need to move all such checks to after the process has
completed. Right now this includes: validating snippets, and
rescheduling repository pool creation.
parent 2ae25491
...@@ -41,8 +41,9 @@ module Backup ...@@ -41,8 +41,9 @@ module Backup
def restore def restore
restore_project_repositories restore_project_repositories
restore_snippets restore_snippet_repositories
cleanup_snippets_without_repositories
restore_object_pools restore_object_pools
end end
...@@ -56,12 +57,10 @@ module Backup ...@@ -56,12 +57,10 @@ module Backup
end end
end end
def restore_snippets def restore_snippet_repositories
invalid_ids = Snippet.find_each(batch_size: 1000) Snippet.find_each(batch_size: 1000).each do |snippet|
.map { |snippet| restore_snippet_repository(snippet) } restore_repository(snippet, Gitlab::GlRepository::SNIPPET)
.compact end
cleanup_snippets_without_repositories(invalid_ids)
end end
def check_valid_storages! def check_valid_storages!
...@@ -214,26 +213,22 @@ module Backup ...@@ -214,26 +213,22 @@ module Backup
end end
end end
def restore_snippet_repository(snippet) # Snippets without a repository should be removed because they failed to import
restore_repository(snippet, Gitlab::GlRepository::SNIPPET) # due to having invalid repositories
def cleanup_snippets_without_repositories
invalid_snippets = []
response = Snippets::RepositoryValidationService.new(nil, snippet).execute Snippet.find_each(batch_size: 1000).each do |snippet|
response = Snippets::RepositoryValidationService.new(nil, snippet).execute
next if response.success?
if response.error?
snippet.repository.remove snippet.repository.remove
progress.puts("Snippet #{snippet.full_path} can't be restored: #{response.message}") progress.puts("Snippet #{snippet.full_path} can't be restored: #{response.message}")
snippet.id invalid_snippets << snippet.id
else
nil
end end
end
# Snippets without a repository should be removed because they failed to import Snippet.id_in(invalid_snippets).delete_all
# due to having invalid repositories
def cleanup_snippets_without_repositories(ids)
Snippet.id_in(ids).delete_all
end end
class BackupRestore class BackupRestore
......
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