使用heroku pg:backups:restore导入到Heroku Postgres 1制作转储文件 2将转储文件上传到AWS my-bucket-name / db-backup文件夹中 3生成签名的URL: 4验证签名的URL是否可访问 5使用生成的签名URL备份到Heroku 结果

问题描述

我正在尝试将本地Postgresql数据库复制到Heroku per this article

这是我所做的:

1。制作转储文件

pg_dump -Fc --no-acl --no-owner -h localhost -U postgres mydb > mydb.dump

2。将转储文件上传到AWS my-bucket-name / db-backup文件夹中。

aws s3 cp mydb.dump s3://my-bucket-name/db-backup/mydb.dump

3。生成签名的URL:

aws s3 presign s3://my-bucket-name/db-backup/mydb.dump --region us-east-2

4。验证签名的URL是否可访问。

在浏览器的隐身标签中导航到预签名的URL。可以。

5。使用生成的签名URL备份到Heroku

由于在Windows上,我在GENERATED_URL周围使用双引号:

heroku pg:backups:restore --app my-app-name --confirm my-app-name "GENERATED_URL"

例如:

heroku pg:backups:restore --app my-app-name --confirm my-app-name "https://s3.us-east-2.amazonaws.com/s3.console.aws.amazon.com/s3/buckets/my-bucket-name/db-backup/mydb.dump?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIABCDVKE2GXCY3YXL7V%2F20200934%2Fus-east-2%2Fs3%2Faws4_request&X-Amz-Date=20200924T164718Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&X-Amz-Signature=fb2f51c0d7fbe1234e3740cf23c37f003575d968a1e4961684a47ac627fbae2e"

结果

我收到以下错误

Restoring... !
 !    An error occurred and the backup did not finish.
 !
 !    Could not initialize transfer
 !
 !    Run heroku pg:backups:info r021 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.

我发现其他人也有类似的问题,但没有解决方案。预先感谢任何可以提供帮助的人。

解决方法

无论如何,我遇到了同样的问题,我的解决方案是复制格式为 https://s3.amazonaws.com/<bucket_name>/<dump_file>.dump 的 S3 URL。出于某种原因,预签名 URL 方法不起作用,但公共 URL 起作用。

,

已解决。有两个问题。

  1. PowerShell没有正确转义字符。因此,我切换到CMD。
  2. 转储文件无效。

以下代码行生成了无效的转储文件:

pg_dump -Fc --no-acl --no-owner -h localhost -U postgres mydb > mydb.dump

相反,我需要使用以下语法:

pg_dump -Fc --no-acl --no-owner -h localhost -U myuser -d mydb -f mydb.dump

进行更改后,所有操作均顺利进行。