【发布时间】:2021-03-19 08:17:03
【问题描述】:
我犯了这个错误 6 小时后发疯了。
我已经使用 CLI 创建了一个 heroku 应用程序并成功推送了 git,但是我需要在应用程序工作之前使用 db.create_all() 初始化一堆表,但是我的 localhost postgres 中有 6gb 的数据我希望迁移到heroku使用。
以通常的方式 (create_all) 实例化表格将不起作用,因为索引页面的表格需要某些内容,因此我的表格必须预先填充所述本地主机数据才能工作。
我已按照此处的文档进行操作,并导出了我的 .dump 文件并将其上传到我的存储桶:https://devcenter.heroku.com/articles/heroku-postgres-import-export#import
已启用公共共享,我已使用 setx 命令在 AWS CLI 中设置 ACCESS_KEY_ID 和 SECRET_ACCESS_KEY。我也设置了heroku config:set AWS_ACCESS_KEY_ID=matching_aws_cli_blah AWS_SECRET_ACCESS_KEY=matching_aws_cli_blah。
然后使用命令 aws s3 presign s3_url 我复制了输出(我将添加看起来与我使用的 AWS 文档 https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3/presign.html 不同)
我的外观示例(随机更改了一些数字)
https://mybucketname.s3.eu-west-2.amazonaws.com/mydb.dump?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=LLLLL4C7LLLLLLLNLLLQ%2FNNNNNN08%2Feu-west-2%2Fs3%2Faws4_request&X-Amz-Date=20201208T004613Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&X-Amz-Signature=ll9d80nnnnc457ea83298fdnnnn4a25b0c9ll066f54e6ff8acf42dafnnnea8877 而文档提供了一个漂亮整洁的 AWSAccessKeyId= 变量。
我只有一个存储桶,Block public access (bucket settings) 设置为 OFF,并且文件本身可以公开共享。对象 URL 初始化下载正常,包括隐身。
使用以下命令时(根据 heroku 文档)
heroku pg:backups:restore 'https://mybucketname.s3.eu-west-2.amazonaws.com/mydb.dump?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=LLLLL4C7LLLLLLLNLLLQ%2FNNNNNN08%2Feu-west-2%2Fs3%2Faws4_request&X-Amz-Date=20201208T004613Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&X-Amz-Signature=ll9d80nnnnc457ea83298fdnnnn4a25b0c9ll066f54e6ff8acf42dafnnnea8877' DATABASE_URL
我得到以下输出到终端。
Restoring... !
! An error occurred and the backup did not finish.
!
! waiting for restore to complete
! pg_restore finished with errors
! waiting for download to complete
! download finished with errors
! please check the source URL and ensure it is publicly accessible
!
! Run heroku pg:backups:info r001 for more details.
'X-Amz-Credential' is not recognized as an internal or external command,
operable program or batch file.
'X-Amz-Date' is not recognized as an internal or external command,
operable program or batch file.
'X-Amz-Expires' is not recognized as an internal or external command,
operable program or batch file.
'X-Amz-SignedHeaders' is not recognized as an internal or external command,
operable program or batch file.
'X-Amz-Signature' is not recognized as an internal or external command,
operable program or batch file.
日志文件中显示的
=== Backup r001
Database: BACKUP
Started at: 2020-12-08 00:47:33 +0000
Finished at: 2020-12-08 00:47:34 +0000
Status: Failed
Type: Manual
Backup Size: 0.00B (0% compression)
=== Backup Logs
2020-12-08 00:47:34 +0000 2020/12/08 00:47:34 aborting: could not write to output stream: Expected HTTP Status 200, received: "400 Bad Request"
2020-12-08 00:47:34 +0000 pg_restore: error: could not read from input file: end of file
2020-12-08 00:47:34 +0000 waiting for restore to complete
2020-12-08 00:47:34 +0000 pg_restore finished with errors
2020-12-08 00:47:34 +0000 waiting for download to complete
2020-12-08 00:47:34 +0000 download finished with errors
2020-12-08 00:47:34 +0000 please check the source URL and ensure it is publicly accessible
请有人指出我哪里出错了?
谢谢!
【问题讨论】:
-
无论何时在命令行上使用预签名的 URL,都需要引用它们。它们包含诸如
&这样对shell 有意义的结构。因此,通常您应该将预签名的 URL 用双引号括起来。
标签: postgresql amazon-web-services amazon-s3 heroku