github-backup 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README.rdoc +27 -0
- data/Rakefile +57 -0
- data/VERSION +1 -0
- data/bin/github-backup +14 -0
- data/github-backup.gemspec +52 -0
- data/lib/github-backup.rb +69 -0
- data/test/github-backup_test.rb +7 -0
- data/test/test_helper.rb +10 -0
- metadata +76 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 David Dollar
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
= github-backup
|
2
|
+
|
3
|
+
Back up your Github repositories locally.
|
4
|
+
|
5
|
+
To install it as a Gem, just run:
|
6
|
+
|
7
|
+
$ sudo gem install ddollar-github-backup
|
8
|
+
|
9
|
+
To use it:
|
10
|
+
|
11
|
+
$ github-backup /path/to/my/backup/root
|
12
|
+
|
13
|
+
== Authenticated Usage
|
14
|
+
|
15
|
+
=== Seamless authentication using .gitconfig defaults
|
16
|
+
|
17
|
+
You will need a <tt>~/.gitconfig</tt> file in place with a <tt>[github]</tt> section
|
18
|
+
|
19
|
+
See: http://github.com/guides/tell-git-your-user-name-and-email-address
|
20
|
+
|
21
|
+
== Author
|
22
|
+
|
23
|
+
* David Dollar - http://daviddollar.org
|
24
|
+
|
25
|
+
== Copyright
|
26
|
+
|
27
|
+
Copyright (c) 2009 David Dollar. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "github-backup"
|
8
|
+
gem.summary = %Q{Backup your Github repositories}
|
9
|
+
gem.email = "<ddollar@gmail.com>"
|
10
|
+
gem.homepage = "http://github.com/ddollar/github-backup"
|
11
|
+
gem.authors = ["David Dollar"]
|
12
|
+
gem.add_runtime_dependency 'fcoury-octopi', '= 0.1.0'
|
13
|
+
gem.default_executable = 'github-backup'
|
14
|
+
end
|
15
|
+
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'rake/testtask'
|
21
|
+
Rake::TestTask.new(:test) do |test|
|
22
|
+
test.libs << 'lib' << 'test'
|
23
|
+
test.pattern = 'test/**/*_test.rb'
|
24
|
+
test.verbose = true
|
25
|
+
end
|
26
|
+
|
27
|
+
begin
|
28
|
+
require 'rcov/rcovtask'
|
29
|
+
Rcov::RcovTask.new do |test|
|
30
|
+
test.libs << 'test'
|
31
|
+
test.pattern = 'test/**/*_test.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
rescue LoadError
|
35
|
+
task :rcov do
|
36
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
task :default => :test
|
42
|
+
|
43
|
+
require 'rake/rdoctask'
|
44
|
+
Rake::RDocTask.new do |rdoc|
|
45
|
+
if File.exist?('VERSION.yml')
|
46
|
+
config = YAML.load(File.read('VERSION.yml'))
|
47
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
48
|
+
else
|
49
|
+
version = ""
|
50
|
+
end
|
51
|
+
|
52
|
+
rdoc.rdoc_dir = 'rdoc'
|
53
|
+
rdoc.title = "github-backup #{version}"
|
54
|
+
rdoc.rdoc_files.include('README*')
|
55
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
56
|
+
end
|
57
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.2.1
|
data/bin/github-backup
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
|
+
|
5
|
+
require 'octopi'
|
6
|
+
require 'github-backup'
|
7
|
+
|
8
|
+
unless ARGV.length == 1
|
9
|
+
puts "usage: github-backup <local backup root>"
|
10
|
+
exit 1
|
11
|
+
end
|
12
|
+
|
13
|
+
backup = Github::Backup.new(ARGV.first)
|
14
|
+
backup.execute
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{github-backup}
|
5
|
+
s.version = "0.2.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["David Dollar"]
|
9
|
+
s.date = %q{2009-08-10}
|
10
|
+
s.default_executable = %q{github-backup}
|
11
|
+
s.email = %q{<ddollar@gmail.com>}
|
12
|
+
s.executables = ["github-backup"]
|
13
|
+
s.extra_rdoc_files = [
|
14
|
+
"LICENSE",
|
15
|
+
"README.rdoc"
|
16
|
+
]
|
17
|
+
s.files = [
|
18
|
+
".document",
|
19
|
+
".gitignore",
|
20
|
+
"LICENSE",
|
21
|
+
"README.rdoc",
|
22
|
+
"Rakefile",
|
23
|
+
"VERSION",
|
24
|
+
"bin/github-backup",
|
25
|
+
"github-backup.gemspec",
|
26
|
+
"lib/github-backup.rb",
|
27
|
+
"test/github-backup_test.rb",
|
28
|
+
"test/test_helper.rb"
|
29
|
+
]
|
30
|
+
s.homepage = %q{http://github.com/ddollar/github-backup}
|
31
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
32
|
+
s.require_paths = ["lib"]
|
33
|
+
s.rubygems_version = %q{1.3.5}
|
34
|
+
s.summary = %q{Backup your Github repositories}
|
35
|
+
s.test_files = [
|
36
|
+
"test/github-backup_test.rb",
|
37
|
+
"test/test_helper.rb"
|
38
|
+
]
|
39
|
+
|
40
|
+
if s.respond_to? :specification_version then
|
41
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
42
|
+
s.specification_version = 3
|
43
|
+
|
44
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
45
|
+
s.add_runtime_dependency(%q<fcoury-octopi>, ["= 0.1.0"])
|
46
|
+
else
|
47
|
+
s.add_dependency(%q<fcoury-octopi>, ["= 0.1.0"])
|
48
|
+
end
|
49
|
+
else
|
50
|
+
s.add_dependency(%q<fcoury-octopi>, ["= 0.1.0"])
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'octopi'
|
2
|
+
require 'pp'
|
3
|
+
|
4
|
+
module Github; end
|
5
|
+
|
6
|
+
class Github::Backup
|
7
|
+
|
8
|
+
include Octopi
|
9
|
+
|
10
|
+
attr_reader :backup_root, :debug
|
11
|
+
|
12
|
+
def initialize(backup_root)
|
13
|
+
@backup_root = backup_root
|
14
|
+
@debug = false
|
15
|
+
end
|
16
|
+
|
17
|
+
def execute
|
18
|
+
FileUtils::mkdir_p(backup_root)
|
19
|
+
authenticated do |api|
|
20
|
+
repositories = User.find('ddollar').repositories.sort_by { |r| r.name }
|
21
|
+
repositories.each do |repository|
|
22
|
+
puts "Backing up: #{repository.name}"
|
23
|
+
backup_repository repository
|
24
|
+
end
|
25
|
+
end
|
26
|
+
rescue Errno::ENOENT
|
27
|
+
puts "Please install git and create a ~/.gitconfig"
|
28
|
+
puts " See: http://github.com/guides/tell-git-your-user-name-and-email-address"
|
29
|
+
rescue NoMethodError
|
30
|
+
puts "Please add a [github] section to your ~/.gitconfig"
|
31
|
+
puts " See: http://github.com/guides/tell-git-your-user-name-and-email-address"
|
32
|
+
end
|
33
|
+
|
34
|
+
private ######################################################################
|
35
|
+
|
36
|
+
def backup_directory_for(repository)
|
37
|
+
File.join(backup_root, repository.name)
|
38
|
+
end
|
39
|
+
|
40
|
+
def backup_repository(repository)
|
41
|
+
if File.exists?(backup_directory_for(repository))
|
42
|
+
backup_repository_incremental(repository)
|
43
|
+
else
|
44
|
+
backup_repository_initial(repository)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def backup_repository_initial(repository)
|
49
|
+
FileUtils::cd(backup_root) do
|
50
|
+
shell("git clone -n #{repository.clone_url}")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def backup_repository_incremental(repository)
|
55
|
+
FileUtils::cd(backup_directory_for(repository)) do
|
56
|
+
shell("git remote update")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def shell(command)
|
61
|
+
puts "EXECUTING: #{command}" if debug
|
62
|
+
IO.popen(command, 'r') do |io|
|
63
|
+
output = io.read
|
64
|
+
puts "OUTPUT:" if debug
|
65
|
+
puts output if debug
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: github-backup
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Dollar
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-08-10 00:00:00 -04:00
|
13
|
+
default_executable: github-backup
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: fcoury-octopi
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - "="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.1.0
|
24
|
+
version:
|
25
|
+
description:
|
26
|
+
email: <ddollar@gmail.com>
|
27
|
+
executables:
|
28
|
+
- github-backup
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
33
|
+
- README.rdoc
|
34
|
+
files:
|
35
|
+
- .document
|
36
|
+
- .gitignore
|
37
|
+
- LICENSE
|
38
|
+
- README.rdoc
|
39
|
+
- Rakefile
|
40
|
+
- VERSION
|
41
|
+
- bin/github-backup
|
42
|
+
- github-backup.gemspec
|
43
|
+
- lib/github-backup.rb
|
44
|
+
- test/github-backup_test.rb
|
45
|
+
- test/test_helper.rb
|
46
|
+
has_rdoc: true
|
47
|
+
homepage: http://github.com/ddollar/github-backup
|
48
|
+
licenses: []
|
49
|
+
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options:
|
52
|
+
- --charset=UTF-8
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: "0"
|
60
|
+
version:
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: "0"
|
66
|
+
version:
|
67
|
+
requirements: []
|
68
|
+
|
69
|
+
rubyforge_project:
|
70
|
+
rubygems_version: 1.3.5
|
71
|
+
signing_key:
|
72
|
+
specification_version: 3
|
73
|
+
summary: Backup your Github repositories
|
74
|
+
test_files:
|
75
|
+
- test/github-backup_test.rb
|
76
|
+
- test/test_helper.rb
|