Created
May 17, 2011 19:33
-
-
Save carlhoerberg/977203 to your computer and use it in GitHub Desktop.
How to do automatic backup with Heroku PGBackups and Heroku Cron. http://carlhoerberg.com/automatic-backup-of-heroku-database-to-s3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'aws/s3' | |
require 'heroku' | |
require 'heroku/command' | |
require 'heroku/command/auth' | |
require 'heroku/command/pgbackups' | |
task :cron do | |
class Heroku::Auth | |
def self.client | |
Heroku::Client.new ENV['heroku_login'], ENV['heroku_passwd'] | |
end | |
end | |
Heroku::Command.run 'pgbackups:capture', ['--expire', '--app', ENV['heroku_appname']] | |
url = capture_stdout do | |
Heroku::Command.run 'pgbackups:url', ['--app', 'dmks'] | |
end | |
AWS::S3::Base.establish_connection!(:access_key_id => ENV['s3_access_key'], :secret_access_key => ENV['s3_secret_key']) | |
AWS::S3::S3Object.store "pgdb-#{Time.now.strftime('%y%m%d_%H%M')}.dump", open(url), ENV['s3_backup_bucket'] | |
end | |
module Kernel | |
def capture_stdout | |
out = StringIO.new | |
$stdout = out | |
yield | |
return out.string | |
ensure | |
$stdout = STDOUT | |
end | |
end |
Author
carlhoerberg
commented
Jun 1, 2011
via email
installed the heroku gem?
```
gem install heroku
```
…On Wed, Jun 1, 2011 at 16:49, mcansky < ***@***.***>wrote:
having trouble with this :
require 'heroku/command/auth'
require 'heroku/command/pgbackups'
don't work for me
##
Reply to this email directly or view it on GitHub:
https://gist.github.com/977203
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment