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
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/backup/manager.rb19
-rw-r--r--lib/backup/repositories.rb20
2 files changed, 25 insertions, 14 deletions
diff --git a/lib/backup/manager.rb b/lib/backup/manager.rb
index f249becb8f9..16b8f21c9e9 100644
--- a/lib/backup/manager.rb
+++ b/lib/backup/manager.rb
@@ -11,7 +11,8 @@ module Backup
LIST_ENVS = {
skipped: 'SKIP',
- repositories_storages: 'REPOSITORIES_STORAGES'
+ repositories_storages: 'REPOSITORIES_STORAGES',
+ repositories_paths: 'REPOSITORIES_PATHS'
}.freeze
TaskDefinition = Struct.new(
@@ -190,7 +191,11 @@ module Backup
max_storage_concurrency = ENV['GITLAB_BACKUP_MAX_STORAGE_CONCURRENCY'].presence
strategy = Backup::GitalyBackup.new(progress, incremental: incremental?, max_parallelism: max_concurrency, storage_parallelism: max_storage_concurrency)
- Repositories.new(progress, strategy: strategy, storages: repositories_storages)
+ Repositories.new(progress,
+ strategy: strategy,
+ storages: list_env(:repositories_storages),
+ paths: list_env(:repositories_paths)
+ )
end
def build_files_task(app_files_dir, excludes: [])
@@ -266,7 +271,8 @@ module Backup
tar_version: tar_version,
installation_type: Gitlab::INSTALLATION_TYPE,
skipped: ENV['SKIP'],
- repositories_storages: ENV['REPOSITORIES_STORAGES']
+ repositories_storages: ENV['REPOSITORIES_STORAGES'],
+ repositories_paths: ENV['REPOSITORIES_PATHS']
}
end
@@ -279,7 +285,8 @@ module Backup
tar_version: tar_version,
installation_type: Gitlab::INSTALLATION_TYPE,
skipped: list_env(:skipped).join(','),
- repositories_storages: list_env(:repositories_storages).join(',')
+ repositories_storages: list_env(:repositories_storages).join(','),
+ repositories_paths: list_env(:repositories_paths).join(',')
)
end
@@ -472,10 +479,6 @@ module Backup
@skipped ||= list_env(:skipped)
end
- def repositories_storages
- @repositories_storages ||= list_env(:repositories_storages)
- end
-
def list_env(name)
list = ENV.fetch(LIST_ENVS[name], '').split(',')
list += backup_information[name].split(',') if backup_information[name]
diff --git a/lib/backup/repositories.rb b/lib/backup/repositories.rb
index 4a31e87b969..29b20bd2e73 100644
--- a/lib/backup/repositories.rb
+++ b/lib/backup/repositories.rb
@@ -3,19 +3,25 @@
require 'yaml'
module Backup
+ # Backup and restores repositories by querying the database
class Repositories < Task
extend ::Gitlab::Utils::Override
- def initialize(progress, strategy:, storages: [])
+ # @param [IO] progress IO interface to output progress
+ # @param [Object] :strategy Fetches backups from gitaly
+ # @param [Array<String>] :storages Filter by specified storage names. Empty means all storages.
+ # @param [Array<String>] :paths Filter by specified project paths. Empty means all projects, groups and snippets.
+ def initialize(progress, strategy:, storages: [], paths: [])
super(progress)
@strategy = strategy
@storages = storages
+ @paths = paths
end
override :dump
- def dump(path, backup_id)
- strategy.start(:create, path, backup_id: backup_id)
+ def dump(destination_path, backup_id)
+ strategy.start(:create, destination_path, backup_id: backup_id)
enqueue_consecutive
ensure
@@ -23,8 +29,8 @@ module Backup
end
override :restore
- def restore(path)
- strategy.start(:restore, path)
+ def restore(destination_path)
+ strategy.start(:restore, destination_path)
enqueue_consecutive
ensure
@@ -36,7 +42,7 @@ module Backup
private
- attr_reader :strategy, :storages
+ attr_reader :strategy, :storages, :paths
def enqueue_consecutive
enqueue_consecutive_projects
@@ -66,12 +72,14 @@ module Backup
def project_relation
scope = Project.includes(:route, :group, namespace: :owner)
scope = scope.id_in(ProjectRepository.for_repository_storage(storages).select(:project_id)) if storages.any?
+ scope = scope.where_full_path_in(paths) if paths.any?
scope
end
def snippet_relation
scope = Snippet.all
scope = scope.id_in(SnippetRepository.for_repository_storage(storages).select(:snippet_id)) if storages.any?
+ scope = scope.joins(:project).merge(Project.where_full_path_in(paths)) if paths.any?
scope
end