bard-backup 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/bard/backup/controller.rb +3 -6
- data/lib/bard/backup/deleter.rb +41 -0
- data/lib/bard/backup/s3_dir.rb +12 -8
- data/lib/bard/backup/version.rb +1 -1
- data/lib/bard/backup.rb +8 -2
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30f8ca36634a8ee2f414e6aa238a27227d71b9033904b19ff55c649dd8bfe71b
|
4
|
+
data.tar.gz: 2c858195ad3e2e23d84cbce7be7d99ab0000fec2d39f2cd1d409774987067f2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44346cf310237c1d24c60733328dff6ac819ce050a45a183af50b269e61d9ebef420af721e961e612d5fff5d083d53c70dbf8b214b1443d9eee265df6f5b25ba
|
7
|
+
data.tar.gz: 5bcf351a8697340af6e2388b42cf513a7dab8b76da456c0d4ba659dd846e32455eb447148cf77006dd32dd4992a4100ffd6b0f9b7662efe55ac633cf544fd3cf
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Bard::Backup does 3 things in a bard project
|
4
4
|
1. Takes a database dump and uploads it to our s3 bucket
|
5
|
-
2. Deletes old backups using a backoff heuristic:
|
5
|
+
2. Deletes old backups using a backoff heuristic: 72 hours, 60 days, 52 weeks, 48 months, then yearly
|
6
6
|
3. Raises an error if we don't have a backup from the previous hour
|
7
7
|
|
8
8
|
## Installation
|
@@ -1,13 +1,10 @@
|
|
1
|
-
require "backhoe"
|
2
|
-
require "bard/backup/s3_dir"
|
3
|
-
|
4
1
|
module Bard
|
5
2
|
module Backup
|
6
|
-
class Controller < Struct.new(:
|
3
|
+
class Controller < Struct.new(:dumper, :s3_dir, :now)
|
7
4
|
def call
|
5
|
+
filename = "#{now.iso8601}.sql.gz"
|
8
6
|
path = "/tmp/#{filename}"
|
9
|
-
|
10
|
-
s3_dir = S3Dir.new(path: s3_path, access_key:, secret_key:)
|
7
|
+
dumper.dump path
|
11
8
|
s3_dir.put path
|
12
9
|
end
|
13
10
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require "active_support"
|
2
|
+
require "active_support/core_ext/date_time/calculations"
|
3
|
+
require "active_support/core_ext/integer/time"
|
4
|
+
|
5
|
+
module Bard
|
6
|
+
module Backup
|
7
|
+
class Deleter < Struct.new(:s3_dir, :now)
|
8
|
+
def call
|
9
|
+
s3_dir.delete keys_to_delete
|
10
|
+
end
|
11
|
+
|
12
|
+
def keys_to_delete
|
13
|
+
s3_dir.keys.select do |key|
|
14
|
+
[
|
15
|
+
Filter.new(now, 72, :hours),
|
16
|
+
Filter.new(now, 60, :days),
|
17
|
+
Filter.new(now, 52, :weeks),
|
18
|
+
Filter.new(now, 48, :months),
|
19
|
+
Filter.new(now, 100, :years),
|
20
|
+
].all? { |filter| !filter.cover?(key) }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class Filter < Struct.new(:now, :limit, :unit)
|
25
|
+
def cover? key
|
26
|
+
remote = DateTime.parse(key).beginning_of_hour
|
27
|
+
limit.times.any? do |count|
|
28
|
+
remote == ago(count)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def ago count
|
35
|
+
now.send(:"beginning_of_#{unit.to_s.singularize}") - count.send(unit)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
data/lib/bard/backup/s3_dir.rb
CHANGED
@@ -21,16 +21,20 @@ module Bard
|
|
21
21
|
})
|
22
22
|
end
|
23
23
|
|
24
|
+
def delete keys
|
25
|
+
objects_to_delete = Array(keys).map { |key| { key: key } }
|
26
|
+
client.delete_objects({
|
27
|
+
bucket: bucket_name,
|
28
|
+
delete: {
|
29
|
+
objects: objects_to_delete,
|
30
|
+
quiet: true,
|
31
|
+
}
|
32
|
+
})
|
33
|
+
end
|
34
|
+
|
24
35
|
def empty!
|
25
36
|
keys.each_slice(1000) do |key_batch|
|
26
|
-
|
27
|
-
client.delete_objects({
|
28
|
-
bucket: bucket_name,
|
29
|
-
delete: {
|
30
|
-
objects: objects_to_delete,
|
31
|
-
quiet: true,
|
32
|
-
}
|
33
|
-
})
|
37
|
+
delete key_batch
|
34
38
|
end
|
35
39
|
end
|
36
40
|
|
data/lib/bard/backup/version.rb
CHANGED
data/lib/bard/backup.rb
CHANGED
@@ -1,9 +1,15 @@
|
|
1
1
|
require "bard/backup/controller"
|
2
|
+
require "bard/backup/deleter"
|
3
|
+
require "bard/backup/s3_dir"
|
4
|
+
require "backhoe"
|
2
5
|
|
3
6
|
module Bard
|
4
7
|
module Backup
|
5
|
-
def self.call s3_path, access_key:, secret_key:,
|
6
|
-
|
8
|
+
def self.call s3_path, access_key:, secret_key:, now: Time.now.utc
|
9
|
+
dumper = Backhoe
|
10
|
+
s3_dir = S3Dir.new(path: s3_path, access_key:, secret_key:)
|
11
|
+
Controller.new(dumper, s3_dir, now).call
|
12
|
+
Deleter.new(s3_dir, now).call
|
7
13
|
end
|
8
14
|
end
|
9
15
|
end
|
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
|
+
version: 0.3.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-07-
|
11
|
+
date: 2024-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: backhoe
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activesupport
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
description:
|
56
70
|
email:
|
57
71
|
- micah@botandrose.com
|
@@ -68,6 +82,7 @@ files:
|
|
68
82
|
- lib/bard-backup.rb
|
69
83
|
- lib/bard/backup.rb
|
70
84
|
- lib/bard/backup/controller.rb
|
85
|
+
- lib/bard/backup/deleter.rb
|
71
86
|
- lib/bard/backup/s3_dir.rb
|
72
87
|
- lib/bard/backup/version.rb
|
73
88
|
- sig/bard/backup.rbs
|