bard-backup 0.16.2 → 0.16.4

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: 334fe0c69997da7ca4ea68bcfe33b23868b863c9ca5fd355d8713cec9184d9e6
4
- data.tar.gz: 883b6e3b202f9e57de6c414a282c4d2983b61b50791f7e1a3c10e3bd4f14f02f
3
+ metadata.gz: e86879e3ce9f411f44333fb1fe7f91ca03bcde7a2ce59fd06ecff3195baa57e4
4
+ data.tar.gz: 405a0fd2cef1e33ed766e65594129545198acb5621bdb18ec69990049fe72062
5
5
  SHA512:
6
- metadata.gz: f73eddb5fc415a04bfae9e25953fc07a8c9b2d04280f341490b6c4f73601618c9ae5120e4cb9c5305deeb239f820cf4842d3b783ba7f2b4d20f170fc6efbe8eb
7
- data.tar.gz: 1c68e20bb32a956c3385211ac166fa278eee80df2a3b4e3c537e00dd81136ff4849ccaf621562a8e14c06b2f7cfd9817e5749c497ce0787eb421413e3c6b0b13
6
+ metadata.gz: cb1dd0d3b55864aa3d91b67917d0142cac819eb2e7ad0294192cced323cb486cd4fdfeb9ed3e5d1c207fd854870c28c7e8beace12aa92ff03872277f3d1d3ff1
7
+ data.tar.gz: 6838665c92586d4e0a8a12a197e6ffd780aae8e631cebc73327c729cc78bd6e086e6a1826902bb5ec4efede3c6447af9dc51bacacf2d5c097a25465a7793f4a9
@@ -1,26 +1,37 @@
1
1
  require "backhoe"
2
+ require "bard/config"
3
+ require "fileutils"
4
+ require "tmpdir"
2
5
 
3
6
  module Bard
4
7
  class Backup
5
8
  class CachedLocalBackhoe < Struct.new(:s3_tree, :now)
9
+ class << self
10
+ attr_accessor :dump_dir
11
+ end
12
+
6
13
  def self.call *args
7
14
  new(*args).call
8
15
  end
9
16
 
10
17
  def call
11
- s3_tree.put_file(path, File.basename(path))
18
+ s3_tree.put_file(path, filename)
12
19
  end
13
20
 
14
21
  private
15
22
 
23
+ def filename
24
+ "#{now.iso8601}.sql.gz"
25
+ end
26
+
16
27
  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
28
+ cached = self.class.dump_dir && File.join(self.class.dump_dir, filename)
29
+ return cached if cached && File.exist?(cached)
30
+
31
+ FileUtils.rm_rf(self.class.dump_dir) if self.class.dump_dir
32
+ self.class.dump_dir = dir = Dir.mktmpdir("#{Bard::Config.current.project_name}-backup-")
33
+ at_exit { FileUtils.rm_rf dir }
34
+ File.join(dir, filename).tap { |path| Backhoe.dump path }
24
35
  end
25
36
  end
26
37
  end
@@ -31,13 +31,17 @@ module Bard
31
31
  end
32
32
 
33
33
  def call
34
- manifest = load_manifest
35
- local_files = collect_local_files
34
+ File.open("#{MANIFEST_PATH}.lock", File::CREAT | File::RDWR) do |lock|
35
+ return unless lock.flock(File::LOCK_EX | File::LOCK_NB)
36
36
 
37
- if manifest.empty?
38
- sync_from_s3(local_files)
39
- else
40
- sync_from_manifest(local_files, manifest)
37
+ manifest = load_manifest
38
+ local_files = collect_local_files
39
+
40
+ if manifest.empty?
41
+ sync_from_s3(local_files)
42
+ else
43
+ sync_from_manifest(local_files, manifest)
44
+ end
41
45
  end
42
46
  end
43
47
 
@@ -75,7 +79,7 @@ module Bard
75
79
 
76
80
  local_files.each do |path, stat|
77
81
  md5 = Digest::MD5.file(path).hexdigest
78
- unless remote[path] == md5
82
+ unless remote[path] == s3_tree.etag_for(path)
79
83
  s3_tree.put_file(path, path)
80
84
  end
81
85
  new_manifest[path] = { "md5" => md5, "mtime" => stat[:mtime], "size" => stat[:size] }
@@ -1,13 +1,16 @@
1
1
  require "backhoe"
2
+ require "bard/config"
3
+ require "tmpdir"
2
4
 
3
5
  module Bard
4
6
  class Backup
5
7
  class LocalBackhoe
6
8
  def self.call s3_tree, now
7
- filename = "#{now.iso8601}.sql.gz"
8
- path = "/tmp/#{filename}"
9
- Backhoe.dump path
10
- s3_tree.mv path
9
+ Dir.mktmpdir("#{Bard::Config.current.project_name}-backup-") do |dir|
10
+ path = File.join(dir, "#{now.iso8601}.sql.gz")
11
+ Backhoe.dump path
12
+ s3_tree.mv path
13
+ end
11
14
  end
12
15
  end
13
16
  end
@@ -1,5 +1,6 @@
1
1
  require "aws-sdk-s3"
2
2
  require "fileutils"
3
+ require "digest/md5"
3
4
  require "bard/backup/encryptor"
4
5
 
5
6
  module Bard
@@ -52,6 +53,13 @@ module Bard
52
53
  put_body(remote_key, File.binread(local_path))
53
54
  end
54
55
 
56
+ # S3's ETag for a single-part upload is the MD5 of the stored bytes, i.e. the ciphertext when encrypting
57
+ def etag_for(local_path)
58
+ body = File.binread(local_path)
59
+ body = encryptor.encrypt(body) if encryptor
60
+ Digest::MD5.hexdigest(body)
61
+ end
62
+
55
63
  def put_body(remote_key, body)
56
64
  body = encryptor.encrypt(body) if encryptor
57
65
  client.put_object({
@@ -1,6 +1,6 @@
1
1
  module Bard
2
2
  class Backup
3
- VERSION = "0.16.2"
3
+ VERSION = "0.16.4"
4
4
  end
5
5
  end
6
6
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bard-backup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.2
4
+ version: 0.16.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micah Geisel
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2026-11-13 00:00:00.000000000 Z
10
+ date: 2026-11-16 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: backhoe