Hi all,
I'd like to periodically create a backup of my github repositories. Is there a quick way to pull all of them without knowing what the entire list is?
Walter
Hi all,
I'd like to periodically create a backup of my github repositories. Is there a quick way to pull all of them without knowing what the entire list is?
Walter
You can get the entire list via GitHub's API:
curl http://github.com/api/v2/yaml/repos/show/walterjwhite
For example, this simple DOS/Unix shell one-liner:
ruby -ryaml -ropen-uri -e "puts YAML.load(open('http://github.com/api/v2/yaml/repos/show/walterjwhite'))['repositories'].map {|r| %Q[* **#{r[:name]}** (#{r[:description]}) is at <#{r[:url]}/>] }"
prints (assuming you have Ruby installed):
The answer I was waiting for.
I decided to give Ruby a try and it is okay. I like how it is compact, but it isn't pretty looking :(.
This works:
#!/usr/bin/env ruby
require "yaml"
require "open-uri"
time = Time.new
backupDirectory = "/storage/backups/github.com/#{time.year}.#{time.month}.#{time.day}"
username = "walterjwhite"
#repositories =
# .map{|r| %Q[#{r[:name]}] }
#FileUtils.mkdir_p #{backupDirectory}
YAML.load(open("http://github.com/api/v2/yaml/repos/show/#{username}"))['repositories'].map{|repository|
puts "found repository: #{repository[:name]} ... downloading ..."
#exec
system "git clone [email protected]:#{username}/#{repository[:name]}.git #{backupDirectory}/#{repository[:name]}"
}
Walter