2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/heroku_s3_backup.rb', line 2
def self.backup
begin
require 'right_aws'
puts "[#{Time.now}] heroku:backup started"
name = "#{ENV['APP_NAME']}-#{Time.now.strftime('%Y-%m-%d-%H%M%S')}.dump"
db = ENV['DATABASE_URL'].match(/postgres:\/\/([^:]+):([^@]+)@([^\/]+)\/(.+)/)
system "PGPASSWORD=#{db[2]} pg_dump -Fc -i --username=#{db[1]} --host=#{db[3]} #{db[4]} > tmp/#{name}"
s3 = RightAws::S3.new(ENV['s3_access_key_id'], ENV['s3_secret_access_key'])
bucket = s3.bucket("#{ENV['APP_NAME']}-heroku-backups", true, 'private')
bucket.put(name, open("tmp/#{name}"))
system "rm tmp/#{name}"
puts "[#{Time.now}] heroku:backup complete"
end
end
|