Created
October 27, 2012 13:19
-
-
Save k9ert/3964597 to your computer and use it in GitHub Desktop.
Backup Git based on a script by Alter White
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
#!/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