Sha256: d4a29951d11687bff64af117b7d4d1b6e279c8bf69565ad869aaf96c5d0a2d88
Contents?: true
Size: 1.1 KB
Versions: 2
Compression:
Stored size: 1.1 KB
Contents
class Backup def self.generate_id SecureRandom.hex(32) end include Comparable attr_reader :s3_object, :ts, :keep def <=>(other) ts <=> other.ts end def initialize(s3_object) @s3_object = s3_object @ts = Time.parse(s3_object.key.split('/').last) @keep = false end def to_s "id: #{short_id}, key: #{basename}" end def on_day?(date) ts.strftime('%F') == date.strftime('%F') end def on_week?(date) ts.strftime('%Y-%U') == date.strftime('%Y-%U') end def on_month?(date) ts.strftime('%Y-%m') == date.strftime('%Y-%m') end def keep_on_day(date) @keep = true if on_day?(date) end def keep_on_week(date) @keep = true if on_week?(date) end def keep_on_month(date) @keep = true if on_month?(date) end def prune if keep puts "Keeping backup: #{self}" else delete end end def delete puts "Deleting backup: #{self}" s3_object.delete end def id @id ||= s3_object.metadata['backup_id'] end def short_id id[0..8] end def basename File.basename(s3_object.key) end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
pg_s3_dumper-0.1.6 | lib/pg_s3_dumper/backup.rb |
pg_s3_dumper-0.1.5 | lib/pg_s3_dumper/backup.rb |