Sha256: 3d3748ae1566e43dd92df0754c67cb9dfc7960f0fb5876dee8a4d95725317975

Contents?: true

Size: 825 Bytes

Versions: 3

Compression:

Stored size: 825 Bytes

Contents

require "heroku/client"

class Heroku::Client::PgbackupsArchive

  attr_reader :client, :backup

  def initialize(attrs={})
    Heroku::Command.load
    @client = Heroku::Client::Pgbackups.new attrs[:pgbackups_url]
    @backup = nil
    @environment = attrs[:env] || (defined?(Rails) ? Rails.env : nil)
  end

  def capture
    @backup = @client.create_transfer ENV["DATABASE_URL"], ENV["DATABASE_URL"], nil, "BACKUP", :expire => true

    until @backup["finished_at"]
      print "."
      sleep 1
      @backup = @client.get_transfer @backup["id"]
    end

    @backup
  end

  def file
    open @backup["public_url"]
  end

  def key
    ["pgbackups", @environment, @backup["finished_at"].gsub(/\/|\:|\.|\s/, "-").concat(".dump")].join("/")
  end

  def store
    PgbackupsArchive::Storage.new(key, file).store
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pgbackups-archive-0.0.4 lib/pgbackups-archive/heroku/client/pgbackups_archive.rb
pgbackups-archive-0.0.3 lib/pgbackups-archive/heroku/client/pgbackups_archive.rb
pgbackups-archive-0.0.1 lib/pgbackups-archive/heroku/client/pgbackups_archive.rb