Skip to content

Instantly share code, notes, and snippets.

@joshellington
Created May 19, 2014 01:07
Show Gist options
  • Save joshellington/5dadb27095e940314821 to your computer and use it in GitHub Desktop.
Save joshellington/5dadb27095e940314821 to your computer and use it in GitHub Desktop.
Backup your Github organization repos.
require 'github_api'
require 'optparse'
require 'pp'
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: github_org_backup.rb [options]"
opts.on("-u", "--user USER", "Your Github username") do |v|
options[:user] = v
end
opts.on("-p", "--password PASSWORD", "Your Github password") do |v|
options[:password] = v
end
opts.on("-o", "--organization ORGANIZATION", "Your Github organization") do |v|
options[:org] = v
end
opts.on("-d", "--directory DIRECTORY", "Backup directory") do |v|
options[:backup_directory] = v
end
end.parse!
pp options
github = Github.new basic_auth: "#{options[:user]}:#{options[:password]}", org: "#{options[:org]}"
repos = github.repos.list auto_pagination: true
repos.each do |repo|
pp '////////////////////////'
pp "Working on #{repo.name}"
path = "#{options[:backup_directory]}/#{options[:org]}-#{repo.name}"
`git clone #{repo.ssh_url} #{path};`
`cd #{path}; git bundle create #{repo.name}.bundle --all --branches --tags;`
# `git bundle create #{backup_directory}/#{repo.name}.bundle --all --remote=#{repo.ssh_url};`
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment