gitti-backup 0.0.1 → 0.4.1

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: 1d7f9258dfc4b2096d4eba9f5ee6d4c5ce959c0f
4
- data.tar.gz: d4d6ae45a22ef15d65bdaaf36c50e48d04b13814
3
+ metadata.gz: 98528e760c07a1b0d66ddd120073ef829bce821a
4
+ data.tar.gz: b9e5e7e4c2cb3d88cac33b00874274623fb34a29
5
5
  SHA512:
6
- metadata.gz: e810a27fcd3ed818223625b4f1f5baf42cb90b19dd37307ef896c435821c0b89b73f0253f74c858548cabb0f4164c682a4fcdcc97ee24ba07eac88238aeff854
7
- data.tar.gz: 857d68067ced2982261bf8408dcadc4c992553223a7771f1446b108690d7d94752cfa42cde2a19d25c5277aeae734e1be7f48c9b7c1f839e9d65182f3c0ffb1d
6
+ metadata.gz: 88be2d1aef4b657bdc49ea048c72cdd5fdaf1fcb39555302d19c7db118550597a64a1e83b8ff88a3d8114d26973f0b5da272e840d8ebc9f1eb379b05fcbdff8d
7
+ data.tar.gz: 2e51ed36028c50f21419bada59e72fed01d7e564a5a42c621073f2e42f128fe2a9fa257849be5253e479d88f73eaa109075aae3c1522d0b4a56b5e9e9f2f8a32
File without changes
@@ -1,6 +1,12 @@
1
- HISTORY.md
1
+ CHANGELOG.md
2
2
  Manifest.txt
3
3
  README.md
4
4
  Rakefile
5
+ bin/backup
5
6
  lib/gitti/backup.rb
7
+ lib/gitti/backup/backup.rb
8
+ lib/gitti/backup/base.rb
6
9
  lib/gitti/backup/version.rb
10
+ test/data/repos.yml
11
+ test/helper.rb
12
+ test/test_backup.rb
data/README.md CHANGED
@@ -2,15 +2,117 @@
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
12
  ## Usage
12
13
 
13
- TBD
14
+ ### `backup` Command Line Tool
15
+
16
+ Use the `backup` command line tool to backup all repos listed in a "manifest" file (e.g. `repos.yml`, `code.yml`, `github.yml` or such). Example:
17
+
18
+ ```
19
+ backup repos.yml # or
20
+ backup code.yml data.yml
21
+ ```
22
+
23
+ In a nutshell backup will backup all repos by using
24
+ 1. `git clone --mirror` or
25
+ 2. `git remote update` (if the local backup already exists)
26
+ and store all bare repos (without workspace) in the `~/backup` directory.
27
+
28
+
29
+ #### Repos Manifest
30
+
31
+ For now only github repos are supported listed by
32
+ owner / organization. Example `repos.yml`:
33
+
34
+ ``` yaml
35
+ sportdb:
36
+ - sport.db
37
+ - sport.db.sources
38
+ - football.db
39
+
40
+ yorobot:
41
+ - cache.csv
42
+ - sport.db.more
43
+ - football.db
44
+ - football.csv
45
+
46
+ openfootball:
47
+ - leagues
48
+ - clubs
49
+ ```
50
+
51
+ Using `backup` with defaults this will result in:
52
+
53
+ ```
54
+ ~/backup
55
+ /sportdb
56
+ /sport.db.git
57
+ /sport.db.sources.git
58
+ /football.db.git
59
+ /yorobot
60
+ /cache.csv.git
61
+ /sport.db.more.git
62
+ /football.db.git
63
+ /football.csv.git
64
+ /openfootball
65
+ /leagues.git
66
+ /clubs.git
67
+ ```
68
+
69
+
70
+
71
+ ### Scripting
72
+
73
+ You can script your backup in ruby. Example:
74
+
75
+
76
+ ``` ruby
77
+ require 'gitti/backup'
78
+
79
+ ## step 1: setup the root backup directory - defaults to ~/backup
80
+ backup = GitBackup.new
81
+
82
+ ## step 2: pass in all repos to backup by using
83
+ ## 1) git clone --mirror or
84
+ ## 2) git remote update (if local backup already exists)
85
+ backup.backup( GitRepoSet.read( './repos.yml' ) )
86
+ ```
87
+
88
+ or
89
+
90
+ ``` ruby
91
+ require 'gitti/backup'
92
+
93
+ ## step 1: setup the root backup directory
94
+ ## 1) use custom directory e.g. /backups
95
+ ## 2) auto-add a daily directory e.g. /backups/2020-09-27
96
+ backup = GitBackup.new( '/backups', daily: true )
97
+
98
+ backup.backup( GitRepoSet.read( './repos.yml' ) )
99
+ ```
100
+
101
+
102
+
103
+ That's all for now.
104
+
105
+
106
+
107
+ ## Installation
108
+
109
+ Use
110
+
111
+ gem install gitti-backup
112
+
113
+ or add to your Gemfile
114
+
115
+ gem 'gitti-backup'
14
116
 
15
117
 
16
118
  ## License
data/Rakefile CHANGED
@@ -3,28 +3,28 @@ require './lib/gitti/backup/version.rb'
3
3
 
4
4
  Hoe.spec 'gitti-backup' do
5
5
 
6
- self.version = Gitti::GitBackup::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
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
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ###################
4
+ # DEV TIPS:
5
+ #
6
+ # For local testing run like:
7
+ #
8
+ # ruby -Ilib bin/backup
9
+ #
10
+ # Set the executable bit in Linux. Example:
11
+ #
12
+ # % chmod a+x bin/backup
13
+ #
14
+
15
+ require 'gitti/backup/base'
16
+
17
+ Gitti::GitBackup::Tool.main
@@ -1,11 +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
-
8
-
9
- # say hello
10
- puts Gitti::GitBackup.banner if defined?($RUBYLIBS_DEBUG)
4
+ ## note: auto include Gitti; for "modular" version use ("Sinatra-style")
5
+ ## require "gitti/backup/base"
11
6
 
7
+ include Gitti
@@ -0,0 +1,110 @@
1
+
2
+ module Gitti
3
+
4
+
5
+ class GitBackup
6
+
7
+ class Tool ## nested class
8
+ def self.main( args=ARGV )
9
+ backup = GitBackup.new
10
+ args.each do |arg|
11
+ backup.backup( GitRepoSet.read( arg ))
12
+ end
13
+ end
14
+ end ## nested class Tool
15
+
16
+
17
+
18
+ def initialize( root= '~/backup', daily: false )
19
+ @root = File.expand_path( root )
20
+ pp @root
21
+
22
+ ## use current working dir for the log path; see do_with_log helper for use
23
+ @log_path = File.expand_path( '.' )
24
+ pp @log_path
25
+
26
+ @daily = daily
27
+ end
28
+
29
+
30
+ ## auto-add "daily" date folder / dir
31
+ ## e.g. 2015-11-20 using Date.today.strftime('%Y-%m-%d')
32
+ def daily=(value) @daily=value; end
33
+
34
+
35
+
36
+ def backup( repos )
37
+ count_orgs = 0
38
+ count_repos = 0
39
+
40
+ total_repos = repos.size
41
+
42
+ ## default to adding folder per day ## e.g. 2015-11-20
43
+ backup_path = "#{@root}"
44
+ backup_path << "/#{Date.today.strftime('%Y-%m-%d')}" if @daily
45
+ pp backup_path
46
+
47
+ FileUtils.mkdir_p( backup_path ) ## make sure path exists
48
+
49
+ repos.each do |org, names|
50
+ org_path = "#{backup_path}/#{org}"
51
+ FileUtils.mkdir_p( org_path ) ## make sure path exists
52
+
53
+ names.each do |name|
54
+ puts "[#{count_repos+1}/#{total_repos}] #{org}@#{name}..."
55
+
56
+ repo = GitHubRepo.new( org, name ) ## owner, name e.g. rubylibs/webservice
57
+
58
+ success = Dir.chdir( org_path ) do
59
+ if Dir.exist?( "#{repo.name}.git" )
60
+ GitMirror.open( "#{repo.name}.git" ) do |mirror|
61
+ do_with_retries { mirror.update } ## note: defaults to two tries
62
+ end
63
+ else
64
+ do_with_retries { Git.mirror( repo.https_clone_url ) }
65
+ end
66
+ end
67
+
68
+ ## todo/check: fail if success still false after x retries? -- why? why not?
69
+
70
+ count_repos += 1
71
+ end
72
+ count_orgs += 1
73
+ end
74
+
75
+ ## print stats
76
+ puts " #{count_repos} repo(s) @ #{count_orgs} org(s)"
77
+ end ## backup
78
+
79
+
80
+ ######
81
+ # private helpers
82
+
83
+ def do_with_log( &blk )
84
+ blk.call
85
+ true ## return true ## success/ok
86
+ rescue GitError => ex
87
+ puts "!! ERROR: #{ex.message}"
88
+
89
+ File.open( "#{@log_path}/errors.log", 'a' ) do |f|
90
+ f.write "#{Time.now} -- #{ex.message}\n"
91
+ end
92
+ false ## return false ## error/nok
93
+ end
94
+
95
+
96
+ def do_with_retries( retries: 2, sleep: 5, &blk )
97
+ retries_count = 0
98
+ success = false
99
+ loop do
100
+ success = do_with_log( &blk )
101
+ retries_count += 1
102
+ break if success || retries_count >= retries
103
+ puts "retrying in #{sleep}secs... sleeping..."
104
+ sleep( sleep ) ## sleep 5secs or such
105
+ end
106
+ success ## return if success or not (true/false)
107
+ end
108
+
109
+ end ## class GitBackup
110
+ 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,10 +1,8 @@
1
- # encoding: utf-8
2
1
 
3
- module Gitti
4
- module GitBackup
2
+ module GittiBackup
5
3
 
6
4
  MAJOR = 0 ## todo: namespace inside version or something - why? why not??
7
- MINOR = 0
5
+ MINOR = 4
8
6
  PATCH = 1
9
7
  VERSION = [MAJOR,MINOR,PATCH].join('.')
10
8
 
@@ -19,7 +17,6 @@ module Gitti
19
17
  def self.root
20
18
  "#{File.expand_path( File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) )}"
21
19
  end
22
-
23
- end # module GitBackup
24
- end # module Gitti
20
+
21
+ end # module GittiBackup
25
22
 
@@ -0,0 +1,16 @@
1
+ ##########################
2
+ # some repos
3
+
4
+ openbeer (2):
5
+ - at-austria
6
+ - be-belgium
7
+
8
+ openfootball (3):
9
+ - austria
10
+ - mexico
11
+ - world-cup
12
+
13
+ openmundi (2):
14
+ - austria.db
15
+ - world.db
16
+
@@ -0,0 +1,10 @@
1
+ ## note: use the local version of gitti gems
2
+ $LOAD_PATH.unshift( File.expand_path( '../gitti/lib' ))
3
+
4
+ ## minitest setup
5
+ require 'minitest/autorun'
6
+
7
+
8
+ ## our own code
9
+ require 'gitti/backup'
10
+
@@ -0,0 +1,30 @@
1
+ ###
2
+ # to run use
3
+ # ruby -I ./lib -I ./test test/test_backup.rb
4
+
5
+
6
+ require 'helper'
7
+
8
+
9
+ class TestBackup < MiniTest::Test
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
18
+
19
+ def test_backup_ii
20
+ repos = GitRepoSet.read( "#{GittiBackup.root}/test/data/repos.yml" )
21
+ pp repos
22
+
23
+ backup = GitBackup.new
24
+ backup.backup( repos )
25
+
26
+ assert true ## assume everything ok if get here
27
+ end
28
+
29
+ end # class TestBackup
30
+
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.0.1
4
+ version: 0.4.1
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-20 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,30 +44,37 @@ 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
- executables: []
57
+ executables:
58
+ - backup
58
59
  extensions: []
59
60
  extra_rdoc_files:
60
- - HISTORY.md
61
+ - CHANGELOG.md
61
62
  - Manifest.txt
62
63
  - README.md
63
64
  files:
64
- - HISTORY.md
65
+ - CHANGELOG.md
65
66
  - Manifest.txt
66
67
  - README.md
67
68
  - Rakefile
69
+ - bin/backup
68
70
  - lib/gitti/backup.rb
71
+ - lib/gitti/backup/backup.rb
72
+ - lib/gitti/backup/base.rb
69
73
  - lib/gitti/backup/version.rb
70
- homepage: https://github.com/rubylibs/gitti
74
+ - test/data/repos.yml
75
+ - test/helper.rb
76
+ - test/test_backup.rb
77
+ homepage: https://github.com/rubycoco/gitti
71
78
  licenses:
72
79
  - Public Domain
73
80
  metadata: {}
@@ -81,7 +88,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
81
88
  requirements:
82
89
  - - ">="
83
90
  - !ruby/object:Gem::Version
84
- version: 1.9.2
91
+ version: 2.2.2
85
92
  required_rubygems_version: !ruby/object:Gem::Requirement
86
93
  requirements:
87
94
  - - ">="
@@ -89,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
96
  version: '0'
90
97
  requirements: []
91
98
  rubyforge_project:
92
- rubygems_version: 2.2.3
99
+ rubygems_version: 2.5.2
93
100
  signing_key:
94
101
  specification_version: 4
95
102
  summary: gitti-backup - (yet) another (lite) git backup command line script