Sha256: 999bdd795a21fd6a76f2749df43a5759b06345b00ad37b76ae8d4c6e2150bb00

Contents?: true

Size: 1.05 KB

Versions: 3

Compression:

Stored size: 1.05 KB

Contents

require 'fog/aws'

module EY
  module Backup
    class Backend
      include EY::Backup::Logging
      extend  EY::Backup::Logging

      def initialize(secret_id, secret_key, region, bucket_name)
        @bucket_minder = EY::BucketMinder.new(secret_id, secret_key, bucket_name, region)
      end
      attr_reader :bucket_minder

      def start_upload(filenames, environment_name, database_name)
        filenames.each do |filename|
          begin
            object_name = File.join("#{environment_name}.#{database_name}", "#{File.basename(filename)}")
            info "Starting upload: #{filename}"
            @bucket_minder.put(object_name, File.open(filename, 'r'))
            info "Successful upload: #{filename}"
          rescue => e
            retries ||= 5
            retries -= 1
            # remove partial or failed uploads
            @bucket_minder.remove_object(object_name)
            raise e if retries == 0
            warn "retrying upload of #{filename}. Got: #{e.inspect}"
            retry
          end
        end
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ey_cloud_server-1.5.0 lib/ey_backup/backend.rb
ey_cloud_server-1.4.61 lib/ey_backup/backend.rb
ey_cloud_server-1.4.60 lib/ey_backup/backend.rb