Skip to content

Instantly share code, notes, and snippets.

@ravidsrk
Forked from addyosmani/gitback.rb
Created March 22, 2012 19:09
Show Gist options
  • Save ravidsrk/2161877 to your computer and use it in GitHub Desktop.
Save ravidsrk/2161877 to your computer and use it in GitHub Desktop.
A little Ruby script for backing up *all* of the repos on your GitHub account with a single command
#gitback 0.1
#usage: sudo ruby gitback.rb
#credits: walter white, minor changes: addy osmani
#!/usr/bin/env ruby
# dependencies
require "yaml"
require "open-uri"
time = Time.new
# feel free to edit this as you please
backupDirectory = "/backups/github.com/#{time.year}.#{time.month}.#{time.day}"
# your github username
username = "addyosmani"
#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 "discovered repository: #{repository[:name]} ... backing up ..."
#exec
system "git clone [email protected]:#{username}/#{repository[:name]}.git #{backupDirectory}/#{repository[:name]}"
}

and if you just want a quick way to list all your repos this might be useful:

#replace 'addyosmani' with your username:
ruby -ryaml -ropen-uri -e "puts YAML.load(open('http://github.com/api/v2/yaml/repos/show/addyosmani'))['repositories'].map {|r| %Q[* **#{r[:name]}** (#{r[:description]}) is at <#{r[:url]}/>] }"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment