How to restore database from one heroku to another heroku database - heroku

I have two Heroku application in that from one heroku application - I take a dump. Now I want to restore that database to another heroku application. so How Can I do that?
I try this :
heroku pgbackups:restore HEROKU_POSTGRESQL_GREEN_URL "URL" --APP
When I run above command then
HEROKU_POSTGRESQL_COLOR_URL <---restore--- b013.dump
Retrieving... done
Restoring... done
then after when I am checking the database then No records display in the table.
All table records are blank
So What Should I do?
Please Help Me, Thanks In Advance

Heroku has step by step documentation on how to do this:
Heroku Dev Center: Using PG Backups to Upgrade Heroku Postgres Databases

Heroku has recently changed their commands around, here is the newest version of how to do it.

Related

Error: Missing required flag: -a, --app APP app to run command against

I am new to Heroku and I keep getting the above error - everything looks good to go when I deploy in heroku, connect to my github repo etc.. but I keep getting this error.
Its a node/express app and works exactly as I'd like locally but it won't deploy. Any help would be appreciated.
For getting logs of particular heroku app, use:
heroku logs --app=app_name
For example: your app name is 'chatapp'
heroku logs -app=chatapp
just run the command with the --app flag, followed by the app name.
I like how the --app flag is "mandatory" according to the official documentation, but the lone usage example in the official documentation doesn't use the --app flag.
Anyway, it's not really mandatory. It's just implicit, usually. You have to tell Heroku which app you're using, with something like:
$ heroku git:remote -a your_app_name
and then it stops wondering which app to run these commands on.
you did not set git remote to your application, do that first by,
heroku git:remote -a your_app_name
To expand a little further on this (just for the benefit of other new users encountering a similar issue) - below is an example of a command you could enter in macOS Terminal:
heroku logs --tail --app yourexampleservername
If you have deployed yourexampleservername to Heroku, this should then display a log.

Upgrade hobby-dev to hobby-basic on Heroku

I'm still getting my head wrapped around Heroku's plans. But I know I'm going to have around 3M rows in the db so I need to upgrade from hobby-dev to hobby-basic.
However, I can't find any documentation or help about this level of upgrade. Only docs to go from Hobby to Standard.
Do I need to create a new PG Add-On and then wipe out my hobby-dev db?
This answer assumes that you're using Heroku CLI. Any instance of "YOUR_APP_NAME" in a command should be replaced by the application name of the Heroku App you're working with.
You will also need on hand the connection URL (shown here as DATABASE_URL) of your current hobby-dev database to be upgraded.
1. Provision a new hobby-basic database:
heroku addons:create heroku-postgresql:hobby-basic -a YOUR_APP_NAME
This will output a name for the new database containing a color. You will need to refer to this later. For example:
HEROKU_POSTGRESQL_PINK_URL
2. Optionally put db into maintenance mode to ensure that no data is added to the db while it's being copied.
heroku maintenance:on --app YOUR_APP_NAME
3. Copy the existing hobby-dev db to the hobby-basic db
heroku pg:copy DATABASE_URL HEROKU_POSTGRESQL_PINK --app YOUR_APP_NAME
Heroku will now print the following message.
heroku pg:copy DATABASE_URL HEROKU_POSTGRESQL_PINK --app YOUR_APP_NAME
! WARNING: Destructive Action
! Transfering data from DATABASE_URL to HEROKU_POSTGRESQL_PINK
! This command will affect the app: YOUR_APP_NAME
! To proceed, type "YOUR_APP_NAME" or re-run this command with --confirm YOUR_APP_NAME
YOUR_APP_NAME
4. Confirm db transfer by typing the actual name of your application
YOUR_APP_NAME
5. Promote your new database
heroku pg:promote HEROKU_POSTGRESQL_PINK --app YOUR_APP_NAME
The color-based name of the database you promote should be copied from the output you got up in step 1. Do not copy and paste the line above word for word, it will not work.
6. If you put your db into maintenance mode earlier, turn it off.
heroku maintenance:off --app YOUR_APP_NAME

Copy production database to staging heroku

How can I pull my production database to my staging server on heroku?
I have two remotes, production and staging.
From the documentation it appears that I want to run heroku pg:copy COBALT GREEN --app sushi but it isn't clear what all the arguments mean. How can I copy my production database to my staging database?
First use:
heroku pg:info -a your_production_app
to retrieve the name of the environment variable that has the URL of your production db, e.g HEROKU_POSTGRESQL_WHITE_URL.
Then:
heroku pg_info -a your_staging_app
to get the same for your staging app (e.g. DATABASE_URL).
Finally:
heroku pg:copy your_production_app::HEROKU_POSTGRESQL_WHITE_URL DATABASE_URL -a your_staging_app
Just to add a clarification to the #Yoni Rabinovitch's answer.
I do not have named database so I needed to replace name with DATABASE_URL instead. It is not much intuitive to duplicate DATABASE_URL, is it?
So instead of:
heroku pg:copy your_production_app::HEROKU_POSTGRESQL_WHITE_URL DATABASE_URL -a your_staging_app
I used
heroku pg:copy your_production_app::DATABASE_URL DATABASE_URL -a your_staging_app
Hope this might help somebody.

Trying to pull Heroku database onto my localhost

I recently made a mistake by rolling back my database too far on my localhost and removed all the data from within the databases I've had. I did migrate the databases so they would return but they still were cleaned out.
Asking around what to do next, I was told that I should backup the database on Heroku (which has all the current information) and pull it onto my localhost. If this is the correct action to take, then I am still facing a problem. When I type:
heroku pg:pull DATABASE_URL mylocaldb --app (my_app_name) it returns an error of:
sh: createdb: command not found
!
! Unable to create new local database. Ensure your local Postgres is
working and try again.
I do not have the best understanding of databases as I am newer; however, I have downloaded sql on my local machine. All of the commands I input are in the regular console and not the psql terminal.
If anyone has any knowledge or can help me, I would greatly appreciate it. Thank you so much!
Joe
Edit: If you do have another method/solution, please let me know. I cannot update my application until I have this done so I do not lose my information.
I would try using backup/restore:
heroku pg:backups --app MYAPPNAME capture
curl -o latest.dump `heroku pg:backups --app MYAPPNAME public-url`
as (almost) documented at
https://devcenter.heroku.com/articles/heroku-postgres-import-export
Note the strange placement of --app MYAPPNAME. It needs to go immediately after the heroku sub-command and before any other arguments.

How can I pull an existing heroku app to new location for development?

I currently have the latest version of my code on another computer that I want to develop from (Home computer and laptop for when I'm out and about) I set up heroku for my app on my laptop. Now I need to associate my code on my desktop so that I can push to heroku from there as well.
This is what I get from my desktop:
desktop:~/NetBeansProjects/onlinescheduler$ git pull heroku master
fatal: 'heroku' does not appear to be a git repository
fatal: The remote end hung up unexpectedly
I can't do heroku create because that will create a separate app. How do I associated the existing code with (or pull down a brand new version from) heroku?
Whats the command to do this?
Also, If you've never used heroku before on the other machine, you'll need to do a few more things first:
$ gem install heroku
$ heroku login
[then enter your credentials]
$ heroku keys:add [path to keyfile]
Now you can clone the remote repository:
$ git clone git#heroku.com:<heroku_app>.git <local_directory>
First of all, you'll want to follow the Quick Start instructions for Heroku, which you can get straight from the horse's mouth, right here: https://devcenter.heroku.com/articles/quickstart
Once you've gotten through step 3, come back here.
Then, you can type this into the command line:
heroku git:clone -a myapp
This is described here:
https://devcenter.heroku.com/articles/git-clone-heroku-app
Then, if you want to grab the database too, here are some options.
Newer Heroku instructions on import/export:
https://devcenter.heroku.com/articles/heroku-postgres-import-export
Older heroku instructions on push and pull: https://blog.heroku.com/archives/2009/3/18/push_and_pull_databases_to_and_from_heroku
If you are using mongo, this is a useful tool to sync your mongo database: https://github.com/pedro/heroku-mongo-sync#readme
If you first need to get the app from Heroku, clone your app.
To do that, write in your Terminal:
heroku git:clone -a your_app_name
If you already have the app and the remote to heroku follow the next steps. If not, you can check instructions here https://devcenter.heroku.com/articles/git
Find the name of your database
Write in your Terminal:
heroku pg:info -a your_app_name
it will look something like this:
HEROKU_POSTGRESQL_MAROON_URL
Find the name of your local database
In your Rails app go to config/database.yml
it will look something like this:
your_app_name_development
Clone your production database (PostgreSQL)
Write in your Terminal with your own database names:
heroku pg:pull HEROKU_POSTGRESQL_MAROON_URL your_app_name_development -a your_app_name
HEROKU_POSTGRESQL_MAROON_URL is an example of how could be the name of your production database (in Heroku):
my_app_name_development is the name of your development database (locally)
the_name_of_my_app is the name of your app in Heroku
Don't forget to finish this with bundle install...
If you already have your code base ready and have heroku setup, use:
$ heroku git:remote -a your_heroku_app
This will allow you to deploy from your new location.
Reference: https://devcenter.heroku.com/articles/git#creating-a-heroku-remote
Once you create a key in a new computer, you have to upload your new SSH key by typing heroku keys:add.

Resources