Skip to content

Instantly share code, notes, and snippets.

@champierre
Created July 28, 2010 17:16
Show Gist options
  • Save champierre/495370 to your computer and use it in GitHub Desktop.
Save champierre/495370 to your computer and use it in GitHub Desktop.
namespace :myapp do
desc 'Captures a heroku bundle and downloads it. The downloaded files are stored in backups/'
task :backup do
app_name = RAILS_ROOT.split('/').last
timestamp = `date -u '+%Y-%m-%d-%H-%M'`.chomp
bundle_name = "#{app_name}-#{timestamp}"
puts "Capturing bundle #{bundle_name}..."
`heroku bundles:capture --app #{app_name} '#{bundle_name}'`
# poll for completion (warning, a little hacky)
begin
bundles = `heroku bundles --app #{app_name}`
end while bundles.match(/complete/).nil?
# download & destroy the bundle we just captured
%w(download destroy).each do | action |
`heroku bundles:#{action} --app #{app_name} '#{bundle_name}'`
end
`mv #{app_name}.tar.gz backups/#{bundle_name}.tar.gz`
puts "Bundle captured and stored in backups/#{bundle_name}.tar.gz"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment