11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/tina/cli.rb', line 11
def restore(prefix_file)
total_storage = options[:total_storage]
duration = options[:duration]
keep_days = options[:keep_days]
duration_in_seconds = parse_duration(duration)
prefixes = File.readlines(prefix_file).map(&:chomp)
objects = RestorePlan::ObjectCollection.new(s3_client.list_bucket_prefixes(prefixes))
restore_plan = RestorePlan.new(total_storage.to_i, objects)
price = restore_plan.price(duration_in_seconds)
chunks = objects.chunk(duration_in_seconds)
say
say "Restores will be performed in the following chunks:"
say "-" * 60
chunks.each_with_index do |chunk, index|
chunk_size = chunk.map(&:size).reduce(&:+)
say "#{index+1}) #{chunk.size} objects of total size %.2f GiB / %.2f TiB" % [chunk_size / 1024 ** 3, chunk_size.to_f / 1024 ** 4]
end
say "-" * 60
say "Actual restore time: %i days, %i hours" % [(4 * chunks.size) / 24, (4 * chunks.size) % 24]
say "Number of objects to restore: #{objects.size}"
say "Total restore size: %.2f MiB / %.2f GiB / %.2f TiB" % [objects.total_size.to_f / 1024 ** 2, objects.total_size.to_f / 1024 ** 3, objects.total_size.to_f / 1024 ** 4]
say "Estimated cost: $#{price}"
say "Days to keep objects on S3: #{keep_days} days"
say "-" * 60
say "* Please beware that these costs are not included in estimated cost:"
say "* - Cost for %i restore requests" % [objects.size]
say "* - Storage on S3 of %.2f GiB during %i days" % [objects.total_size.to_f / 1024 ** 3, keep_days]
say "-" * 60
return unless yes?("Do you feel rich? [y/n]", :yellow)
restore_chunks(chunks, keep_days)
end
|