gitti-backup 0.2.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 10cb944dcd9536d4c7b558b2490db1eb0addb9ce
4
- data.tar.gz: 4cb0022b84627722a8891d0adc4a1aa20f9935bc
3
+ metadata.gz: da31fe3c40e34387650d37bac81a8a4c15ce858c
4
+ data.tar.gz: 595414af6e4655bb6dddc552db194794ac31cb72
5
5
  SHA512:
6
- metadata.gz: 3a6b92b4850612350321f78a3def3fd968b1ed33b321e21dd3174d7a295930e8128f3abc80af49a22b2c752da4bfc3af45c76717c462d20f594459dff993cd0a
7
- data.tar.gz: 2e42a28928f778f55e40cef53a7368df2b933035020fc790ea172158484c96889ca922a264f25fac0cc9041c85c8d29b736a408dfdf4d85bb67304ca8599521b
6
+ metadata.gz: 3881867d7f7513f4af361c9a15b96092ce026ed122055d960ef24f3158f777b293dda7a01c1819bf6fee6673060639c29d1720d761ee43ad7a5734d0ba7de312
7
+ data.tar.gz: e4d6a6066aebdc6e12b2ddaeac156583b78bdba87fac097d80fb2875ef7b5c37983d76b8c730f7772530aa07f1e08a85f306b0ee83929c56cdcb0edaecb893a0
File without changes
@@ -1,10 +1,10 @@
1
- HISTORY.md
1
+ CHANGELOG.md
2
2
  Manifest.txt
3
3
  README.md
4
4
  Rakefile
5
5
  lib/gitti/backup.rb
6
6
  lib/gitti/backup/backup.rb
7
- lib/gitti/backup/repo.rb
7
+ lib/gitti/backup/base.rb
8
8
  lib/gitti/backup/version.rb
9
9
  test/data/repos.yml
10
10
  test/helper.rb
data/README.md CHANGED
@@ -2,15 +2,40 @@
2
2
 
3
3
  gitti-backup gem - (yet) another (lite) git backup command line script
4
4
 
5
- * home :: [github.com/rubylibs/gitti](https://github.com/rubylibs/gitti)
6
- * bugs :: [github.com/rubylibs/gitti/issues](https://github.com/rubylibs/gitti/issues)
5
+ * home :: [github.com/rubycoco/gitti](https://github.com/rubycoco/gitti)
6
+ * bugs :: [github.com/rubycoco/gitti/issues](https://github.com/rubycoco/gitti/issues)
7
7
  * gem :: [rubygems.org/gems/gitti-backup](https://rubygems.org/gems/gitti-backup)
8
8
  * rdoc :: [rubydoc.info/gems/gitti-backup](http://rubydoc.info/gems/gitti-backup)
9
9
 
10
10
 
11
11
  ## Usage
12
12
 
13
- TBD
13
+
14
+ ``` ruby
15
+ require 'gitti/backup'
16
+
17
+ ## step 1: setup the root backup directory - defaults to ~/backup
18
+ backup = GitBackup.new
19
+
20
+ ## step 2: pass in all repos to backup by using
21
+ ## 1) git clone --mirror or
22
+ ## 2) git remote update (if local backup already exists)
23
+ backup.backup( GitRepoSet.read( './repos.yml' ) )
24
+ ```
25
+
26
+ That's all for now.
27
+
28
+
29
+
30
+ ## Installation
31
+
32
+ Use
33
+
34
+ gem install gitti-backup
35
+
36
+ or add to your Gemfile
37
+
38
+ gem 'gitti-backup'
14
39
 
15
40
 
16
41
  ## License
data/Rakefile CHANGED
@@ -8,23 +8,23 @@ Hoe.spec 'gitti-backup' do
8
8
  self.summary = 'gitti-backup - (yet) another (lite) git backup command line script'
9
9
  self.description = summary
10
10
 
11
- self.urls = ['https://github.com/rubylibs/gitti']
11
+ self.urls = { home: 'https://github.com/rubycoco/gitti' }
12
12
 
13
13
  self.author = 'Gerald Bauer'
14
14
  self.email = 'ruby-talk@ruby-lang.org'
15
15
 
16
16
  # switch extension to .markdown for gihub formatting
17
17
  self.readme_file = 'README.md'
18
- self.history_file = 'HISTORY.md'
18
+ self.history_file = 'CHANGELOG.md'
19
19
 
20
20
  self.extra_deps = [
21
- ['gitti' ],
21
+ ['gitti', '>= 0.3.0' ],
22
22
  ]
23
23
 
24
24
  self.licenses = ['Public Domain']
25
25
 
26
26
  self.spec_extras = {
27
- required_ruby_version: '>= 1.9.2'
27
+ required_ruby_version: '>= 2.2.2'
28
28
  }
29
29
 
30
30
  end
@@ -1,13 +1,7 @@
1
- # encoding: utf-8
1
+ require_relative 'backup/base'
2
2
 
3
- require 'gitti'
4
3
 
5
- # our own code
6
- require 'gitti/backup/version' # note: let version always go first
7
- require 'gitti/backup/repo'
8
- require 'gitti/backup/backup'
9
-
10
-
11
- # say hello
12
- puts GittiBackup.banner if defined?($RUBYLIBS_DEBUG)
4
+ ## note: auto include Gitti; for "modular" version use ("Sinatra-style")
5
+ ## require "gitti/backup/base"
13
6
 
7
+ include Gitti
@@ -1,53 +1,90 @@
1
- # encoding: utf-8
2
-
3
1
 
4
2
  module Gitti
5
3
 
6
4
 
7
5
  class GitBackup
8
6
 
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??
7
+ def initialize( root= '~/backup' )
8
+ @root = File.expand_path( root )
9
+ pp @root
10
+
11
+ ## use current working dir for the log path; see do_with_log helper for use
12
+ @log_path = File.expand_path( '.' )
13
+ pp @log_path
13
14
  end
14
15
 
16
+
15
17
  def backup( repos )
18
+ count_orgs = 0
19
+ count_repos = 0
20
+
21
+ total_repos = repos.size
22
+
16
23
  ## 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
24
+ backup_path = "#{@root}/#{Date.today.strftime('%Y-%m-%d')}"
25
+ pp backup_path
21
26
 
22
- org_count = 0
23
- repo_count = 0
27
+ FileUtils.mkdir_p( backup_path ) ## make sure path exists
24
28
 
25
- repos.each do |key,values|
26
- dest_dir = "#{backup_dir}/#{key}"
27
- FileUtils.mkdir_p( dest_dir ) ## make sure path exists
29
+ repos.each do |org, names|
30
+ org_path = "#{backup_path}/#{org}"
31
+ FileUtils.mkdir_p( org_path ) ## make sure path exists
28
32
 
29
- values.each_with_index do |value,i|
30
- puts " \##{repo_count+1} [#{i+1}/#{values.size}] #{value}"
33
+ names.each do |name|
34
+ puts "[#{count_repos+1}/#{total_repos}] #{org}@#{name}..."
31
35
 
32
- puts " #{key}/#{value}"
36
+ repo = GitHubRepo.new( org, name ) ## owner, name e.g. rubylibs/webservice
33
37
 
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?
38
+ success = Dir.chdir( org_path ) do
39
+ if Dir.exist?( "#{repo.name}.git" )
40
+ GitMirror.open( "#{repo.name}.git" ) do |mirror|
41
+ do_with_retries { mirror.update } ## note: defaults to two tries
42
+ end
43
+ else
44
+ do_with_retries { Git.mirror( repo.https_clone_url ) }
45
+ end
46
+ end
37
47
 
38
- repo_count += 1
48
+ ## todo/check: fail if success still false after x retries? -- why? why not?
39
49
 
40
- ### exit if repo_count > 2
50
+ count_repos += 1
41
51
  end
42
-
43
- org_count += 1
52
+ count_orgs += 1
44
53
  end
45
-
46
- ## print stats
47
54
 
48
- puts " #{org_count} orgs, #{repo_count} repos"
55
+ ## print stats
56
+ puts " #{count_repos} repo(s) @ #{count_orgs} org(s)"
49
57
  end ## backup
50
58
 
51
- end ## GitBackup
52
59
 
60
+ ######
61
+ # private helpers
62
+
63
+ def do_with_log( &blk )
64
+ blk.call
65
+ true ## return true ## success/ok
66
+ rescue GitError => ex
67
+ puts "!! ERROR: #{ex.message}"
68
+
69
+ File.open( "#{@log_path}/errors.log", 'a' ) do |f|
70
+ f.write "#{Time.now} -- #{ex.message}\n"
71
+ end
72
+ false ## return false ## error/nok
73
+ end
74
+
75
+
76
+ def do_with_retries( retries: 2, sleep: 5, &blk )
77
+ retries_count = 0
78
+ success = false
79
+ loop do
80
+ success = do_with_log( &blk )
81
+ retries_count += 1
82
+ break if success || retries_count >= retries
83
+ puts "retrying in #{sleep}secs... sleeping..."
84
+ sleep( sleep ) ## sleep 5secs or such
85
+ end
86
+ success ## return if success or not (true/false)
87
+ end
88
+
89
+ end ## class GitBackup
53
90
  end ## module Gitti
@@ -0,0 +1,11 @@
1
+ require 'gitti/base' # note: include "modular" base without (auto)include Gitti
2
+
3
+
4
+ # our own code
5
+ require 'gitti/backup/version' # note: let version always go first
6
+ require 'gitti/backup/backup'
7
+
8
+
9
+ # say hello
10
+ puts GittiBackup.banner ## if defined?($RUBYCOCO_DEBUG)
11
+
@@ -1,9 +1,8 @@
1
- # encoding: utf-8
2
1
 
3
2
  module GittiBackup
4
3
 
5
4
  MAJOR = 0 ## todo: namespace inside version or something - why? why not??
6
- MINOR = 2
5
+ MINOR = 4
7
6
  PATCH = 0
8
7
  VERSION = [MAJOR,MINOR,PATCH].join('.')
9
8
 
@@ -18,6 +17,6 @@ module GittiBackup
18
17
  def self.root
19
18
  "#{File.expand_path( File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) )}"
20
19
  end
21
-
20
+
22
21
  end # module GittiBackup
23
22
 
@@ -6,8 +6,8 @@ openbeer (2):
6
6
  - be-belgium
7
7
 
8
8
  openfootball (3):
9
- - at-austria
10
- - br-brazil
9
+ - austria
10
+ - mexico
11
11
  - world-cup
12
12
 
13
13
  openmundi (2):
@@ -1,13 +1,10 @@
1
- # encoding: utf-8
2
-
3
- ## $:.unshift(File.dirname(__FILE__))
1
+ ## note: use the local version of gitti gems
2
+ $LOAD_PATH.unshift( File.expand_path( '../gitti/lib' ))
4
3
 
5
4
  ## minitest setup
6
5
  require 'minitest/autorun'
7
6
 
8
7
 
9
- $RUBYLIBS_DEBUG = true
10
-
11
8
  ## our own code
12
9
  require 'gitti/backup'
13
10
 
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  ###
4
2
  # to run use
5
3
  # ruby -I ./lib -I ./test test/test_backup.rb
@@ -10,17 +8,22 @@ require 'helper'
10
8
 
11
9
  class TestBackup < MiniTest::Test
12
10
 
11
+ def test_backup_i
12
+ repos = GitRepoSet.read( "#{GittiBackup.root}/test/data/repos.yml" )
13
+ pp repos
14
+
15
+ backup = GitBackup.new
16
+ assert true ## assume everything ok if get here
17
+ end
13
18
 
14
- def test_backup
15
-
16
- repos = Gitti::GitRepoSet.from_file( "#{GittiBackup.root}/test/data/repos.yml" )
19
+ def test_backup_ii
20
+ repos = GitRepoSet.read( "#{GittiBackup.root}/test/data/repos.yml" )
17
21
  pp repos
18
-
19
- backup = Gitti::GitBackup.new
22
+
23
+ backup = GitBackup.new
20
24
  backup.backup( repos )
21
-
22
- assert true
23
- ## assume everything ok if get here
25
+
26
+ assert true ## assume everything ok if get here
24
27
  end
25
28
 
26
29
  end # class TestBackup
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitti-backup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-22 00:00:00.000000000 Z
11
+ date: 2020-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gitti
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 0.3.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 0.3.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rdoc
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,35 +44,35 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '3.14'
47
+ version: '3.16'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '3.14'
54
+ version: '3.16'
55
55
  description: gitti-backup - (yet) another (lite) git backup command line script
56
56
  email: ruby-talk@ruby-lang.org
57
57
  executables: []
58
58
  extensions: []
59
59
  extra_rdoc_files:
60
- - HISTORY.md
60
+ - CHANGELOG.md
61
61
  - Manifest.txt
62
62
  - README.md
63
63
  files:
64
- - HISTORY.md
64
+ - CHANGELOG.md
65
65
  - Manifest.txt
66
66
  - README.md
67
67
  - Rakefile
68
68
  - lib/gitti/backup.rb
69
69
  - lib/gitti/backup/backup.rb
70
- - lib/gitti/backup/repo.rb
70
+ - lib/gitti/backup/base.rb
71
71
  - lib/gitti/backup/version.rb
72
72
  - test/data/repos.yml
73
73
  - test/helper.rb
74
74
  - test/test_backup.rb
75
- homepage: https://github.com/rubylibs/gitti
75
+ homepage: https://github.com/rubycoco/gitti
76
76
  licenses:
77
77
  - Public Domain
78
78
  metadata: {}
@@ -86,7 +86,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: 1.9.2
89
+ version: 2.2.2
90
90
  required_rubygems_version: !ruby/object:Gem::Requirement
91
91
  requirements:
92
92
  - - ">="
@@ -94,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
94
  version: '0'
95
95
  requirements: []
96
96
  rubyforge_project:
97
- rubygems_version: 2.2.3
97
+ rubygems_version: 2.5.2
98
98
  signing_key:
99
99
  specification_version: 4
100
100
  summary: gitti-backup - (yet) another (lite) git backup command line script
@@ -1,60 +0,0 @@
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
-