Class: Martilla::S3

Inherits:
Storage show all
Defined in:
lib/martilla/storages/s3.rb

Instance Attribute Summary

Attributes inherited from Storage

#options

Instance Method Summary collapse

Methods inherited from Storage

#append_datetime_suffix, #config_error, create, #enforce_retention!, #initialize, #invalid_options_msg, #output_filename, #retention_limit, #suffix?, #timestamp_regex

Methods inherited from Component

#bash

Constructor Details

This class inherits a constructor from Martilla::Storage

Instance Method Details

#enfore_retention!(gzip:) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/martilla/storages/s3.rb', line 14

def enfore_retention!(gzip:)
  return if retention_limit < 1

  objs = s3_resource.bucket(bucket_name).objects.sort_by(&:last_modified)
  while objs.count > retention_limit do
    objs.first.delete
    puts "Retention limit met. Removed the backup file: #{objs.shift.key}"
  end
end

#persist(tmp_file:, gzip:) ⇒ Object

Raises:



5
6
7
8
9
10
11
12
# File 'lib/martilla/storages/s3.rb', line 5

def persist(tmp_file:, gzip:)
  path = output_filename(gzip)
  obj = s3_resource.bucket(bucket_name).object(path)

  # Upload it
  return nil if obj.upload_file(tmp_file)
  raise Error.new('Error uploading backup to bucket')
end