Using heroku pg:backups:restore to Import to Heroku Postgres



根据本文,我正在尝试将本地PostgreSQL数据库复制到Heroku。

以下是我所做的:

1.制作一个转储文件

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

2.将转储文件上传到aws my bucket name/db备份文件夹

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

我在GENERATED_URL周围使用双引号,因为我在Windows:上

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.

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

此问题已解决。有两个问题。

  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 postgres -d mydb -f mydb.dump

做出改变后,一切都很顺利。

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

相关内容

  • 没有找到相关文章

最新更新