thin_out_backups 0.0.6 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/bin/thin_out_backups +1 -3
- data/lib/thin_out_backups/version.rb +1 -1
- data/lib/thin_out_backups.rb +18 -16
- data/spec/thin_out_backups_spec.rb +93 -25
- data/thin_out_backups.gemspec +1 -1
- metadata +4 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 44d0bc06671e26f04c1aadea17a36ed97f634a4ee600ca74aa25d46ee37a33c4
|
4
|
+
data.tar.gz: 1ecb7d651527191a1b3698019295413d90b57f5ed19a38be5da5120d7690c65a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 415595c279a2cb7d59b001b0c95838f23fd0075231eb2bac8ea509a6b7ee407232067b39bece0427a950968a0a4de4b9c3dce3198262bbf9a5930122ab412c9a
|
7
|
+
data.tar.gz: 0440b71875c0e58fa27f0feef5fc51716f6d603d55d2da7cf1bc2c7fe444964faec966264c68ecfd85502f780367710861110fee72f3f3815640650c9254e6aa
|
data/bin/thin_out_backups
CHANGED
@@ -13,8 +13,6 @@ Before any other deletes, it should search for/delete duplicates. If --duplicate
|
|
13
13
|
=end
|
14
14
|
|
15
15
|
require 'getoptlong'
|
16
|
-
#require 'rubygems'
|
17
|
-
#require 'facets'
|
18
16
|
require 'thin_out_backups'
|
19
17
|
|
20
18
|
def help
|
@@ -154,7 +152,7 @@ opts.each do | opt, arg |
|
|
154
152
|
ThinOutBackups::Command.force = true
|
155
153
|
|
156
154
|
when '--no-color'
|
157
|
-
|
155
|
+
Rainbow.enabled = false
|
158
156
|
|
159
157
|
when *ThinOutBackups::Command.options.map {|o| "--#{o.to_s.gsub(/_/, '-')}"}
|
160
158
|
name = opt.gsub(/^--/, '').to_sym
|
data/lib/thin_out_backups.rb
CHANGED
@@ -5,13 +5,14 @@ require "thin_out_backups/version"
|
|
5
5
|
require 'fileutils'
|
6
6
|
require 'pathname'
|
7
7
|
require 'delegate'
|
8
|
+
require 'rainbow'
|
8
9
|
|
9
|
-
#require 'rubygems'
|
10
10
|
require 'facets/time'
|
11
|
+
require 'active_support' # Without this, we get error when we try to cherry pick: undefined method `deprecator' for ActiveSupport:Module
|
11
12
|
require 'active_support/time'
|
12
|
-
require 'colored'
|
13
13
|
require 'active_support/core_ext/module/attribute_accessors'
|
14
14
|
|
15
|
+
|
15
16
|
class ThinOutBackups::Command
|
16
17
|
#---------------------------------------------------------------------------------------------------------------------------------------------------
|
17
18
|
|
@@ -20,7 +21,7 @@ class ThinOutBackups::Command
|
|
20
21
|
|
21
22
|
#---------------------------------------------------------------------------------------------------------------------------------------------------
|
22
23
|
# Options
|
23
|
-
@@options = [:get_time_from, :ignore_files ,:verbosity, :time_format, :now, :force
|
24
|
+
@@options = [:get_time_from, :ignore_files ,:verbosity, :time_format, :now, :force]
|
24
25
|
mattr_reader :options
|
25
26
|
mattr_accessor *@@options
|
26
27
|
|
@@ -33,13 +34,12 @@ class ThinOutBackups::Command
|
|
33
34
|
@@ignore_files = nil
|
34
35
|
@@verbosity = 1
|
35
36
|
@@force = false
|
36
|
-
@@color = true
|
37
37
|
|
38
38
|
@@now = Time.now
|
39
39
|
def self.now=(new)
|
40
40
|
time = DateTime.strptime('2008-11-12 07:45:00', '%Y-%m-%d %H:%M:%S').to_time
|
41
41
|
@@now = new
|
42
|
-
puts "Using alternate now: #{@@now}"
|
42
|
+
puts "Using alternate now: #{@@now}" if @@verbosity >= 1
|
43
43
|
end
|
44
44
|
|
45
45
|
@@time_format = /(\d{4})[^\d]?(\d{2})[^\d]?(\d{2})T(\d{2})[^\d]?(\d{2})[^\d]?(\d{2})?/
|
@@ -61,7 +61,7 @@ class ThinOutBackups::Command
|
|
61
61
|
@parent = parent
|
62
62
|
@name = name
|
63
63
|
(
|
64
|
-
raise "Invalid quota '#{quota}'" unless quota.is_a?(
|
64
|
+
raise "Invalid quota '#{quota}'" unless quota.is_a?(Integer) || quota =~ @@quota_format
|
65
65
|
@quota = quota
|
66
66
|
)
|
67
67
|
@keepers = []
|
@@ -117,7 +117,7 @@ class ThinOutBackups::Command
|
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
|
-
def keep_all?; quota =~ /\*/ end
|
120
|
+
def keep_all?; quota.to_s =~ /\*/ end
|
121
121
|
|
122
122
|
def satisfied?
|
123
123
|
if keep_all?
|
@@ -180,7 +180,7 @@ class ThinOutBackups::Command
|
|
180
180
|
@buckets[name] = Bucket.new(self, name, quota) unless quota.nil?
|
181
181
|
end
|
182
182
|
|
183
|
-
puts "Processing #{@dir}/*".magenta
|
183
|
+
puts Rainbow("Processing #{@dir}/*").magenta
|
184
184
|
files = Dir["#{@dir}/*"].map { |filename|
|
185
185
|
file = File.new(filename)
|
186
186
|
}
|
@@ -213,9 +213,9 @@ class ThinOutBackups::Command
|
|
213
213
|
#raise "Didn't find any files to keep?!" unless keepers.any?
|
214
214
|
files_with_times.each do |file|
|
215
215
|
if (buckets = buckets_with_file(file)).any?
|
216
|
-
puts "#{file.full_path}: in buckets: #{buckets.map(&:name).join(', ')}".green
|
216
|
+
puts Rainbow("#{file.full_path}: in buckets: #{buckets.map(&:name).join(', ')}").green
|
217
217
|
else
|
218
|
-
puts "#{file.full_path}: delete".red
|
218
|
+
puts Rainbow("#{file.full_path}: delete").red
|
219
219
|
end
|
220
220
|
end
|
221
221
|
|
@@ -252,31 +252,33 @@ class ThinOutBackups::Command
|
|
252
252
|
|
253
253
|
# Fill each bucket until its quota is met
|
254
254
|
buckets.each do |bucket|
|
255
|
-
puts "Trying to fill bucket '#{bucket.name}' (quota: #{bucket.quota})...".magenta
|
255
|
+
puts Rainbow("Trying to fill bucket '#{bucket.name}' (quota: #{bucket.quota})...").magenta if verbosity >= 1
|
256
256
|
|
257
257
|
time_max = bucket.start_time
|
258
258
|
time_min = time_max.shift(-1, bucket.unit)
|
259
259
|
|
260
260
|
#puts "Earliest_file_time: #{earliest_file_time}"
|
261
261
|
while time_max > earliest_file_time
|
262
|
-
print "Checking range (#{time_min} .. #{time_max})... ".yellow if verbosity >= 1
|
263
262
|
new_keeper = files_with_times.detect {|file|
|
264
263
|
#print "#{file}? "
|
265
264
|
time_min <= file.time &&
|
266
265
|
file.time < time_max
|
267
266
|
}
|
267
|
+
if verbosity >= 2 || (verbosity >= 1 && new_keeper)
|
268
|
+
print Rainbow("Checking range (#{time_min} .. #{time_max})... ").yellow
|
269
|
+
end
|
268
270
|
if new_keeper
|
269
|
-
puts "found keeper #{new_keeper}".green if verbosity >= 1
|
271
|
+
puts Rainbow("found keeper #{new_keeper}").green if verbosity >= 1
|
270
272
|
bucket.keep new_keeper
|
271
273
|
else
|
272
|
-
#puts "found no keepers".red if verbosity >= 1
|
273
|
-
puts "" if verbosity >=
|
274
|
+
#puts Rainbow("found no keepers").red if verbosity >= 1
|
275
|
+
puts "" if verbosity >= 2
|
274
276
|
end
|
275
277
|
|
276
278
|
time_max = time_min
|
277
279
|
#puts "Stepping back from #{time_min} by 1 #{bucket.unit} => #{time_min.shift(-1, bucket.unit)}"
|
278
280
|
time_min = time_min.shift(-1, bucket.unit)
|
279
|
-
(puts 'Filled quota!'.green; break) if bucket.satisfied?
|
281
|
+
(puts Rainbow('Filled quota!').green; break) if bucket.satisfied?
|
280
282
|
end
|
281
283
|
end
|
282
284
|
|
@@ -1,21 +1,19 @@
|
|
1
1
|
require 'tmpdir'
|
2
|
-
#require 'rubygems'
|
3
2
|
require 'rspec'
|
4
|
-
require 'facets'
|
5
3
|
require_relative '../lib/thin_out_backups'
|
6
4
|
|
7
5
|
$now = Time.utc(2008,11,12, 7,45,19)
|
8
6
|
|
9
7
|
describe '.time_format' do
|
10
8
|
subject { ThinOutBackups::Command.time_format }
|
11
|
-
it { 'db_dump_20080808T0303.sql'.
|
12
|
-
it { 'db_dump_2008-08-08T0303.sql'.
|
13
|
-
it { 'db_backup.2016-04-28T01:04.sql.gz'.
|
9
|
+
it { expect('db_dump_20080808T0303.sql').to match subject }
|
10
|
+
it { expect('db_dump_2008-08-08T0303.sql').to match subject }
|
11
|
+
it { expect('db_backup.2016-04-28T01:04.sql.gz').to match subject }
|
14
12
|
end
|
15
13
|
|
16
14
|
describe Time, "#beginning_of_week(:sunday)" do
|
17
15
|
it "should return a Sunday" do
|
18
|
-
Time.utc(2008,11,12).beginning_of_week(:sunday).
|
16
|
+
expect(Time.utc(2008,11,12).beginning_of_week(:sunday)).to eq(Time.utc(2008,11,9))
|
19
17
|
end
|
20
18
|
end
|
21
19
|
|
@@ -35,27 +33,28 @@ describe ThinOutBackups::Command::Bucket, "time interval alignment" do
|
|
35
33
|
before do
|
36
34
|
@command = ThinOutBackups::Command.new('bogus_dir', sample_quotas)
|
37
35
|
@now = $now
|
38
|
-
@command.
|
36
|
+
allow(@command).to receive(:now).and_return(@now)
|
39
37
|
end
|
40
38
|
|
41
39
|
it "should use the time specified by our test" do
|
42
|
-
@command.now.
|
40
|
+
expect(@command.now).to eq(@now)
|
43
41
|
end
|
44
42
|
|
45
43
|
it "hour interval should start on the hour, etc." do
|
46
|
-
@command.bucket(:minutely).start_time.
|
47
|
-
@command.bucket(:hourly). start_time.
|
48
|
-
@command.bucket(:daily). start_time.
|
49
|
-
@command.bucket(:weekly). start_time.
|
50
|
-
@command.bucket(:monthly). start_time.
|
51
|
-
@command.bucket(:yearly). start_time.
|
44
|
+
expect(@command.bucket(:minutely).start_time).to eq(Time.utc(2008,11,12, 7,46,0))
|
45
|
+
expect(@command.bucket(:hourly). start_time).to eq(Time.utc(2008,11,12, 8,0,0))
|
46
|
+
expect(@command.bucket(:daily). start_time).to eq(Time.utc(2008,11,13, 0,0,0))
|
47
|
+
expect(@command.bucket(:weekly). start_time).to eq(Time.utc(2008,11,16, 0,0,0))
|
48
|
+
expect(@command.bucket(:monthly). start_time).to eq(Time.utc(2008,12, 1, 0,0,0))
|
49
|
+
expect(@command.bucket(:yearly). start_time).to eq(Time.utc(2009, 1, 1, 0,0,0))
|
52
50
|
end
|
53
51
|
|
54
52
|
end
|
55
53
|
|
56
54
|
|
57
55
|
$command = <<End
|
58
|
-
thin_out_backups --force --daily=3 --weekly=3 --monthly=* \
|
56
|
+
ruby -Ilib bin/thin_out_backups --force --daily=3 --weekly=3 --monthly=* \
|
57
|
+
--no-color \
|
59
58
|
--now='#{$now.strftime("%Y-%m-%d %H:%M:%S")}'\
|
60
59
|
spec/test_dir/db_dumps \
|
61
60
|
spec/test_dir/maildir
|
@@ -120,21 +119,90 @@ describe ThinOutBackups::Command, "when calling `#{$command}`" do
|
|
120
119
|
system "touch #{dir}/#{subdir}/some_other_folder"
|
121
120
|
end
|
122
121
|
|
123
|
-
|
124
|
-
|
125
|
-
# TODO: also check output against expected
|
122
|
+
@output = `#{$command}`
|
123
|
+
expect($?.success?).to eq true
|
126
124
|
end
|
127
125
|
|
128
|
-
it
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
126
|
+
it do
|
127
|
+
#puts @output
|
128
|
+
|
129
|
+
expect(@output).to eq <<~End
|
130
|
+
Using alternate now: 2008-11-12 07:45:19
|
131
|
+
Processing spec/test_dir/db_dumps/*
|
132
|
+
Trying to fill bucket 'daily' (quota: 3)...
|
133
|
+
Checking range (2008-11-12 00:00:00 -0800 .. 2008-11-13 00:00:00 -0800)... found keeper db_dump_2008-11-12T0303.sql
|
134
|
+
Checking range (2008-11-11 00:00:00 -0800 .. 2008-11-12 00:00:00 -0800)... found keeper db_dump_2008-11-11T0303.sql
|
135
|
+
Checking range (2008-11-10 00:00:00 -0800 .. 2008-11-11 00:00:00 -0800)... found keeper db_dump_2008-11-10T0303.sql
|
136
|
+
Filled quota!
|
137
|
+
Trying to fill bucket 'weekly' (quota: 3)...
|
138
|
+
Checking range (2008-11-09 00:00:00 -0800 .. 2008-11-16 00:00:00 -0800)... found keeper db_dump_2008-11-12T0303.sql
|
139
|
+
Checking range (2008-11-02 00:00:00 -0700 .. 2008-11-09 00:00:00 -0800)... found keeper db_dump_2008-11-08T0303.sql
|
140
|
+
Checking range (2008-10-26 00:00:00 -0700 .. 2008-11-02 00:00:00 -0700)... found keeper db_dump_2008-11-01T0303.sql
|
141
|
+
Filled quota!
|
142
|
+
Trying to fill bucket 'monthly' (quota: *)...
|
143
|
+
Checking range (2008-11-01 23:00:00 -0700 .. 2008-12-02 00:00:00 -0800)... found keeper db_dump_2008-11-12T0303.sql
|
144
|
+
Checking range (2008-10-01 23:00:00 -0700 .. 2008-11-01 23:00:00 -0700)... found keeper db_dump_2008-11-01T0303.sql
|
145
|
+
Checking range (2008-09-01 23:00:00 -0700 .. 2008-10-01 23:00:00 -0700)... found keeper db_dump_2008-09-10T0303.sql
|
146
|
+
Checking range (2008-08-01 23:00:00 -0700 .. 2008-09-01 23:00:00 -0700)... found keeper db_dump_2008-09-01T0303.sql
|
147
|
+
spec/test_dir/db_dumps/db_dump_2008-11-12T0303.sql: in buckets: daily, weekly, monthly
|
148
|
+
spec/test_dir/db_dumps/db_dump_2008-11-11T0303.sql: in buckets: daily
|
149
|
+
spec/test_dir/db_dumps/db_dump_2008-11-10T0303.sql: in buckets: daily
|
150
|
+
spec/test_dir/db_dumps/db_dump_2008-11-09T0303.sql: delete
|
151
|
+
spec/test_dir/db_dumps/db_dump_2008-11-08T0303.sql: in buckets: weekly
|
152
|
+
spec/test_dir/db_dumps/db_dump_2008-11-07T0303.sql: delete
|
153
|
+
spec/test_dir/db_dumps/db_dump_2008-11-06T0303.sql: delete
|
154
|
+
spec/test_dir/db_dumps/db_dump_2008-11-05T0303.sql: delete
|
155
|
+
spec/test_dir/db_dumps/db_dump_2008-11-04T0303.sql: delete
|
156
|
+
spec/test_dir/db_dumps/db_dump_2008-11-03T0303.sql: delete
|
157
|
+
spec/test_dir/db_dumps/db_dump_2008-11-02T0303.sql: delete
|
158
|
+
spec/test_dir/db_dumps/db_dump_2008-11-01T0303.sql: in buckets: weekly, monthly
|
159
|
+
spec/test_dir/db_dumps/db_dump_2008-10-31T0303.sql: delete
|
160
|
+
spec/test_dir/db_dumps/db_dump_2008-10-30T0303.sql: delete
|
161
|
+
spec/test_dir/db_dumps/db_dump_2008-10-29T0303.sql: delete
|
162
|
+
spec/test_dir/db_dumps/db_dump_2008-10-28T0303.sql: delete
|
163
|
+
spec/test_dir/db_dumps/db_dump_2008-10-27T0303.sql: delete
|
164
|
+
spec/test_dir/db_dumps/db_dump_2008-10-26T0303.sql: delete
|
165
|
+
spec/test_dir/db_dumps/db_dump_2008-10-25T0303.sql: delete
|
166
|
+
spec/test_dir/db_dumps/db_dump_2008-10-24T0303.sql: delete
|
167
|
+
spec/test_dir/db_dumps/db_dump_2008-10-23T0303.sql: delete
|
168
|
+
spec/test_dir/db_dumps/db_dump_2008-10-22T0303.sql: delete
|
169
|
+
spec/test_dir/db_dumps/db_dump_2008-10-21T0303.sql: delete
|
170
|
+
spec/test_dir/db_dumps/db_dump_2008-10-20T0303.sql: delete
|
171
|
+
spec/test_dir/db_dumps/db_dump_2008-10-19T0303.sql: delete
|
172
|
+
spec/test_dir/db_dumps/db_dump_2008-10-18T0303.sql: delete
|
173
|
+
spec/test_dir/db_dumps/db_dump_2008-10-17T0303.sql: delete
|
174
|
+
spec/test_dir/db_dumps/db_dump_2008-10-16T0303.sql: delete
|
175
|
+
spec/test_dir/db_dumps/db_dump_2008-10-15T0303.sql: delete
|
176
|
+
spec/test_dir/db_dumps/db_dump_2008-09-10T0303.sql: in buckets: monthly
|
177
|
+
spec/test_dir/db_dumps/db_dump_2008-09-01T0303.sql: in buckets: monthly
|
178
|
+
spec/test_dir/db_dumps/db_dump_2008-08-08T0303.sql: delete
|
179
|
+
Processing spec/test_dir/maildir/*
|
180
|
+
Trying to fill bucket 'daily' (quota: 3)...
|
181
|
+
Checking range (2008-11-11 00:00:00 -0800 .. 2008-11-12 00:00:00 -0800)... found keeper 2008-11-11T0303
|
182
|
+
Checking range (2008-11-10 00:00:00 -0800 .. 2008-11-11 00:00:00 -0800)... found keeper 2008-11-10T0303
|
183
|
+
Checking range (2008-11-09 00:00:00 -0800 .. 2008-11-10 00:00:00 -0800)... found keeper 2008-11-09T0303
|
184
|
+
Filled quota!
|
185
|
+
Trying to fill bucket 'weekly' (quota: 3)...
|
186
|
+
Checking range (2008-11-09 00:00:00 -0800 .. 2008-11-16 00:00:00 -0800)... found keeper 2008-11-11T0303
|
187
|
+
Trying to fill bucket 'monthly' (quota: *)...
|
188
|
+
Checking range (2008-11-01 23:00:00 -0700 .. 2008-12-02 00:00:00 -0800)... found keeper 2008-11-11T0303
|
189
|
+
spec/test_dir/maildir/2008-11-11T0303: in buckets: daily, weekly, monthly
|
190
|
+
spec/test_dir/maildir/2008-11-10T0303: in buckets: daily
|
191
|
+
spec/test_dir/maildir/2008-11-09T0303: in buckets: daily
|
192
|
+
End
|
193
|
+
|
194
|
+
# It keeps/removes the correct files
|
195
|
+
expect(Dir['spec/test_dir/db_dumps/*']).to match_array(
|
134
196
|
"spec/test_dir/db_dumps/db_dump_2008-08-08T0303.sql",
|
135
|
-
"spec/test_dir/db_dumps/db_dump_2008-
|
197
|
+
"spec/test_dir/db_dumps/db_dump_2008-09-01T0303.sql",
|
136
198
|
"spec/test_dir/db_dumps/db_dump_2008-09-10T0303.sql",
|
199
|
+
"spec/test_dir/db_dumps/db_dump_2008-10-31T0303.sql",
|
200
|
+
"spec/test_dir/db_dumps/db_dump_2008-11-01T0303.sql",
|
201
|
+
"spec/test_dir/db_dumps/db_dump_2008-11-08T0303.sql",
|
202
|
+
"spec/test_dir/db_dumps/db_dump_2008-11-10T0303.sql",
|
137
203
|
"spec/test_dir/db_dumps/db_dump_2008-11-11T0303.sql"]
|
204
|
+
["spec/test_dir/db_dumps/db_dump_2008-11-12T0303.sql",
|
205
|
+
)
|
138
206
|
end
|
139
207
|
|
140
208
|
after do
|
data/thin_out_backups.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thin_out_backups
|
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
|
- Tyler Rick
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: facets
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: rainbow
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
@@ -104,12 +104,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
104
|
- !ruby/object:Gem::Version
|
105
105
|
version: '0'
|
106
106
|
requirements: []
|
107
|
-
|
108
|
-
rubygems_version: 2.4.6
|
107
|
+
rubygems_version: 3.5.1
|
109
108
|
signing_key:
|
110
109
|
specification_version: 4
|
111
110
|
summary: Thin out a directory full of backups, only keeping a specified number from
|
112
111
|
each category (weekly, daily, etc.), and deleting the rest.
|
113
112
|
test_files:
|
114
113
|
- spec/thin_out_backups_spec.rb
|
115
|
-
has_rdoc:
|