如何使用pgbackups将生产数据库转储到Heroku上?获取错误 [英] How do I transfer production database to staging on Heroku using pgbackups? Getting error

查看:97
本文介绍了如何使用pgbackups将生产数据库转储到Heroku上?获取错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Heroku上,我试图使用pgbackups插件将生产数据库复制到我的登台应用程序中。我按照插件页面上的说明操作: https://devcenter.heroku.com/articles/pgbackups



首先我抓住了DB:

  heroku pgbackups:capture --app production- app 

结果如下:

  HEROKU_POSTGRESQL_PURPLE(DATABASE_URL)---- backup ---> b238 

撷取...完成
储存...完成

然而,当我尝试在临时应用程序上恢复它时:

  heroku pgbackups:restore数据库`heroku pgbackups:url  - app production-app` --remote staging 

我收到以下错误消息:

  DATABASE_URL与您的任何数据库不匹配
!无法解析数据库DATABASE

!可用数据库:

我也尝试输入完整的网址:

  heroku pgbackups:url b238 --app production-app 
heroku pgbackups:restore DATABASEhttps://s3.amazonaws.com / ... --remote staging

并尝试命名应用程序(而不是--remote staging):

  heroku pgbackups:restore DATABASE`heroku pgbackups:url --app production-app` --app staging-app 

这些都不起作用。有意思的是,错误消息表明没有可用数据库。我假设它指的是确实是空的分段应用程序。如果我输入:

  heroku pgbackups 

我得到:

 !没有备份。用`heroku pgbackups:capture`捕获一个。 

要找到可用的备份(产品),我需要输入:

  heroku pgbackups --app production-app 

,我得到当前备份的列表。我不知道这是否正常,或者即使它与问题有关,但我想我应该提及它。

我已经阅读并尝试过所有关于SO的答案,但没有任何成效。任何想法?

解决方案

2017年中的更新(从 Takehiro Mouri < DATABSE_NAME部分)



2015年年中的更新...



pgbackups加载项已被弃用。没有 pgbackups:transfer



要将数据库从 yourapp 复制到 yourapp_staging

 #在关闭
heroku maintenance:on -a yourapp中关闭Web dynos -staging

#如果你有非web-dynos,也可以这样做
heroku ps:scale worker = 0 -a yourapp-staging

#backup (可选)
heroku pg:备份捕获-a yourapp-staging

#执行副本
heroku pg:复制你的应用程序:: DATABASE_URL DATABASE_URL -a yourapp-staging

然后,当完成时,转向登陆:

 #这是如果您有工人,将'1'更改为
heroku ps:scale worker = 1 - yourapp-staging

heroku maintenance:off -a yourapp-staging

(来源:< a href =https://devcenter.heroku.com/articles/upgrading-heroku-postgres-databases#upgrade-with-pg-copy-default rel =noreferrer> https://devcenter.heroku.com/articles/upgrading-heroku-postgres-databases#upgrade-with-pg-copy-default )


On Heroku, I am trying to copy the production database into my staging app using the pgbackups addon. I followed the instructions on the addon page: https://devcenter.heroku.com/articles/pgbackups

First I captured the DB:

heroku pgbackups:capture --app production-app 

That worked:

HEROKU_POSTGRESQL_PURPLE (DATABASE_URL)  ----backup--->  b238

Capturing... done
Storing... done

However when I try to restore it on the staging app:

heroku pgbackups:restore DATABASE `heroku pgbackups:url --app production-app` --remote staging

I get the following error message:

DATABASE_URL does not match any of your databases
 !    Could not resolve database DATABASE
 !    
 !    Available databases: 

I have also tried typing in the full URL:

 heroku pgbackups:url b238 --app production-app
 heroku pgbackups:restore DATABASE "https://s3.amazonaws.com/..." --remote staging

and also tried naming the app (instead of --remote staging):

heroku pgbackups:restore DATABASE `heroku pgbackups:url --app production-app` --app staging-app

None of these worked. It's interesting to note that the error message says there are no "Available databases". I'm assuming it is referring to the staging app which is indeed empty. If I type:

heroku pgbackups

I get:

 !    No backups. Capture one with `heroku pgbackups:capture`.

To find the available backups (production), I need to type:

heroku pgbackups --app production-app

and I get the list of current backups. I don't know if this is normal or even if it is related to the problem, but I thought I should mention it.

I have read and tried every answer here on SO but nothing worked. Any ideas?

解决方案

Update for mid-2017 (stealing from Takehiro Mouri's answer - simplify the DATABSE_NAME part)

Update for mid-2015...

The pgbackups add-on has been deprecated. No more pgbackups:transfer.

To copy a database from yourapp to yourapp_staging:

# turn off the web dynos in staging
heroku maintenance:on -a yourapp-staging

# if you have non-web-dynos, do them too
heroku ps:scale worker=0 -a yourapp-staging

# backup the staging database if you are paranoid like me (optional)
heroku pg:backups capture -a yourapp-staging

# execute the copy
heroku pg:copy your-app::DATABASE_URL DATABASE_URL -a yourapp-staging

Then when it's complete, turn staging back on:

# this is if you have workers, change '1' to whatever
heroku ps:scale worker=1 -a yourapp-staging

heroku maintenance:off -a yourapp-staging

(source: https://devcenter.heroku.com/articles/upgrading-heroku-postgres-databases#upgrade-with-pg-copy-default)

这篇关于如何使用pgbackups将生产数据库转储到Heroku上?获取错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆