-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script to clone heroku repos & data
- Loading branch information
1 parent
a1c79e8
commit 3c0cd2a
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require "json" | ||
|
||
def heroku_cli_missing? | ||
result = system("heroku auth:whoami >/dev/null", exception: true) | ||
|
||
!result | ||
end | ||
|
||
def fetch_heroku_apps | ||
IO.popen("heroku apps --json") do |io| | ||
json = io.read | ||
io.close | ||
JSON.parse(json) | ||
end | ||
end | ||
|
||
def clone_code(name, git_url) | ||
cmd = "git clone #{git_url} #{name}" | ||
|
||
system(cmd) | ||
end | ||
|
||
def fetch_backup(name) | ||
capture = "heroku pg:backups:capture --app=#{name}" | ||
download = "heroku pg:backups:download --app=#{name}" | ||
move = "mv latest.dump #{name}/pg-data.dump" | ||
cmd = [capture, download, move].join(" && ") | ||
|
||
system(cmd) | ||
end | ||
|
||
if __FILE__ == $0 | ||
if heroku_cli_missing? | ||
puts "Could not find `heroku` CLI " | ||
puts "$ brew install heroku" | ||
exit -1 | ||
end | ||
|
||
apps = fetch_heroku_apps | ||
apps.each do |app| | ||
name, git_url = app.values_at("name", "git_url") | ||
puts "app: #{name}" | ||
|
||
clone_code(name, git_url) | ||
fetch_backup(name) | ||
end | ||
|
||
exit 0 | ||
end |