Skip to content

Instantly share code, notes, and snippets.

@russ
Created September 14, 2013 19:06
Show Gist options
  • Save russ/6564667 to your computer and use it in GitHub Desktop.
Save russ/6564667 to your computer and use it in GitHub Desktop.
namespace :sync do
desc "Backs up heroku database and restores it locally"
task production: :environment do
Bundler.with_clean_env do
system("heroku pgbackups:capture --expire --remote production")
timestamp = Time.now.utc.strftime("%Y%m%d%H%M%S")
system("curl -o ../pgbackups/production_#{timestamp}.dump --create-dirs `heroku pgbackups:url --remote production`")
last_backup = Dir.entries("../pgbackups").last
database = Rails.configuration.database_configuration[Rails.env]['database']
system("pg_restore --verbose --clean --no-acl --no-owner -d #{database} ../pgbackups/#{last_backup}")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment