gitti-backup 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Manifest.txt +3 -0
- data/Rakefile +1 -1
- data/lib/gitti/backup.rb +4 -1
- data/lib/gitti/backup/backup.rb +52 -0
- data/lib/gitti/backup/repo.rb +60 -0
- data/lib/gitti/backup/reposet.rb +36 -0
- data/lib/gitti/backup/version.rb +4 -6
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a438558dd2333adfe3211959e6b62a9a1bb65458
|
4
|
+
data.tar.gz: 57e3aa5153a0d087adaef5f4b170b49acfd7c00b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ea1bb3df6a888a1685943f1d0f029b6a4e88a1fce7e488101ca22aa0466d84f51270f11025df19a309c48c805356a64ef85f48174e4950c6ddd10ec6ce05b19
|
7
|
+
data.tar.gz: 7c73898fbc3ec21cbbf54fa971d1a960f1c04396a4409c7dd7bee781bb16ef68352e7603addb5ce8ccdf4109220469ceccb3f56c27c74288528987246a3eb5e8
|
data/Manifest.txt
CHANGED
data/Rakefile
CHANGED
@@ -3,7 +3,7 @@ require './lib/gitti/backup/version.rb'
|
|
3
3
|
|
4
4
|
Hoe.spec 'gitti-backup' do
|
5
5
|
|
6
|
-
self.version =
|
6
|
+
self.version = GittiBackup::VERSION
|
7
7
|
|
8
8
|
self.summary = 'gitti-backup - (yet) another (lite) git backup command line script'
|
9
9
|
self.description = summary
|
data/lib/gitti/backup.rb
CHANGED
@@ -4,8 +4,11 @@ require 'gitti'
|
|
4
4
|
|
5
5
|
# our own code
|
6
6
|
require 'gitti/backup/version' # note: let version always go first
|
7
|
+
require 'gitti/backup/repo'
|
8
|
+
require 'gitti/backup/reposet' ## todo: move to gitti-support (commons) gem ??
|
9
|
+
require 'gitti/backup/backup'
|
7
10
|
|
8
11
|
|
9
12
|
# say hello
|
10
|
-
puts
|
13
|
+
puts GittiBackup.banner if defined?($RUBYLIBS_DEBUG)
|
11
14
|
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
|
4
|
+
module Gitti
|
5
|
+
|
6
|
+
|
7
|
+
class GitBackup
|
8
|
+
|
9
|
+
def initialize( backup_dir = '~/backup' )
|
10
|
+
@backup_dir = File.expand_path( backup_dir )
|
11
|
+
pp @backup_dir
|
12
|
+
## use/renmae to backup_root - why? why not??
|
13
|
+
end
|
14
|
+
|
15
|
+
def backup( repos )
|
16
|
+
## default to adding folder per day ## e.g. 2015-11-20
|
17
|
+
backup_dir = "#{@backup_dir}/#{Date.today.strftime('%Y-%m-%d')}"
|
18
|
+
pp backup_dir
|
19
|
+
|
20
|
+
FileUtils.mkdir_p( backup_dir ) ## make sure path exists
|
21
|
+
|
22
|
+
org_count = 0
|
23
|
+
repo_count = 0
|
24
|
+
|
25
|
+
repos.each do |key,values|
|
26
|
+
dest_dir = "#{backup_dir}/#{key}"
|
27
|
+
FileUtils.mkdir_p( dest_dir ) ## make sure path exists
|
28
|
+
|
29
|
+
values.each_with_index do |value,i|
|
30
|
+
puts " \##{repo_count+1} [#{i+1}/#{values.size}] #{value}"
|
31
|
+
|
32
|
+
puts " #{key}/#{value}"
|
33
|
+
|
34
|
+
repo = GitHubBareRepo.new( key, value ) ## owner, name e.g. rubylibs/webservice
|
35
|
+
success = repo.backup_with_retries( dest_dir ) ## note: defaults to two tries
|
36
|
+
## todo/check: fail if success still false after x retries? -- why? why not?
|
37
|
+
|
38
|
+
repo_count += 1
|
39
|
+
|
40
|
+
### exit if repo_count > 2
|
41
|
+
end
|
42
|
+
|
43
|
+
org_count += 1
|
44
|
+
end
|
45
|
+
|
46
|
+
## print stats
|
47
|
+
|
48
|
+
puts " #{org_count} orgs, #{repo_count} repos"
|
49
|
+
end ## backup
|
50
|
+
|
51
|
+
end ## GitBackup
|
52
|
+
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Gitti
|
4
|
+
|
5
|
+
|
6
|
+
class GitHubBareRepo ## use/rename to GitHubServerRepo - why? why not?
|
7
|
+
def initialize( owner, name )
|
8
|
+
@owner = owner ## use/rename to login or something - why? why not??
|
9
|
+
@name = name # e.g. "rubylibs/webservice"
|
10
|
+
end
|
11
|
+
|
12
|
+
def http_clone_url ## use clone_url( http: true ) -- why? why not?
|
13
|
+
## check: use https: as default? for github - http:// still supported? or redirected?
|
14
|
+
"http://github.com/#{@owner}/#{@name}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def git_dir
|
18
|
+
## todo: rename to use bare_git_dir or mirror_dir or something ??
|
19
|
+
"#{@name}.git"
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
def backup_with_retries( dest_dir, retries: 2 )
|
24
|
+
retries_count = 0
|
25
|
+
success = false
|
26
|
+
begin
|
27
|
+
success = backup( dest_dir )
|
28
|
+
retries_count += 1
|
29
|
+
end until success || retries_count >= retries
|
30
|
+
success ## return if success or not (true/false)
|
31
|
+
end
|
32
|
+
|
33
|
+
def backup( dest_dir )
|
34
|
+
###
|
35
|
+
## use --mirror
|
36
|
+
## use -n (--no-checkout) -- needed - why? why not?
|
37
|
+
|
38
|
+
Dir.chdir( dest_dir ) do
|
39
|
+
if Dir.exist?( git_dir )
|
40
|
+
Dir.chdir( git_dir ) do
|
41
|
+
Git.remote_update
|
42
|
+
end
|
43
|
+
else
|
44
|
+
Git.mirror( http_clone_url )
|
45
|
+
end
|
46
|
+
end
|
47
|
+
true ## return true ## success/ok
|
48
|
+
rescue GitError => ex
|
49
|
+
puts "*** error: #{ex.message}"
|
50
|
+
|
51
|
+
File.open( './errors.log', 'a' ) do |f|
|
52
|
+
f.write "#{Time.now} -- repo #{@owner}/#{@name} - #{ex.message}\n"
|
53
|
+
end
|
54
|
+
false ## return false ## error/nok
|
55
|
+
end ## method backup
|
56
|
+
|
57
|
+
end ## class Repo
|
58
|
+
|
59
|
+
end ## module Gitti
|
60
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Gitti
|
4
|
+
|
5
|
+
class GitRepoSet ## todo: rename to Hash/Dict/List/Map ??
|
6
|
+
|
7
|
+
def self.from_file( path )
|
8
|
+
hash = YAML.load_file( path )
|
9
|
+
self.new( hash )
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
def initialize( hash )
|
14
|
+
@hash = hash
|
15
|
+
end
|
16
|
+
|
17
|
+
def each
|
18
|
+
@hash.each do |key_with_counter,values|
|
19
|
+
|
20
|
+
## remove optional number from key e.g.
|
21
|
+
## mrhydescripts (3) => mrhydescripts
|
22
|
+
## footballjs (4) => footballjs
|
23
|
+
## etc.
|
24
|
+
|
25
|
+
key = key_with_counter.sub( /\s+\([0-9]+\)/, '' )
|
26
|
+
|
27
|
+
puts " -- #{key_with_counter} [#{key}] --"
|
28
|
+
|
29
|
+
yield( key, values )
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end ## class GitRepoSet
|
34
|
+
|
35
|
+
end ## module Gitti
|
36
|
+
|
data/lib/gitti/backup/version.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
module
|
4
|
-
module GitBackup
|
3
|
+
module GittiBackup
|
5
4
|
|
6
5
|
MAJOR = 0 ## todo: namespace inside version or something - why? why not??
|
7
|
-
MINOR =
|
8
|
-
PATCH =
|
6
|
+
MINOR = 1
|
7
|
+
PATCH = 0
|
9
8
|
VERSION = [MAJOR,MINOR,PATCH].join('.')
|
10
9
|
|
11
10
|
def self.version
|
@@ -20,6 +19,5 @@ module Gitti
|
|
20
19
|
"#{File.expand_path( File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) )}"
|
21
20
|
end
|
22
21
|
|
23
|
-
end
|
24
|
-
end # module Gitti
|
22
|
+
end # module GittiBackup
|
25
23
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gitti-backup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
@@ -66,6 +66,9 @@ files:
|
|
66
66
|
- README.md
|
67
67
|
- Rakefile
|
68
68
|
- lib/gitti/backup.rb
|
69
|
+
- lib/gitti/backup/backup.rb
|
70
|
+
- lib/gitti/backup/repo.rb
|
71
|
+
- lib/gitti/backup/reposet.rb
|
69
72
|
- lib/gitti/backup/version.rb
|
70
73
|
homepage: https://github.com/rubylibs/gitti
|
71
74
|
licenses:
|