Skip to content

Instantly share code, notes, and snippets.

@stopanko
Forked from nabucosound/heroku_env_copy.sh
Last active June 24, 2019 11:27
Show Gist options
  • Save stopanko/77dfa4826ba0dd765dc35982bb208b1a to your computer and use it in GitHub Desktop.
Save stopanko/77dfa4826ba0dd765dc35982bb208b1a to your computer and use it in GitHub Desktop.
Script to copy environment variables from an existing heroku app to another one
# https://emirkarsiyakali.com/heroku-copying-environment-variables-from-an-existing-app-to-another-9253929198d9
# Bash script
heroku config -s -a existing-heroku-app > config.txt
cat config.txt | tr '\n' ' ' | xargs heroku config:set -a new-heroku-app
# Ruby Script
#!/usr/bin/env ruby
require 'json'
source_app = ARGV[0]
dest_app = ARGV[1]
ignore = %w(DATABASE_URL)
vars = JSON.parse `heroku config --app #{source_app} --json`
vars.each do |key, value|
next if ignore.include?(key)
`heroku config:set #{key}="#{value}" --app #{dest_app}`
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment