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 +4 -4
- data/lib/bard/backup/cached_local_backhoe.rb +19 -8
- data/lib/bard/backup/file_tree.rb +11 -7
- data/lib/bard/backup/local_backhoe.rb +7 -4
- data/lib/bard/backup/s3_tree.rb +8 -0
- data/lib/bard/backup/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e86879e3ce9f411f44333fb1fe7f91ca03bcde7a2ce59fd06ecff3195baa57e4
|
|
4
|
+
data.tar.gz: 405a0fd2cef1e33ed766e65594129545198acb5621bdb18ec69990049fe72062
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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,
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
35
|
-
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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] ==
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
data/lib/bard/backup/s3_tree.rb
CHANGED
|
@@ -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({
|
data/lib/bard/backup/version.rb
CHANGED
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.
|
|
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-
|
|
10
|
+
date: 2026-11-16 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: backhoe
|