bard-backup 0.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4746616bc6439c661cc7187970f3d72f51df06395e6e7535ce1238465746c1f7
4
- data.tar.gz: b1a41fca533525a326fecf71f848477ed31e391346c53cf2db73bf4d1c5e6c23
3
+ metadata.gz: 5727d5acc23ec75d951a70f062b7bf4da0bbc3ab010c3d96de502530f063497e
4
+ data.tar.gz: d3d07429a57b4e2ea090216ae954e7e682f5f18c9ddeb44f93446af3b871dd53
5
5
  SHA512:
6
- metadata.gz: 1c1ee7c76fd20226a6880e7f667a6f9eeb074d073248687673119574501db7e322112ade1de83768034a037a538c08182d8fdbfbab1c14f101e27ea1a86cc212
7
- data.tar.gz: 8944a7834916e521b35ec5bf4a09cd4369cfe7613225d5f6e46fff0ffe16729e8ba80a0cdabc99647365ede937103dcc8d083deb9b756304dcff7c2f8dd060de
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: 72 hours, 60 days, 52 weeks, 48 months, then yearly
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 s3_path, access_key: "...", secret_key: "...", region: "..."`
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
@@ -3,7 +3,7 @@ require "active_support/core_ext/date_time/calculations"
3
3
  require "active_support/core_ext/integer/time"
4
4
 
5
5
  module Bard
6
- module Backup
6
+ class Backup
7
7
  class Deleter < Struct.new(:s3_dir, :now)
8
8
  def call
9
9
  s3_dir.delete files_to_delete
@@ -1,7 +1,7 @@
1
1
  require "backhoe"
2
2
 
3
3
  module Bard
4
- module Backup
4
+ class Backup
5
5
  class LocalBackhoe
6
6
  def self.call s3_dir, now
7
7
  filename = "#{now.iso8601}.sql.gz"
@@ -2,8 +2,13 @@ require "aws-sdk-s3"
2
2
  require "rexml"
3
3
 
4
4
  module Bard
5
- module Backup
6
- class S3Dir < Data.define(:path, :access_key, :secret_key, :region)
5
+ class Backup
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,
@@ -70,6 +75,7 @@ module Bard
70
75
 
71
76
  def client
72
77
  Aws::S3::Client.new({
78
+ endpoint: endpoint,
73
79
  region: region,
74
80
  access_key_id: access_key,
75
81
  secret_access_key: secret_key,
@@ -78,4 +84,3 @@ module Bard
78
84
  end
79
85
  end
80
86
  end
81
-
@@ -1,6 +1,6 @@
1
1
  module Bard
2
- module Backup
3
- VERSION = "0.6.0"
2
+ class Backup
3
+ VERSION = "0.8.0"
4
4
  end
5
5
  end
6
6
 
data/lib/bard/backup.rb CHANGED
@@ -1,14 +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
- module Backup
7
- def self.call s3_path, access_key:, secret_key:, region: "us-west-2", now: Time.now.utc, strategy: LocalBackhoe
8
- s3_dir = S3Dir.new(path: s3_path, access_key:, secret_key:, region:)
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
9
21
  strategy.call(s3_dir, now)
10
22
  Deleter.new(s3_dir, now).call
11
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
12
61
  end
13
62
  end
14
-
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.6.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-04-02 00:00:00.000000000 Z
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