Created
September 4, 2015 18:23
-
-
Save softr8/be3a08309dadaf947012 to your computer and use it in GitHub Desktop.
Backup github repos locally
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 'github_api' | |
require 'git' | |
client = Github.new oauth_token: 'TOKEN', org: 'ORG_NAME' | |
BASE_DIR ||= '../repos' | |
i = 1 | |
while true | |
repos = client.repos.list(page: i) | |
break if repos.size == 0 | |
repos.each do |repo| | |
type = repo.private ? "private" : "public" | |
repo_path = File.join BASE_DIR, type, repo.name | |
unless Dir.exists?(repo_path) | |
puts "Cloning repo #{repo.name}..." | |
Git.clone repo.ssh_url, repo_path | |
puts "...Done" | |
end | |
g = Git.open(repo_path) | |
puts "Fetching new changes of #{repo.name}" | |
puts g.pull | |
puts "...Done" | |
end | |
i += 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment