Commit c085f88f authored by James Lopez's avatar James Lopez

fix backup task to ignore errors per project

parent 1b76c719
...@@ -14,7 +14,7 @@ module Backup ...@@ -14,7 +14,7 @@ module Backup
# Create namespace dir if missing # Create namespace dir if missing
FileUtils.mkdir_p(File.join(backup_repos_path, project.namespace.full_path)) if project.namespace FileUtils.mkdir_p(File.join(backup_repos_path, project.namespace.full_path)) if project.namespace
if project.empty_repo? if empty_repo?(project)
$progress.puts "[SKIPPED]".color(:cyan) $progress.puts "[SKIPPED]".color(:cyan)
else else
in_path(path_to_project_repo) do |dir| in_path(path_to_project_repo) do |dir|
...@@ -23,10 +23,7 @@ module Backup ...@@ -23,10 +23,7 @@ module Backup
output, status = Gitlab::Popen.popen(cmd) output, status = Gitlab::Popen.popen(cmd)
unless status.zero? unless status.zero?
puts "[FAILED]".color(:red) progress_warn(project, cmd.join(' '), output)
puts "failed: #{cmd.join(' ')}"
puts output
abort 'Backup failed'
end end
end end
...@@ -36,10 +33,7 @@ module Backup ...@@ -36,10 +33,7 @@ module Backup
if status.zero? if status.zero?
$progress.puts "[DONE]".color(:green) $progress.puts "[DONE]".color(:green)
else else
puts "[FAILED]".color(:red) progress_warn(project, cmd.join(' '), output)
puts "failed: #{cmd.join(' ')}"
puts output
abort 'Backup failed'
end end
end end
...@@ -49,7 +43,7 @@ module Backup ...@@ -49,7 +43,7 @@ module Backup
if File.exist?(path_to_wiki_repo) if File.exist?(path_to_wiki_repo)
$progress.print " * #{wiki.path_with_namespace} ... " $progress.print " * #{wiki.path_with_namespace} ... "
if wiki.repository.empty? if empty_wiki_repo?(wiki)
$progress.puts " [SKIPPED]".color(:cyan) $progress.puts " [SKIPPED]".color(:cyan)
else else
cmd = %W(#{Gitlab.config.git.bin_path} --git-dir=#{path_to_wiki_repo} bundle create #{path_to_wiki_bundle} --all) cmd = %W(#{Gitlab.config.git.bin_path} --git-dir=#{path_to_wiki_repo} bundle create #{path_to_wiki_bundle} --all)
...@@ -57,10 +51,7 @@ module Backup ...@@ -57,10 +51,7 @@ module Backup
if status.zero? if status.zero?
$progress.puts " [DONE]".color(:green) $progress.puts " [DONE]".color(:green)
else else
puts " [FAILED]".color(:red) progress_warn(wiki, cmd.join(' '), output)
puts "failed: #{cmd.join(' ')}"
puts output
abort 'Backup failed'
end end
end end
end end
...@@ -96,10 +87,7 @@ module Backup ...@@ -96,10 +87,7 @@ module Backup
if status.zero? if status.zero?
$progress.puts "[DONE]".color(:green) $progress.puts "[DONE]".color(:green)
else else
puts "[FAILED]".color(:red) progress_warn(project, cmd.join(' '), output)
puts "failed: #{cmd.join(' ')}"
puts output
abort 'Restore failed'
end end
in_path(path_to_tars(project)) do |dir| in_path(path_to_tars(project)) do |dir|
...@@ -107,10 +95,7 @@ module Backup ...@@ -107,10 +95,7 @@ module Backup
output, status = Gitlab::Popen.popen(cmd) output, status = Gitlab::Popen.popen(cmd)
unless status.zero? unless status.zero?
puts "[FAILED]".color(:red) progress_warn(project, cmd.join(' '), output)
puts "failed: #{cmd.join(' ')}"
puts output
abort 'Restore failed'
end end
end end
...@@ -131,10 +116,7 @@ module Backup ...@@ -131,10 +116,7 @@ module Backup
if status.zero? if status.zero?
$progress.puts " [DONE]".color(:green) $progress.puts " [DONE]".color(:green)
else else
puts " [FAILED]".color(:red) progress_warn(project, cmd.join(' '), output)
puts "failed: #{cmd.join(' ')}"
puts output
abort 'Restore failed'
end end
end end
end end
...@@ -201,6 +183,27 @@ module Backup ...@@ -201,6 +183,27 @@ module Backup
private private
def progress_warn(project, cmd, output)
$progress.puts "[WARNING] Executing #{cmd}".color(:orange)
$progress.puts "Ignoring error on #{project.path_with_namespace} - #{output}".color(:orange)
end
def empty_repo?(project)
project.empty_repo?
rescue => e
$progress.puts "Ignoring error on #{project.full_path} repository - #{e.message}".color(:orange)
false
end
def empty_wiki_repo?(wiki)
wiki.repository.empty?
rescue => e
$progress.puts "Ignoring error on #{wiki.path_with_namespace} repository - #{e.message}".color(:orange)
false
end
def repository_storage_paths_args def repository_storage_paths_args
Gitlab.config.repositories.storages.values.map { |rs| rs['path'] } Gitlab.config.repositories.storages.values.map { |rs| rs['path'] }
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