bibliotech 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/default_configuration/config.yaml +1 -1
- data/lib/bibliotech/backups/prune_list.rb +1 -1
- data/lib/bibliotech/backups/pruner.rb +22 -5
- data/lib/bibliotech/config.rb +1 -1
- data/lib/bibliotech/logger.rb +14 -1
- data/lib/bibliotech/railtie.rb +17 -0
- data/lib/bibliotech/rake_lib.rb +8 -3
- data/lib/bibliotech.rb +1 -0
- data/spec/bibliotech/backup_pruner_spec.rb +5 -4
- data/spec/spec_helper.rb +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29396006a12015a3a5d1e6473d119743e05df2a6
|
4
|
+
data.tar.gz: 8cca90411e64dc5a4bcbf647e7a838be7ad9c4e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf5b1c8544ae1d3ac98a7dd67265a7ed7925b23781aa788958edd64d7c6bc19490cd015094941299f9c68a8b6d8662b7b984785946f1fa98811f0ca0bfe4cfde
|
7
|
+
data.tar.gz: 37607ddddabd0e2fc8c196b4e739d1d026c605d9741b8b8e291d20cf3e0dd3f71dc2d401345d5a8945a4b3d86859209332e4d816e11524c681355af709a1ba8a
|
@@ -45,7 +45,7 @@ module BiblioTech
|
|
45
45
|
parsed_time = Time::utc(*timespec)
|
46
46
|
return FileRecord.new(File::join(path, file), parsed_time)
|
47
47
|
else
|
48
|
-
raise "File prefixed #{prefix} doesn't match #{prefix_timestamp_re.
|
48
|
+
raise "File prefixed #{prefix} doesn't match #{prefix_timestamp_re.inspect}: #{File::join(path, file)}"
|
49
49
|
end
|
50
50
|
else
|
51
51
|
if file !~ TIMESTAMP_REGEX
|
@@ -29,8 +29,23 @@ module BiblioTech
|
|
29
29
|
|
30
30
|
def backup_needed?(time)
|
31
31
|
most_recent = most_recent()
|
32
|
-
|
33
|
-
|
32
|
+
log.info{ "backup_needed?: most_recent is #{most_recent.path rescue "<nil>"}" }
|
33
|
+
if most_recent.nil?
|
34
|
+
log.warn{ "backup_needed?: no backups yet -> YES" }
|
35
|
+
return true
|
36
|
+
end
|
37
|
+
|
38
|
+
difference = time - most_recent.timestamp
|
39
|
+
freq_seconds = frequency * 60
|
40
|
+
if difference >= freq_seconds
|
41
|
+
log.warn{ "backup_needed?: check time: #{time.inspect} most_recent timestamp: #{most_recent.timestamp.inspect}" }
|
42
|
+
log.warn{ "backup_needed?: delta: #{difference} frequency: #{freq_seconds} -> YES" }
|
43
|
+
return true
|
44
|
+
else
|
45
|
+
log.info{ "backup_needed?: check time: #{time.inspect} most_recent timestamp: #{most_recent.timestamp.inspect}" }
|
46
|
+
log.info{ "backup_needed?: delta: #{difference} frequency: #{freq_seconds} -> NO" }
|
47
|
+
return false
|
48
|
+
end
|
34
49
|
end
|
35
50
|
|
36
51
|
def list
|
@@ -59,9 +74,11 @@ module BiblioTech
|
|
59
74
|
log.warn{ "No backup files in #{path} / #{name} !" }
|
60
75
|
end
|
61
76
|
list.each do |record|
|
62
|
-
|
63
|
-
"#{record.path} #{record.timestamp}
|
64
|
-
|
77
|
+
if record.keep
|
78
|
+
log.info{ "#{record.path} #{record.timestamp} kept: #{record.scheduled_by.inspect}" }
|
79
|
+
else
|
80
|
+
log.warn{ "#{record.path} #{record.timestamp} discarding" }
|
81
|
+
end
|
65
82
|
end
|
66
83
|
list.select do |record|
|
67
84
|
!record.keep?
|
data/lib/bibliotech/config.rb
CHANGED
data/lib/bibliotech/logger.rb
CHANGED
@@ -2,8 +2,21 @@ require 'logger'
|
|
2
2
|
|
3
3
|
module BiblioTech
|
4
4
|
module Logging
|
5
|
+
class NullLogger < BasicObject
|
6
|
+
def method_missing(method, *args, &block)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
5
10
|
def self.logger
|
6
|
-
return @logger
|
11
|
+
return (@logger || null_logger)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.null_logger
|
15
|
+
@null_logger ||=
|
16
|
+
begin
|
17
|
+
warn "Logging to a NullLogger (because logger didn't get set up)"
|
18
|
+
NullLogger.new
|
19
|
+
end
|
7
20
|
end
|
8
21
|
|
9
22
|
def self.logger=(value)
|
@@ -0,0 +1,17 @@
|
|
1
|
+
begin
|
2
|
+
require 'rails'
|
3
|
+
raise LoadError unless defined? Rails
|
4
|
+
|
5
|
+
module BiblioTech
|
6
|
+
class Railtie < Rails::Railtie
|
7
|
+
#XXX Consider adding Rails options for bibliotech
|
8
|
+
#Would probably need to be exclusive with config files
|
9
|
+
rake_tasks do
|
10
|
+
require 'bibliotech/rake_lib'
|
11
|
+
|
12
|
+
BiblioTech::Tasklib.new
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
rescue LoadError
|
17
|
+
end
|
data/lib/bibliotech/rake_lib.rb
CHANGED
@@ -23,10 +23,15 @@ module BiblioTech
|
|
23
23
|
configured_state = to_hash
|
24
24
|
configured_state.delete(:app)
|
25
25
|
configured_state.delete(:config_path)
|
26
|
-
|
27
|
-
|
26
|
+
|
27
|
+
case [config_path == app.config_path, configured_state == @default_state]
|
28
28
|
when [true, true]
|
29
|
-
|
29
|
+
when [false, false]
|
30
|
+
raise "Won't both change config path and any other setting (sorry) - put configs in a file"
|
31
|
+
# The rationale here is that it would introduce two conflicting sets of
|
32
|
+
# configs, which would only enhance the level of confusion possible.
|
33
|
+
# XXX by that reasoning, if there are any non-default config files, we
|
34
|
+
# should reject Rakefile configs, but we don't
|
30
35
|
when [true, false]
|
31
36
|
app.config.hash.merge!(configured_state)
|
32
37
|
when [false, true]
|
data/lib/bibliotech.rb
CHANGED
@@ -6,13 +6,14 @@ module BiblioTech
|
|
6
6
|
describe Backups::Pruner do
|
7
7
|
include FileSandbox
|
8
8
|
|
9
|
+
let :app do
|
10
|
+
App.new
|
11
|
+
end
|
12
|
+
|
9
13
|
before :each do
|
10
14
|
sandbox.new :directory => "db_backups"
|
11
15
|
sandbox.new :file => '.bibliotech/config.yaml', :with_contents => "log:\n target: ../tmp/test.log"
|
12
|
-
|
13
|
-
|
14
|
-
let :app do
|
15
|
-
App.new
|
16
|
+
app.log
|
16
17
|
end
|
17
18
|
|
18
19
|
let :schedule do
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bibliotech
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evan Dorn
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2015-02-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: caliph
|
@@ -101,6 +101,7 @@ files:
|
|
101
101
|
- lib/bibliotech/backups/file_record.rb
|
102
102
|
- lib/bibliotech/application.rb
|
103
103
|
- lib/bibliotech/cli.rb
|
104
|
+
- lib/bibliotech/railtie.rb
|
104
105
|
- lib/bibliotech.rb
|
105
106
|
- bin/bibliotech
|
106
107
|
- spec/spec_helper.rb
|
@@ -129,7 +130,7 @@ rdoc_options:
|
|
129
130
|
- --main
|
130
131
|
- doc/README
|
131
132
|
- --title
|
132
|
-
- bibliotech-0.
|
133
|
+
- bibliotech-0.4.0 Documentation
|
133
134
|
require_paths:
|
134
135
|
- lib/
|
135
136
|
required_ruby_version: !ruby/object:Gem::Requirement
|