Module: HerokuBackupTask

Defined in:
lib/heroku_backup_task.rb,
lib/heroku_backup_task/version.rb

Constant Summary collapse

VERSION =
"0.0.5.1"

Class Method Summary collapse

Class Method Details

.backup_name(to_url) ⇒ Object



26
27
28
29
30
# File 'lib/heroku_backup_task.rb', line 26

def backup_name(to_url)
  # translate s3://bucket/email/foo/bar.dump => foo/bar
  parts = to_url.split('/')
  parts.slice(4..-1).join('/').gsub(/\.dump$/, '')
end

.backups_urlObject



10
11
12
# File 'lib/heroku_backup_task.rb', line 10

def backups_url
  ENV["PGBACKUPS_URL"]
end

.clientObject



14
15
16
# File 'lib/heroku_backup_task.rb', line 14

def client
  @client ||= PGBackups::Client.new(ENV["PGBACKUPS_URL"])
end

.databasesObject



18
19
20
21
22
23
24
# File 'lib/heroku_backup_task.rb', line 18

def databases
  if db = ENV["HEROKU_BACKUP_DATABASES"]
    db.split(",").map(&:strip)
  else
    ["DATABASE_URL"]
  end
end

.executeObject



32
33
34
35
36
37
38
39
40
# File 'lib/heroku_backup_task.rb', line 32

def execute
  log "starting heroku backup task"

  databases.each do |db|
    db_url = ENV[db]
    log "backing up: #{db}"
    client.create_transfer(db_url, db, nil, "BACKUP", :expire => true)
  end
end

.log(message) ⇒ Object



6
7
8
# File 'lib/heroku_backup_task.rb', line 6

def log(message)
  puts "[#{Time.now}] #{message}"
end