Permalink
Browse files

Update to use AWS::S3 plugin,

  • Loading branch information...
1 parent bb26094 commit dfcc19516971e16588a113597c31b91975ca5f0b @speedmax speedmax committed Jun 8, 2010
Showing with 14 additions and 11 deletions.
  1. +14 −11 lib/heroku_s3_backup.rb
View
@@ -1,23 +1,26 @@
class HerokuS3Backup
def self.backup
begin
- require 'right_aws'
-
- bucket = if ENV['backup_bucket']
+ include AWS::S3
+ puts "[#{Time.now}] heroku:backup started"
+ name = "#{ENV['APP_NAME']}-#{Time.now.strftime('%Y-%m-%d-%H%M%S')}.dump"
+ s3 = AWS::S3::Base.establish_connection!(
+ :access_key_id => ENV['s3_access_key_id'],
+ :secret_access_key => ENV['s3_secret_access_key']
+ )
+ bucket_name = if ENV['backup_bucket']
ENV['backup_bucket']
else
"#{ENV['APP_NAME']}-heroku-backups"
end
-
- 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}"
+ bucket = Bucket.find(bucket_name) || Bucket.create(bucket_name)
- s3 = RightAws::S3.new(ENV['s3_access_key_id'], ENV['s3_secret_access_key'])
- bucket = s3.bucket(bucket, true, 'private')
+ throw "Amazon bucket error" unless bucket
- bucket.put("backups/" + name, open("tmp/#{name}"))
+ db = ENV['DATABASE_URL'].match(/postgres:\/\/([^:]+):([^@]+)@([^\/]+)\/(.+)/)
+ system "PGPASSWORD=#{db[2]} pg_dump -Fc -i --username=#{db[1]} --host=#{db[3]} #{db[4]} > tmp/#{name}"
+
+ S3Object.store("backups/" + name, open("tmp/#{name}"), bucket_name)
system "rm tmp/#{name}"
puts "[#{Time.now}] heroku:backup complete"
# rescue Exception => e

0 comments on commit dfcc195

Please sign in to comment.