-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclone-heroku
executable file
·51 lines (39 loc) · 942 Bytes
/
clone-heroku
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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