Search code examples
backupgithub

Backup / Mirror Github repositories


I'd like to periodically create a backup of my github repositories. Is there a quick way to pull all of them without knowing what the entire list is?

Walter


Solution

  • The answer I was waiting for.

    I decided to give Ruby a try and it is okay. I like how it is compact, but it isn't pretty looking :(.

    This works:

    #!/usr/bin/env ruby
    require "yaml"
    require "open-uri"
    
    time = Time.new
    backupDirectory = "/storage/backups/github.com/#{time.year}.#{time.month}.#{time.day}"
    username = "walterjwhite"
    
    #repositories =
    # .map{|r| %Q[#{r[:name]}] }
    
    #FileUtils.mkdir_p #{backupDirectory}
    
    YAML.load(open("http://github.com/api/v2/yaml/repos/show/#{username}"))['repositories'].map{|repository|
    
        puts "found repository: #{repository[:name]} ... downloading ..."
        #exec
        system "git clone git@github.com:#{username}/#{repository[:name]}.git #{backupDirectory}/#{repository[:name]}"
    }
    

    Walter