Skip to content

Instantly share code, notes, and snippets.

@pvcarrera
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pvcarrera/e554db225ba7b0386384 to your computer and use it in GitHub Desktop.
Save pvcarrera/e554db225ba7b0386384 to your computer and use it in GitHub Desktop.
Heroku Rake tasks
namespace :heroku do
DEFAULT_APP = 'my_app'
desc 'Create database backup'
task :backup, :app do |task, args|
args.with_defaults(app: DEFAULT_APP)
Bundler.with_clean_env do
`heroku pg:backups capture --app #{args[:app]}`
end
puts $?.exitstatus == 0 ? 'Backup created.' : 'Backup failed.'
end
desc 'Download latest database backup'
task :download_backup, :app do |task, args|
args.with_defaults(app: DEFAULT_APP)
Bundler.with_clean_env do
url = `heroku pg:backups public-url --app #{args[:app]}`
`curl -o latest.dump "#{url}"`
end
puts $?.exitstatus == 0 ? 'Database downloaded.' : 'Download failed.'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment