[英]How to easily DB dump to heroku's DB
I have a local db full of data that i want to push to the Heroku's DB in order to populae it. 我有一个充满数据的本地数据库,我想将其推送到Heroku的数据库以填充它。
What is the best way/tools o realize this ? 实现此目的的最佳方法/工具是什么?
Thank you! 谢谢!
您可以编写一个脚本,将当前数据库移植到种子文件中,然后使用heroku run rake db:seed
种子文件。
First dump your local database to a dump file: 首先将本地数据库转储到转储文件中:
PGPASSWORD=mypassword pg_dump -Fc --no-acl --no-owner -h localhost -U myuser mydb > mydb.dump
Replace myuser
, mypassword
, and mydb
with your username, password and database name. 将
myuser
, mypassword
和mydb
替换为您的用户名,密码和数据库名称。 If there is no password set, leave out the PGPASSWORD=mypassword
part. 如果未设置密码,则忽略
PGPASSWORD=mypassword
部分。
Next, you must place the mydb.dump
file in a publicly accessible location, so upload it to an FTP server or Amazon S3 bucket (for example). 接下来,您必须将
mydb.dump
文件放置在公共可访问的位置,然后将其上传到FTP服务器或Amazon S3存储桶(例如)。
Then on your local machine run: 然后在您的本地计算机上运行:
heroku pg:backups restore 'https://s3.amazonaws.com/me/mydb.dump' HEROKU_POSTGRESQL_COLOR_URL -a appname
Replace HEROKU_POSTGRESQL_COLOR_URL
with the URL for your app's database. 将
HEROKU_POSTGRESQL_COLOR_URL
替换为应用程序数据库的URL。 If you don't know the URL, you can find it with heroku config | grep HEROKU_POSTGRES
如果您不知道该URL,则可以使用
heroku config | grep HEROKU_POSTGRES
heroku config | grep HEROKU_POSTGRES
. heroku config | grep HEROKU_POSTGRES
。 Replace https://s3.amazonaws.com/me/mydb.dump
with the URL where you uploaded the dump file. 将
https://s3.amazonaws.com/me/mydb.dump
替换为上载转储文件的URL。 Replace appname with name of your app as defined in Heroku. 用Heroku中定义的应用名称替换应用名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.