bard-backup 0.4.0 → 0.5.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
  SHA256:
3
- metadata.gz: 71a87dace6348cc41462c0192446af581cb9253d218d4c32c0c98667fe26c73a
4
- data.tar.gz: 86eac09b1520f87f7bedd20bff84afd94496416d715947ea49f6047fdc45ed72
3
+ metadata.gz: c646d0f6f82c6bc07b6fdfc94256094e60ec681bde22b295aa7ad7f6766a0a23
4
+ data.tar.gz: 05f47f4952af321ac6a7183ed0643ecf134e9f847b42b3a14a05c0b30399d26f
5
5
  SHA512:
6
- metadata.gz: 40fa5aa6fa1ee989cad053b08a529173376ebb3d18ee38d72024a5bbe5a0fe0cd222698664791490edc799200e77f7df7685eec8d561c995925f597a0121f36b
7
- data.tar.gz: 384b78be14d95ee94dafd9941242818b84b073acc11e6833ace1cd011f95583630aeef27d22428c5a1b9864175989bbe40d292196c1908d884461310f138aa81
6
+ metadata.gz: 8eea608f2e85b5bb968985e57a6ca0a87f127516e6e0638ab0657dc829f68f46c9a467d18e53c9b0fdb128c83aa88b25c6fa814d079777b506e592ce21cf34f2
7
+ data.tar.gz: 7aaac7dad88c8ca3c1f50d7a95157adb5c096a41347accd498c46f08905c3f573cd934f6aa7f3c364250628af3126b0e45fd65ec03dc26b70d0209c82ef04586
@@ -6,24 +6,24 @@ module Bard
6
6
  module Backup
7
7
  class Deleter < Struct.new(:s3_dir, :now)
8
8
  def call
9
- s3_dir.delete keys_to_delete
9
+ s3_dir.delete files_to_delete
10
10
  end
11
11
 
12
- def keys_to_delete
13
- s3_dir.keys.select do |key|
12
+ def files_to_delete
13
+ s3_dir.files.select do |file|
14
14
  [
15
15
  Filter.new(now, 72, :hours),
16
16
  Filter.new(now, 60, :days),
17
17
  Filter.new(now, 52, :weeks),
18
18
  Filter.new(now, 48, :months),
19
19
  Filter.new(now, 100, :years),
20
- ].all? { |filter| !filter.cover?(key) }
20
+ ].all? { |filter| !filter.cover?(file) }
21
21
  end
22
22
  end
23
23
 
24
24
  class Filter < Struct.new(:now, :limit, :unit)
25
- def cover? key
26
- remote = DateTime.parse(key).beginning_of_hour
25
+ def cover? file
26
+ remote = DateTime.parse(file).beginning_of_hour
27
27
  limit.times.any? do |count|
28
28
  remote == ago(count)
29
29
  end
@@ -4,13 +4,15 @@ require "rexml"
4
4
  module Bard
5
5
  module Backup
6
6
  class S3Dir < Data.define(:path, :access_key, :secret_key, :region)
7
- def keys
7
+ def files
8
8
  response = client.list_objects_v2({
9
9
  bucket: bucket_name,
10
10
  prefix: folder_prefix,
11
11
  })
12
12
  raise if response.is_truncated
13
- response.contents.map(&:key)
13
+ response.contents.map do |object|
14
+ object.key.sub("#{folder_prefix}/", "")
15
+ end
14
16
  end
15
17
 
16
18
  def put file_path, body: File.read(file_path)
@@ -35,9 +37,11 @@ module Bard
35
37
  FileUtils.rm file_path
36
38
  end
37
39
 
38
- def delete keys
39
- return if keys.empty?
40
- objects_to_delete = Array(keys).map { |key| { key: key } }
40
+ def delete file_paths
41
+ return if file_paths.empty?
42
+ objects_to_delete = Array(file_paths).map do |file_path|
43
+ { key: [folder_prefix, File.basename(file_path)].compact.join("/") }
44
+ end
41
45
  client.delete_objects({
42
46
  bucket: bucket_name,
43
47
  delete: {
@@ -48,8 +52,8 @@ module Bard
48
52
  end
49
53
 
50
54
  def empty!
51
- keys.each_slice(1000) do |key_batch|
52
- delete key_batch
55
+ files.each_slice(1000) do |batch|
56
+ delete batch
53
57
  end
54
58
  end
55
59
 
@@ -1,6 +1,6 @@
1
1
  module Bard
2
2
  module Backup
3
- VERSION = "0.4.0"
3
+ VERSION = "0.5.0"
4
4
  end
5
5
  end
6
6
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bard-backup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micah Geisel
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-08-15 00:00:00.000000000 Z
11
+ date: 2024-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backhoe