Merge branch 'print-list-of-available-backups' into 'master'

List backups avilable for restore

See merge request gitlab-org/gitlab-ce!16465
This commit is contained in:
Douwe Maan 2018-01-16 16:40:20 +00:00
commit f084525fe4
2 changed files with 14 additions and 1 deletions

View file

@ -108,7 +108,10 @@ module Backup
$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? && ENV["BACKUP"].nil?
$progress.puts 'Found more than one backup, please specify which one you want to restore:' $progress.puts 'Found more than one backup:'
# print list of available backups
$progress.puts " " + available_timestamps.join("\n ")
$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 end
@ -169,6 +172,10 @@ module Backup
@backup_file_list ||= Dir.glob("*#{FILE_NAME_SUFFIX}") @backup_file_list ||= Dir.glob("*#{FILE_NAME_SUFFIX}")
end end
def available_timestamps
@backup_file_list.map {|item| item.gsub("#{FILE_NAME_SUFFIX}", "")}
end
def connect_to_remote_directory(connection_settings) def connect_to_remote_directory(connection_settings)
# our settings use string keys, but Fog expects symbols # our settings use string keys, but Fog expects symbols
connection = ::Fog::Storage.new(connection_settings.symbolize_keys) connection = ::Fog::Storage.new(connection_settings.symbolize_keys)

View file

@ -194,6 +194,12 @@ describe Backup::Manager do
) )
end end
it 'prints the list of available backups' do
expect { subject.unpack }.to raise_error SystemExit
expect(progress).to have_received(:puts)
.with(a_string_matching('1451606400_2016_01_01_1.2.3\n 1451520000_2015_12_31'))
end
it 'fails the operation and prints an error' do it 'fails the operation and prints an error' do
expect { subject.unpack }.to raise_error SystemExit expect { subject.unpack }.to raise_error SystemExit
expect(progress).to have_received(:puts) expect(progress).to have_received(:puts)