kamal-backup 0.2.0 → 0.2.1
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/kamal_backup/restic.rb +19 -5
- data/lib/kamal_backup/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c69dd196192b66424004ae3769d75602862227ad958e056288e1cb49b8242a8a
|
|
4
|
+
data.tar.gz: fa70cfffdf1d95212700244fcdfbb5e7b72b8f4eaf27f2898177c16c305fe9d8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c1764bd5d9a81b9d705838a27f857a679efebe7b2c3ff64be0f4faffc440678e1958124f0cb8ca81c24fa5e30380324d20d42447ae20e5b33f7d946eab7dcec4
|
|
7
|
+
data.tar.gz: f929aecfd15c9b2ed34560292217a97e4ceff31fd4fad1b9ce0e2589af862cd725a45a275c3755ddc744bb8f0e8703c187aa96537664431b93cc4a2841ae4627
|
data/lib/kamal_backup/restic.rb
CHANGED
|
@@ -6,6 +6,8 @@ require_relative "command"
|
|
|
6
6
|
|
|
7
7
|
module KamalBackup
|
|
8
8
|
class Restic
|
|
9
|
+
RESTIC_ENV_PATTERN = /\A(?:RESTIC_|AWS_|B2_|AZURE_|GOOGLE_|RCLONE_|OS_|ST_|HP_|HTTP_|HTTPS_|NO_PROXY)/i
|
|
10
|
+
|
|
9
11
|
attr_reader :config, :redactor
|
|
10
12
|
|
|
11
13
|
def initialize(config, redactor:)
|
|
@@ -25,13 +27,19 @@ module KamalBackup
|
|
|
25
27
|
end
|
|
26
28
|
|
|
27
29
|
def backup_stream(command, filename:, tags:)
|
|
28
|
-
restic_command = CommandSpec.new(
|
|
30
|
+
restic_command = CommandSpec.new(
|
|
31
|
+
argv: ["restic", "backup", "--stdin", "--stdin-filename", filename] + tag_args(common_tags + tags),
|
|
32
|
+
env: restic_env
|
|
33
|
+
)
|
|
29
34
|
log("backing up stream as #{filename}")
|
|
30
35
|
pipe_commands(command, restic_command, producer_label: "dump", consumer_label: "restic backup")
|
|
31
36
|
end
|
|
32
37
|
|
|
33
38
|
def backup_file(path, filename:, tags:)
|
|
34
|
-
command = CommandSpec.new(
|
|
39
|
+
command = CommandSpec.new(
|
|
40
|
+
argv: ["restic", "backup", "--stdin", "--stdin-filename", filename] + tag_args(common_tags + tags),
|
|
41
|
+
env: restic_env
|
|
42
|
+
)
|
|
35
43
|
log("backing up file content as #{filename}")
|
|
36
44
|
|
|
37
45
|
File.open(path, "rb") do |file|
|
|
@@ -126,12 +134,12 @@ module KamalBackup
|
|
|
126
134
|
end
|
|
127
135
|
|
|
128
136
|
def pipe_dump_to_command(snapshot, filename, command)
|
|
129
|
-
restic_command = CommandSpec.new(argv: ["restic", "dump", snapshot, filename])
|
|
137
|
+
restic_command = CommandSpec.new(argv: ["restic", "dump", snapshot, filename], env: restic_env)
|
|
130
138
|
pipe_commands(restic_command, command, producer_label: "restic dump", consumer_label: command.argv.first)
|
|
131
139
|
end
|
|
132
140
|
|
|
133
141
|
def write_dump_to_path(snapshot, filename, target_path)
|
|
134
|
-
command = CommandSpec.new(argv: ["restic", "dump", snapshot, filename])
|
|
142
|
+
command = CommandSpec.new(argv: ["restic", "dump", snapshot, filename], env: restic_env)
|
|
135
143
|
target_path = File.expand_path(target_path)
|
|
136
144
|
FileUtils.mkdir_p(File.dirname(target_path))
|
|
137
145
|
temp_path = "#{target_path}.kamal-backup-#{$$}.tmp"
|
|
@@ -160,7 +168,7 @@ module KamalBackup
|
|
|
160
168
|
end
|
|
161
169
|
|
|
162
170
|
def run(args)
|
|
163
|
-
Command.capture(CommandSpec.new(argv: ["restic"] + args), redactor: redactor)
|
|
171
|
+
Command.capture(CommandSpec.new(argv: ["restic"] + args, env: restic_env), redactor: redactor)
|
|
164
172
|
end
|
|
165
173
|
|
|
166
174
|
def common_tags
|
|
@@ -172,6 +180,12 @@ module KamalBackup
|
|
|
172
180
|
tags.compact.each_with_object([]) { |tag, args| args.concat(["--tag", tag]) }
|
|
173
181
|
end
|
|
174
182
|
|
|
183
|
+
def restic_env
|
|
184
|
+
config.env.each_with_object({}) do |(key, value), env|
|
|
185
|
+
env[key] = value if key.to_s.match?(RESTIC_ENV_PATTERN)
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
|
|
175
189
|
def pipe_commands(producer, consumer, producer_label:, consumer_label:)
|
|
176
190
|
Open3.popen3(producer.env, *producer.argv) do |producer_stdin, producer_stdout, producer_stderr, producer_wait|
|
|
177
191
|
producer_stdin.close
|
data/lib/kamal_backup/version.rb
CHANGED