Heroku Cheatsheet


Basic

Create a new app

# generate random app name
heroku create

# specify app name
heroku create foo

Link a folder with an existing Heroku app:

heroku git:remote -a project

Different ways of running a heroku command with a particular app

# using git remote name
heroku command --remote remote_name
heroku command -r remote_name

# using app name
heroku command --app app_name
heroku command -a app_name

Logs

Log types and filters:

App logs: --source app
System logs: --source heroku
API logs: --source heroku --dyno api

Log format:

timestamp source[dyno]: message

# example
2010-09-16T15:13:46.677020+00:00 app[web.1]: Processing PostController#list (for 208.39.138.12 at 2010-09-16 15:13:46) [GET]
2010-09-16T15:13:46.677023+00:00 app[web.1]: Rendering template within layouts/application
2010-09-16T15:13:46.677902+00:00 app[web.1]: Rendering post/list
2010-09-16T15:13:46.678990+00:00 app[web.1]: Rendered includes/_header (0.1ms)
2010-09-16T15:13:46.698234+00:00 app[web.1]: Completed in 74ms (View: 31, DB: 40) | 200 OK [http://myapp.heroku.com/]
2010-09-16T15:13:46.723498+00:00 heroku[router]: at=info method=GET path="/posts" host=myapp.herokuapp.com" fwd="204.204.204.204" dyno=web.1 connect=1ms service=18ms status=200 bytes=975
2010-09-16T15:13:47.893472+00:00 app[worker.1]: 2 jobs processed at 16.6761 j/s, 0 failed ...

Commands:

# retrieve logs, 100 lines
heroku logs

# specify number of lines retrieved [--num / -n] max 1500
heroku logs -n 200

# get realtime logs [--tail / -t]
heroku logs --tail

Postgresql

Common commands

# list backups
heroku pg:backups

# create a back up
heroku pg:backups:capture

# cancel backup
heroku pg:backups:cancel

# download latest backup
heroku pg:backups:download

# import backup to local database
pg_restore --verbose --clean --no-acl --no-owner -h localhost -U myuser -d mydb latest.dump

Domains

# list domains
heroku domains

# add domain
heroku domains:add www.example.com

# remove domain
heroku domains:remove www.example.com

Maintenance mode

heroku maintenance:on   # Enable maintenance mode
heroku maintenance:off  # Disable maintenance mode
heroku maintenance      # Check maintenance status

Install nano editor in Heroku shell

mkdir /app/nano
curl https://github.com/Ehryk/heroku-nano/raw/master/heroku-nano-2.5.1/nano.tar.gz --location --silent | tar xz -C /app/nano
export PATH=$PATH:/app/nano

Reference: https://stackoverflow.com/a/48168665