class HerokuPgBackupsArchive::BackupArchive

Attributes

backup[R]

Public Class Methods

new(backup) click to toggle source
# File lib/heroku_pg_backups_archive/backup_archive.rb, line 12
def initialize(backup)
  @backup = backup
end
perform(backup) click to toggle source
# File lib/heroku_pg_backups_archive/backup_archive.rb, line 7
def self.perform(backup)
  backup_archive = new(backup)
  backup_archive.perform
end

Public Instance Methods

perform() click to toggle source
# File lib/heroku_pg_backups_archive/backup_archive.rb, line 16
def perform
  s3.put_object(write_parameters)
end

Private Instance Methods

archive_path() click to toggle source
# File lib/heroku_pg_backups_archive/backup_archive.rb, line 32
def archive_path
  "#{backup.finished_at.strftime("%Y/%m/%d")}/#{backup.finished_at.iso8601}"
end
backup_data() click to toggle source
# File lib/heroku_pg_backups_archive/backup_archive.rb, line 36
def backup_data
  open(backup.url)
end
s3() click to toggle source
# File lib/heroku_pg_backups_archive/backup_archive.rb, line 24
def s3
  @s3 ||= Aws::S3::Client.new(
    access_key_id: HerokuPgBackupsArchive.config.aws_access_key_id,
    secret_access_key: HerokuPgBackupsArchive.config.aws_secret_access_key,
    region: HerokuPgBackupsArchive.config.aws_region
  )
end
sse_customer_options() click to toggle source
# File lib/heroku_pg_backups_archive/backup_archive.rb, line 48
def sse_customer_options
  unless HerokuPgBackupsArchive.config.sse_customer_key.nil?
    {
      sse_customer_algorithm: :AES256,
      sse_customer_key: HerokuPgBackupsArchive.config.sse_customer_key
    }
  else
    {}
  end
end
write_parameters() click to toggle source
# File lib/heroku_pg_backups_archive/backup_archive.rb, line 40
def write_parameters
  {
    body: backup_data,
    bucket: HerokuPgBackupsArchive.config.bucket_name,
    key: archive_path
  }.merge(sse_customer_options)
end