Nếu đây là ứng dụng Rails, bạn có thể sử dụng tập lệnh sau để ghi đè lên cơ sở dữ liệu cục bộ của mình với bản mới nhất bạn đã tạo trên Heroku. Nếu bạn bỏ ghi chú dòng với heroku pg:backups capture
, tập lệnh sẽ tạo ảnh chụp nhanh mới trên Heroku trước khi tải xuống máy của bạn.
Lưu ý rằng bạn không cần phải chỉnh sửa tập lệnh vì nó đọc tất cả cấu hình từ tệp database.yml của bạn.
#!/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}`
Xem chi tiết Heroku docs on downloading DB backups.
lẽ [ 'pg_dump'] (http://www.postgresql.org/docs/current/static/app-pgdump.html) và ['pg_restore'] (http://www.postgresql.org/docs/current/static/app-pgrestore.html)? –