Skip to content

Instantly share code, notes, and snippets.

@k9ert
Created October 27, 2012 13:19
Show Gist options
  • Save k9ert/3964597 to your computer and use it in GitHub Desktop.
Save k9ert/3964597 to your computer and use it in GitHub Desktop.
Backup Git based on a script by Alter White
#!/usr/bin/env ruby
#credits: Walter White, Updates: Addy Osmani
# dependencies
require "json"
require "open-uri"
# your github username
username = "k9ert"
time = Time.new
# feel free to comment out the option you don't wish to use.
backupDirectory = "/backups/github/#{time.year}.#{time.month}.#{time.day}"
backupDirectory = "../github"
#or simply: backupDirectory = "/backups/github/"
#repositories =
# .map{|r| %Q[#{r[:name]}] }
#FileUtils.mkdir_p #{backupDirectory}
JSON.load(open("https://api.github.com/users/#{username}/repos", :ssl_ca_cert=>"/etc/ssl/certs")).map{ |repository|
puts "discovered repository: #{repository["name"]} ... backing up ..."
if File.directory?("#{backupDirectory}/#{repository['name']}")
system "cd #{backupDirectory}/#{repository['name']} && git fetch"
else
system "git clone #{repository['clone_url']} #{backupDirectory}/#{repository['name']}"
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment