Attempt to lower complexity of unpack function

parent c1ed08b7
...@@ -114,35 +114,38 @@ module Backup ...@@ -114,35 +114,38 @@ module Backup
def unpack def unpack
cleanup_required = true cleanup_required = true
Dir.chdir(backup_path) do Dir.chdir(backup_path) do
if ENV['BACKUP'].present?
# User has indicated which backup he/she wants restored
tar_file = File.basename(ENV['BACKUP']) + FILE_NAME_SUFFIX
unless File.exist?(tar_file)
progress.puts "The backup file #{tar_file} does not exist!"
exit 1
end
else
# check for existing backups in the backup dir # check for existing backups in the backup dir
if File.exist?(File.join(backup_path, 'backup_information.yml')) && !ENV['BACKUP'].present? if File.exist?(File.join(backup_path, 'backup_information.yml'))
tar_file = 'SKIP'
progress.puts "Non tarred backup found in #{backup_path}, using that" progress.puts "Non tarred backup found in #{backup_path}, using that"
cleanup_required = false cleanup_required = false
else elsif backup_file_list.empty?
if backup_file_list.empty?
progress.puts "No backups found in #{backup_path}" progress.puts "No backups found in #{backup_path}"
progress.puts "Please make sure that file name ends with #{FILE_NAME_SUFFIX}" progress.puts "Please make sure that file name ends with #{FILE_NAME_SUFFIX}"
exit 1 exit 1
elsif backup_file_list.many? && ENV["BACKUP"].nil? elsif backup_file_list.many?
progress.puts 'Found more than one backup:' progress.puts 'Found more than one backup:'
# print list of available backups # print list of available backups
progress.puts " " + available_timestamps.join("\n ") progress.puts " " + available_timestamps.join("\n ")
progress.puts 'Please specify which one you want to restore:' progress.puts 'Please specify which one you want to restore:'
progress.puts 'rake gitlab:backup:restore BACKUP=timestamp_of_backup' progress.puts 'rake gitlab:backup:restore BACKUP=timestamp_of_backup'
exit 1 exit 1
end
tar_file = if ENV['BACKUP'].present?
File.basename(ENV['BACKUP']) + FILE_NAME_SUFFIX
else else
backup_file_list.first tar_file = backup_file_list.first
end end
unless File.exist?(tar_file)
progress.puts "The backup file #{tar_file} does not exist!"
exit 1
end end
unless tar_file == 'SKIP'
progress.print 'Unpacking backup ... ' progress.print 'Unpacking backup ... '
if Kernel.system(*%W(tar -xf #{tar_file})) if Kernel.system(*%W(tar -xf #{tar_file}))
......
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