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.
Get Started with the Heroku CLIAfter you install the CLI, run the heroku login command. Enter any key to go to your web browser to complete login. The CLI then logs you in automatically. If you'd prefer to stay in the CLI to enter your credentials, run heroku login -i .
The Heroku Toolbelt is a package of the Heroku CLI, Foreman, and Git — all the tools you need to get started using Heroku at the command line. The Toolbelt is available as a native installer for OS X, Windows, and Debian/Ubuntu Linux. The Toolbelt has been available since last fall as part of our polyglot platform.
Scheduling jobsOn the Scheduler Dashboard, click “Add Job…”, enter a task, select a frequency, dyno size, and next run time. Note that the next run time for daily jobs is in UTC. If you want to schedule the job at a certain local time, add the proper UTC offset.
Automatic dyno restartscreate a new release by deploying new code. change your config vars. change your add-ons. run heroku restart.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With