Skip to content

Instantly share code, notes, and snippets.

@derencius
Created March 4, 2014 01:32
Show Gist options
  • Save derencius/9338535 to your computer and use it in GitHub Desktop.
Save derencius/9338535 to your computer and use it in GitHub Desktop.
heroku db download
#!/usr/bin/env ruby
require "thor"
class MyCLI < Thor
desc "download", "production database"
def download(remote)
puts "Downloading... #{remote}"
system "heroku pgbackups:capture --expire --remote #{remote}"
system "curl `heroku pgbackups:url --remote #{remote}` -o #{remote}.dump"
puts "Done!"
end
desc "restore", "load dump in dev database"
def restore(remote, db)
system "ps ax | grep postgres: | grep #{db} | cut -c1-8 | xargs kill"
system "dropdb #{db}; createdb #{db}"
system "pg_restore --verbose --clean --no-acl --no-owner -d #{db} #{remote}.dump"
system "touch tmp/restart.txt"
end
end
MyCLI.start(ARGV)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment