简体   繁体   English

在转储文件上使用pg_restore

[英]Using pg_restore on dump file

I have a database on Heroku I'm trying to copy to my local machine. 我有一个关于Heroku的数据库我正在尝试复制到我的本地机器上。

I created a backup of the database by doing: 我通过执行以下操作创建了数据库的备份:

heroku pgbackups:capture

This create a dump file of the database which I downloaded by creating a URL link to it: 这创建了我通过创建URL链接下载的数据库的转储文件:

heroku pgbackups:url b004

But now I have a dump file and don't really know what do to with it. 但现在我有一个转储文件,并不知道如何处理它。 I tried 我试过了

pg_restore

to restore the database but I don't know where that information went. 恢复数据库,但我不知道该信息的去向。 I basically want to create a .db file out of this dump file. 我基本上想要从这个转储文件中创建一个.db文件。 Is that possible? 那可能吗?

Ultimately my end goal is to access this database -- so if another method of copying the db is better, I'm fine with that that. 最终我的最终目标是访问这个数据库 - 所以如果另一种复制数据库的方法更好,我就可以了。

Heroku does not allow you to use sqlite files, as they have a read only file system. Heroku不允许您使用sqlite文件,因为它们具有只读文件系统。 But you can use Django to dump the data from Heroku into a JSON file via the dumpdata command, and them import that into your local dev environment. 但是你可以使用Django通过dumpdata命令将Heroku中的数据转储到JSON文件中,然后将它们导入到本地开发环境中。

Because it can be difficult to run commands that generate files on the web server using heroku run , I suggest you instead install django smuggler , which makes this operation a point and click affair in admin. 因为运行使用heroku run在Web服务器上生成文件的命令可能很困难,所以我建议你安装django smuggler ,这使得这个操作成为一个点,然后在admin中单击。

在此输入图像描述

First of all you should install postgres in your local machine. 首先,您应该在本地计算机上安装postgres。

PostgreSQL cheat sheet for django beginners 用于django初学者的PostgreSQL备忘单

Then, import your dump file with pg_restore command: 然后,使用pg_restore命令导入转储文件:

pg_restore -d yournewdb -U yournewuser --role=yournewuser /tmp/b001.dump

Thats all, your data is now cloned from your heroku app. 多数,您的数据现在从您的heroku应用程序克隆。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM