Se si tratta di un'app Rails, è possibile utilizzare il seguente script per sovrascrivere il database locale con l'ultimo dump generato su Heroku. Se si decommenta la riga con heroku pg:backups capture
, lo script genererà una nuova istantanea su Heroku prima di scaricarla sul proprio computer.
Nota che non è necessario modificare lo script poiché legge tutta la configurazione dal file database.yml.
#!/usr/bin/env ruby
require_relative '../config/environment'
# Uncomment the line below if you want to generate a new snapshot of the
# Heroku production database before downloading it to the local machine
# `heroku pg:backups capture`
database_dump_file_pathname = Tempfile.new('latest.dump').path
`heroku pg:backups:download --output #{database_dump_file_pathname}`
# Get database config fom database.yml file
database_config = YAML::load_file(Rails.root.join('config', 'database.yml'))
database_name = database_config['development']['database']
database_username = database_config['development']['username']
database_password = database_config['development']['password']
# Overwrite local database with dump
cmd_line_arguments = [
'--verbose',
'--clean',
'--no-acl',
'--no-owner',
'--host localhost',
"-U #{database_username}",
"-d #{database_name}",
database_dump_file_pathname
].join(' ')
`PGPASSWORD=#{database_password} pg_restore #{cmd_line_arguments}`
Vedere il Heroku docs on downloading DB backups per dettagli.
Forse [ 'pg_dump'] (http://www.postgresql.org/docs/current/static/app-pgdump.html) e ['pg_restore'] (http://www.postgresql.org/docs/current/static/app-pgrestore.html)? –