bard-backup 0.7.0 → 0.8.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 +4 -4
- data/README.md +2 -2
- data/lib/bard/backup/cached_local_backhoe.rb +27 -0
- data/lib/bard/backup/deleter.rb +1 -1
- data/lib/bard/backup/local_backhoe.rb +1 -1
- data/lib/bard/backup/s3_dir.rb +6 -2
- data/lib/bard/backup/version.rb +2 -2
- data/lib/bard/backup.rb +52 -7
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5727d5acc23ec75d951a70f062b7bf4da0bbc3ab010c3d96de502530f063497e
|
4
|
+
data.tar.gz: d3d07429a57b4e2ea090216ae954e7e682f5f18c9ddeb44f93446af3b871dd53
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6ccbdd2cef3c31c43165bdb4a206b95d5648aaff3722a71e2e7bb644170367b5b74639155e564ee379d0e70066fa9e5ccbf4fdddaf6185331bc2ce7334f6a51
|
7
|
+
data.tar.gz: 9b0a36b4784e890b8c2c77a0e60f8c24ebf5ebd8515739bd9ad678c7237ba7d317bdd51a17847473f7519537664521a7b2165e426990290bfb93c29af18623b1
|
data/README.md
CHANGED
@@ -2,14 +2,14 @@
|
|
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: 48 hours, 30 days, 26 weeks, 24 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
|
9
9
|
|
10
10
|
## Usage
|
11
11
|
|
12
|
-
Run with `Bard::Backup.call
|
12
|
+
Run with `Bard::Backup.call path: "s3_bucket/optional_subfolder", access_key: "...", secret_key: "...", region: "..."`
|
13
13
|
|
14
14
|
Or just run via the `bard-rake` gem: `rake db:backup`, which wires up the above for you.
|
15
15
|
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "backhoe"
|
2
|
+
|
3
|
+
module Bard
|
4
|
+
class Backup
|
5
|
+
class CachedLocalBackhoe < Struct.new(:s3_dir, :now)
|
6
|
+
def self.call *args
|
7
|
+
new(*args).call
|
8
|
+
end
|
9
|
+
|
10
|
+
def call
|
11
|
+
s3_dir.put path
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def path
|
17
|
+
@@path ||= begin
|
18
|
+
filename = "#{now.iso8601}.sql.gz"
|
19
|
+
path = "/tmp/#{filename}"
|
20
|
+
Backhoe.dump path
|
21
|
+
at_exit { FileUtils.rm_f path }
|
22
|
+
path
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/bard/backup/deleter.rb
CHANGED
data/lib/bard/backup/s3_dir.rb
CHANGED
@@ -2,8 +2,13 @@ require "aws-sdk-s3"
|
|
2
2
|
require "rexml"
|
3
3
|
|
4
4
|
module Bard
|
5
|
-
|
5
|
+
class Backup
|
6
6
|
class S3Dir < Data.define(:endpoint, :path, :access_key, :secret_key, :region)
|
7
|
+
def initialize **kwargs
|
8
|
+
kwargs[:endpoint] ||= "https://s3.#{kwargs[:region]}.amazonaws.com"
|
9
|
+
super
|
10
|
+
end
|
11
|
+
|
7
12
|
def files
|
8
13
|
response = client.list_objects_v2({
|
9
14
|
bucket: bucket_name,
|
@@ -79,4 +84,3 @@ module Bard
|
|
79
84
|
end
|
80
85
|
end
|
81
86
|
end
|
82
|
-
|
data/lib/bard/backup/version.rb
CHANGED
data/lib/bard/backup.rb
CHANGED
@@ -1,17 +1,62 @@
|
|
1
1
|
require "bard/backup/s3_dir"
|
2
2
|
require "bard/backup/local_backhoe"
|
3
|
+
require "bard/backup/cached_local_backhoe"
|
3
4
|
require "bard/backup/deleter"
|
4
5
|
|
5
6
|
module Bard
|
6
|
-
|
7
|
-
def self.call
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
class Backup
|
8
|
+
def self.call configs
|
9
|
+
configs = [configs] if configs.is_a?(Hash)
|
10
|
+
configs.each do |config|
|
11
|
+
new(config).call
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize config
|
16
|
+
@config = config
|
17
|
+
end
|
18
|
+
attr_reader :config
|
19
|
+
|
20
|
+
def call
|
12
21
|
strategy.call(s3_dir, now)
|
13
22
|
Deleter.new(s3_dir, now).call
|
14
23
|
end
|
24
|
+
|
25
|
+
def s3_dir
|
26
|
+
@s3_dir ||= S3Dir.new(endpoint:, path:, access_key:, secret_key:, region:)
|
27
|
+
end
|
28
|
+
|
29
|
+
def strategy
|
30
|
+
return @strategy if @strategy
|
31
|
+
@strategy = config.fetch(:strategy, LocalBackhoe)
|
32
|
+
if @strategy.is_a?(String)
|
33
|
+
@strategy = Bard::Backup.const_get(@strategy)
|
34
|
+
end
|
35
|
+
@strategy
|
36
|
+
end
|
37
|
+
|
38
|
+
def path
|
39
|
+
config.fetch(:path)
|
40
|
+
end
|
41
|
+
|
42
|
+
def access_key
|
43
|
+
config[:access_key_id] || config[:access_key]
|
44
|
+
end
|
45
|
+
|
46
|
+
def secret_key
|
47
|
+
config[:secret_access_key] || config[:secret_key]
|
48
|
+
end
|
49
|
+
|
50
|
+
def region
|
51
|
+
config.fetch(:region, "us-west-2")
|
52
|
+
end
|
53
|
+
|
54
|
+
def now
|
55
|
+
@now ||= config.fetch(:now, Time.now.utc)
|
56
|
+
end
|
57
|
+
|
58
|
+
def endpoint
|
59
|
+
config.fetch(:endpoint, "https://s3.#{region}.amazonaws.com")
|
60
|
+
end
|
15
61
|
end
|
16
62
|
end
|
17
|
-
|
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.8.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: 2025-07-
|
11
|
+
date: 2025-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: backhoe
|
@@ -81,6 +81,7 @@ files:
|
|
81
81
|
- Rakefile
|
82
82
|
- lib/bard-backup.rb
|
83
83
|
- lib/bard/backup.rb
|
84
|
+
- lib/bard/backup/cached_local_backhoe.rb
|
84
85
|
- lib/bard/backup/deleter.rb
|
85
86
|
- lib/bard/backup/local_backhoe.rb
|
86
87
|
- lib/bard/backup/s3_dir.rb
|