Class: Martilla::S3
- Defined in:
- lib/martilla/storages/s3.rb
Instance Attribute Summary
Attributes inherited from Storage
Instance Method Summary collapse
Methods inherited from Storage
#append_datetime_suffix, #config_error, create, #enforce_retention!, #initialize, #invalid_options_msg, #options_filename, #output_filename, #retention_limit, #suffix?, #timestamp_regex
Methods inherited from Component
Constructor Details
This class inherits a constructor from Martilla::Storage
Instance Method Details
#enfore_retention!(gzip:) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/martilla/storages/s3.rb', line 16 def enfore_retention!(gzip:) return if retention_limit < 1 objs = bucket_objs_for_retention(output_file: output_filename(gzip)) while objs.count > retention_limit do delete_params = { bucket: bucket_name, key: objs.first.key } s3_resource.client.delete_object(delete_params) puts "Retention limit met. Removed the backup file: #{objs.shift.key}" end end |
#persist(tmp_file:, gzip:) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/martilla/storages/s3.rb', line 5 def persist(tmp_file:, gzip:) path = output_filename(gzip) # Files in the root path of a bucket need to be stripped of './' # See https://github.com/fdoxyz/martilla/issues/17 path.slice!(0, 2) if path[0...2] == './' obj = s3_resource.bucket(bucket_name).object(path) return nil if obj.upload_file(tmp_file) raise Error.new('Error uploading backup to bucket') end |