class ServerBackups::OrderedBackupFileCollection

Constants

INCREMENTAL
TIMESTAMP_REGEXP

Attributes

s3_collection[R]

Public Class Methods

new(s3_collection) click to toggle source
# File lib/server_backups/ordered_backup_file_collection.rb, line 6
def initialize(s3_collection)
    @s3_collection = s3_collection
end

Public Instance Methods

full_backup_for(restore_point) click to toggle source
# File lib/server_backups/ordered_backup_file_collection.rb, line 10
def full_backup_for(restore_point)
    sorted(full_backups).reverse.find do |file|
        get_timestamp_from_s3_object(file) <= restore_point
    end
end
full_backups() click to toggle source
# File lib/server_backups/ordered_backup_file_collection.rb, line 21
def full_backups
    s3_collection.reject { |file| INCREMENTAL =~ file.key }
end
incremental_backups() click to toggle source
# File lib/server_backups/ordered_backup_file_collection.rb, line 25
def incremental_backups
    @incremental_backups ||=
        sorted(s3_collection.select { |file| INCREMENTAL =~ file.key }).to_a
end
incremental_backups_for(restore_point) click to toggle source
# File lib/server_backups/ordered_backup_file_collection.rb, line 16
def incremental_backups_for(restore_point)
    sorted eligible_incremental_backups(restore_point)
end

Private Instance Methods

eligible_incremental_backups(restore_point) click to toggle source
# File lib/server_backups/ordered_backup_file_collection.rb, line 46
def eligible_incremental_backups(restore_point)
    full_backup_timestamp = get_timestamp_from_s3_object full_backup_for(restore_point)
    incremental_backups.select do |file|
        get_timestamp_from_s3_object(file) > full_backup_timestamp &&
            get_timestamp_from_s3_object(file) <= restore_point
    end
end
get_timestamp_from_s3_object(file) click to toggle source
# File lib/server_backups/ordered_backup_file_collection.rb, line 33
def get_timestamp_from_s3_object(file)
    time_parts = TIMESTAMP_REGEXP.match(file.key).captures
    time_parts[-1].insert(3, ':')
    # Add in hours and seconds arguments
    # https://ruby-doc.org/core-2.2.0/Time.html#method-c-new
    time_parts.insert(4, 0, 0)
    Time.new(*time_parts)
end
sorted(coll) click to toggle source
# File lib/server_backups/ordered_backup_file_collection.rb, line 42
def sorted(coll)
    coll.sort_by { |file| get_timestamp_from_s3_object file }
end