Created
September 7, 2011 05:25
-
-
Save Sutto/1199830 to your computer and use it in GitHub Desktop.
Automatically backs up a github accounts repositories
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
require 'fileutils' | |
require 'octokit' | |
require 'ap' | |
ACCOUNT_NAME = "your-user-name" | |
ACCOUNT_TOKEN = "your-api-token" | |
ITEMS_UNDER = "target-user-or-organisation" | |
REPO_ROOT = File.expand_path('../repositories', __FILE__) | |
FileUtils.mkdir_p REPO_ROOT | |
def clone_or_update!(slug, repository) | |
destination = File.join(REPO_ROOT, slug) | |
if File.directory?(destination) | |
Dir.chdir(destination) { system "git fetch" } | |
else | |
Dir.chdir(REPO_ROOT) do | |
system "git", "clone", "--mirror", repository, slug | |
end | |
end | |
end | |
client = Octokit::Client.new(:login => ACCOUNT_NAME, :token => ACCOUNT_TOKEN) | |
client.repositories(ITEMS_UNDER).each do |repository| | |
name = repository["name"] | |
url = "git@github.com:#{repository["owner"]}/#{name}.git" | |
puts "Getting #{name} from #{url}:" | |
clone_or_update! name, url | |
puts "\n\n\n" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment