Class: PgbackupsArchive::Storage

Inherits:
Object
  • Object
show all
Defined in:
lib/pgbackups-archive/storage.rb

Instance Method Summary collapse

Constructor Details

#initialize(key, file) ⇒ Storage

Returns a new instance of Storage.



6
7
8
9
# File 'lib/pgbackups-archive/storage.rb', line 6

def initialize(key, file)
  @key = key
  @file = file
end

Instance Method Details

#bucketObject



21
22
23
# File 'lib/pgbackups-archive/storage.rb', line 21

def bucket
  connection.directories.get ENV["PGBACKUPS_BUCKET"]
end

#connectionObject



11
12
13
14
15
16
17
18
19
# File 'lib/pgbackups-archive/storage.rb', line 11

def connection
  Fog::Storage.new({
    :provider              => "AWS",
    :aws_access_key_id     => ENV["PGBACKUPS_AWS_ACCESS_KEY_ID"],
    :aws_secret_access_key => ENV["PGBACKUPS_AWS_SECRET_ACCESS_KEY"],
    :region                => ENV["PGBACKUPS_REGION"],
    :persistent            => false
  })
end

#storeObject



25
26
27
28
29
30
31
32
33
# File 'lib/pgbackups-archive/storage.rb', line 25

def store
  options = {:key => @key, :body => @file, :public => false, :encryption => "AES256"}

  if ENV["PGBACKUPS_MULTIPART_CHUNK_SIZE"]
    options.merge!(:multipart_chunk_size => ENV["PGBACKUPS_MULTIPART_CHUNK_SIZE"].to_i)
  end

  bucket.files.create(options)
end