how to install pg_dump and pg_restore to the heroku - heroku

I have to load pg_dump and the pg_restore to Heroku so that I can load a local database to Heroku. How can I install pg_dump and pg_restore on Heroku? What are their addresses?

So they way Heroku works is you install an addon to your Heroku app called Heroku Postgres. Then you add another app called PGBackups. These apps expose commands to your command line. They are like subcommands to the heroku command. So you'd do heroku pgbackups:restore to restore (or really, load initially) a database to your Heroku instance. See this link:
https://devcenter.heroku.com/articles/heroku-postgres-import-export

Related

How to schedule PostgreSql procedure using Heroku scheduler?

I am trying to schedule PostgreSql procedure using Heroku scheduler. I tried heroku pg:psql -c "call procedure_name();" --app app-name but gets the error from scheduler "bash: heroku: command not found"
That error is telling you important information. The Heroku CLI is not present in your environment, so bash complains that heroku isn't a command that it recognizes.
If you want to run heroku commands from your application you'll need to include the cli buildpack when you build your application to make sure it's properly bundled. Once you've included the buildpack and triggered a new build, this should work.

How do I run heroku-toolbelt commands without the `--app` parameter

I used to run heroku create and deploying with git push heroku master but I've since moved onto a Github based workflow where code is first pushed to my Github repo, and deployed via a web hook.
I now have to run --app appname or -a appname after every command, and it gets annoying.
e.g.
heroku run rails db:migrate -a appname # instead of
heroku run rails db:migrate
heroku run rails console -a appname # instead of
heroku run rails console
heroku run logs -t -a appname # instead of
heroku run logs -t
How do I force heroku-toolbelt to link this repo to the heroku app so that I can run heroku without the --app parameter
Add a remote named heroku with the url https://git.heroku.com/appname.git
Run this:
$ git remote add heroku https://git.heroku.com/appname.git

`container:init` is not a heroku command

I have installed heroku with homebrew in my OSX El Capitan(10.11.5) and installed the heroku-container-tools with:
heroku plugins:install heroku-container-tools
The installation goes successfully:
Installing plugin heroku-container-tools... done
When I run a heroku version, I got this:
heroku-toolbelt/3.42.22 (universal.x86_64-darwin15) ruby/2.0.0
heroku-cli/5.2.20-9d094b0 (darwin-amd64) go1.6.2
=== Installed Plugins
heroku-container-tools#3.0.0
But when I run a heroku container:init I got this:
! `container:init` is not a heroku command.
! See `heroku help` for a list of available commands.
Running heroku help container I got this:
Usage: heroku container
Use Docker to build and deploy Heroku apps
Use Docker to build and deploy Heroku apps
Additional commands, type "heroku help COMMAND" for more details:
container:login # Logs in to the Heroku Docker registry
container:push [PROCESS] # Builds, then pushes a Docker image to deploy your Heroku app
I am following this heroku tutorial: https://devcenter.heroku.com/articles/local-development-with-docker
In the tutorial is said to run heroku container:init
This command was replaced but some other and heroku did not updated their documentation or I have some problem installing the plugin?
Yes, they restricted access to their container registry, just read the warning on top of the tutorial you're following https://devcenter.heroku.com/articles/local-development-with-docker
heroku container:release, which creates a Heroku-compatible slug and
deploys it to Heroku, has been deprecated. For access to our container
registry (available in private beta), please contact
docker-feedback#heroku.com
now there are only login and push commands. I hope you can easily ask for the access.

Access to heroku toolbelt commands in a scheduled heroku dyno?

I want to call heroku postgres backup/restore commands within a scheduled heroku task, but the heroku toolbelt isn't available from bash prompt, so I can't call heroku commands:
$ heroku run bash --app myapp
Running `bash` attached to terminal... up, run.4805
~ $ heroku --version
bash: heroku: command not found
How can I get heroku commands available in my scheduled bash script?
I don't know anything about Ruby or Ruby Gems.
None of the other solutions worked for me since Heroku locks the filesystem after the buildpacks finish running.
There's a third-party buildpack that installs the CLI for you. First you set your auth key as an ENV variable on your app:
heroku config:set HEROKU_API_KEY=`heroku auth:token` -a myapp
Then add the buildpack:
heroku buildpacks:add https://github.com/heroku/heroku-buildpack-cli -a myapp
Redeploy your app and it should be able to access your apps via the CLI. If you have https://devcenter.heroku.com/articles/dyno-metadata enabled, you can even access your current app's name with $HEROKU_APP_NAME.
Put this at the top of your scheduled bash script:
# install heroku toolbelt
# inspired by https://toolbelt.heroku.com/install.sh
curl -s https://s3.amazonaws.com/assets.heroku.com/heroku-client/heroku-client.tgz | tar xz
mv heroku-client/* .
rmdir heroku-client
PATH="bin:$PATH"
then, for example, you can call:
heroku pg:reset HEROKU_POSTGRESQL_YELLOW_URL --app myapp-staging --confirm myapp-staging
heroku pgbackups:restore HEROKU_POSTGRESQL_YELLOW_URL `heroku pgbackups:url --app myapp-production` --app myapp-staging --confirm myapp-staging
and poof! Staging database is updated from production database.
As Heather Piwowar said, you can indeed download and untar the heroku tollbelt yourself, but no need to move files around after this. Here is a shorter version:
curl -s https://s3.amazonaws.com/assets.heroku.com/heroku-client/heroku-client.tgz | tar xz
PATH="/app/heroku-client/bin:$PATH"
You can now use the heroku command as you wish.
For authentification, you may want to set the HEROKU_API_KEY env var (using heroku config:set HEROKU_API_KEY=1234567890 -a your-app-name).
Also, note that the first use of the heroku command will run longer than expected because it will try to install the latest version, dependencies and core plugins.
You can use Heroku Scheduler and configure the following command (as an example) to create a database backup:
curl -s https://s3.amazonaws.com/assets.heroku.com/heroku-client/heroku-client.tgz \
| tar xz && ./heroku-client/bin/heroku pg:backups:capture -a you-app-name-here
For this to work, you need to add a Config Variable named HEROKU_API_KEY and set its value to the "API Key" value from your Accounts page.

how to setup postgres db in Heroku

I'm totally new to Heroku and Postgres and I'm trying to figure out how to setup and access the Postgres db in a Heroku Ruby app.
I'm not sure how to go about setting this up. I've found some information about using the command:
rake db:create
Where do I enter this command? I'm completely in the dark on this.
Any help with how to setup/access the Postgres db in Heroku would be greatly appreciated.
Thanks.
Without info on what type of Ruby app you're building, what gems you may be utilizing, or what frameworks you may be building on, it is impossible to completely guide you through how to connect your Ruby app to the Heroku Postgres database. But here are a few things to point you in the right direction:
Install the Heroku Toolbelt as #jordan.baucke suggested. Beyond just adding plugins, you'll be using this toolbelt for nearly every Heroku-related action. Just follow the link, download, and install. Easy!
Now that you have the toolbelt, login to your account from the command line: heroku login.
Now make your app. While in your app folder (on the command line), execute: heroku apps:create <app name> -s cedar.
Now add the Postgres db: heroku addons:add heroku-postgresql:dev -a <app name>
From Ruby, you can connect to the db through the environment variable: ENV['DATABASE_URL'].
Deploy the app via git: git push heroku master.
From here, we really can't give you any further guidance since we don't know how you're interfacing with Postgres. But the above steps should at least get you to be able to connect to the db from your Heroku app.
For starters, are you using the the Heroku toolbelt? (command line tools?)
You can do it from the website as well, but with the toolbelt, you can enter heroku addons:add heroku-postgresql:dev --app *your app name*
Heroku will automatically inject the database into your app's database.yml when you deploy your app into Heroku.
Finally, you need to migrate the production database to your current migrations. You can do this remotely with the toolbelt again:
$ heroku run rake db:migrate
This will remotely connect a console and pull your migrations into your production database on the server.

Resources