Skip to content

Instantly share code, notes, and snippets.

@alnutile
Last active December 25, 2015 05:49
Show Gist options
  • Save alnutile/6927783 to your computer and use it in GitHub Desktop.
Save alnutile/6927783 to your computer and use it in GitHub Desktop.
Quick Script to automate the update of heroku db from dev to basic
site = ARGV[0]
if site
command = %x[heroku addons:add --app #{site} pgbackups]
puts "Added PgBackups"
command = %x[heroku addons:add --app #{site} heroku-postgresql:basic]
pg_info = %x[heroku pg:info --app #{site}]
pg_info_to_array = pg_info.split("\n")
db_row = pg_info[0].split(" ")
database_name = db_row[1]
command = %x[heroku maintenance:on --app #{site}]
puts "Maintenance mode on"
command = %x[heroku pgbackups:capture --app #{site} --expire]
puts "Backup Live DB"
command = %x[heroku pgbackups:restore --app #{site} #{database_name} --confirm #{site}]
puts "Restore to NEW db"
command = %x[heroku pg:promote --app #{site} #{database_name}]
puts "Promote DB"
command = %x[heroku maintenance:off --app #{site}]
puts "Site out of Maintenance mode http://#{site}.herokuapp.com"
else
puts "Oops you forgot to pass a site"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment