Created
July 18, 2010 17:11
-
-
Save nruth/480545 to your computer and use it in GitHub Desktop.
Heroku bundle downloader -- just add cron
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 'rake' | |
APP_NAME = 'heroku_app_name' | |
BACKUP_PATH = '.' | |
namespace "heroku" do | |
desc "create a new Heroku bundle and download it, name with timestamp - only use with single bundle addon" | |
task "backup" do | |
require 'fileutils' | |
app_option = "--app #{APP_NAME}" | |
bundle_name = Time.now.strftime("#{APP_NAME}-heroku-bundle--%Y-%m-%d--%H%M").downcase | |
unless %x{ heroku bundles #{app_option} | grep complete }.empty? | |
puts "Removing existing bundle before proceding" | |
sh "heroku bundles:destroy #{app_option} $(heroku bundles #{app_option})" | |
end | |
sh "heroku bundles:capture #{app_option} '#{bundle_name}'" | |
waited = 0 | |
while %x{ heroku bundles #{app_option} | grep complete }.empty? && waited < (maxwait=200) | |
seconds_to_wait_before_retry = 10 | |
waited += seconds_to_wait_before_retry | |
puts "Heroku hasn't finished bundling the app & database." | |
puts "Waiting #{seconds_to_wait_before_retry} seconds to try again. (#{waited} of max #{maxwait})" | |
sleep seconds_to_wait_before_retry | |
end | |
# download & destroy the bundle we just captured | |
%w(download destroy).each do | action | | |
sh "heroku bundles:#{action} #{app_option} '#{bundle_name}'" | |
end | |
FileUtils.mv "#{APP_NAME}.tar.gz", "#{BACKUP_PATH}/#{bundle_name}.tar.gz" | |
puts "Bundle captured and stored in #{BACKUP_PATH}/#{bundle_name}.tar.gz" | |
end | |
end | |
# references: | |
# Ben Scheirman http://flux88.com/blog/scripting-heroku-backups/ | |
# Matt Buck http://github.com/techpeace/heroku_backup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment