snapshot_archive 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -0
- data/lib/snapshot_archive/archives.rb +21 -0
- data/lib/snapshot_archive/cfg.rb +13 -4
- data/lib/snapshot_archive/repositories.rb +5 -2
- data/lib/snapshot_archive/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: 5e7e55a13d956b69746a56a472a0bb5bf0fca87c8455622ba0486d081b84981a
|
4
|
+
data.tar.gz: 0cb06eb238ad6d518515847751f7c1dfdb98d0f234c47ab10c798ff7c828a5de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13abb74a373a7d31f81704872a7e6d5ab312de98dff229333fbd2ccebb220c5c56a46ec5bbfe0a0035ee496ea75a2d34942f357a5dd5469f8b4cd6c8cc5415cf
|
7
|
+
data.tar.gz: fae50ea54d90d52261a5959cf964b4e1849d0564401c06fff92075288b8cb02a53668179afc9689e70cf8aa9cedde1c1f244f119aa4ded59241d07ab398dee34
|
data/README.md
CHANGED
@@ -113,6 +113,17 @@ SnapshotArchive.configure do |config|
|
|
113
113
|
# restore: accepts the metadata JSON data created when making the backup. No
|
114
114
|
# return value.
|
115
115
|
#
|
116
|
+
# Stores can optionally define:
|
117
|
+
#
|
118
|
+
# delete: accepts the metadata JSON data created when making the backup. No
|
119
|
+
# return value. Invoked when the snapshot is deleted. If your backup method
|
120
|
+
# stores all of its data inside the snapshot directory, then no delete
|
121
|
+
# method is needed because the snapshot directory will be deleted. However,
|
122
|
+
# if your backup stores data in a different directory, then this hook can
|
123
|
+
# be used to cleanup that data. Eg, your method might write some data to
|
124
|
+
# an external or synced directory. In that case, you probably want to save
|
125
|
+
# the path to the file in the metadata, and try to delete it in this hook.
|
126
|
+
#
|
116
127
|
# Stores can either be defined as objects/classes/modules or a builtin store
|
117
128
|
# builder can be used.
|
118
129
|
|
@@ -42,6 +42,27 @@ module SnapshotArchive
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
+
class Delete
|
46
|
+
def self.call(metadata)
|
47
|
+
new(metadata).call
|
48
|
+
end
|
49
|
+
|
50
|
+
attr_reader :metadata
|
51
|
+
def initialize(metadata)
|
52
|
+
@metadata = metadata
|
53
|
+
end
|
54
|
+
|
55
|
+
def call
|
56
|
+
metadata.fetch("stores").each do |store_metadata|
|
57
|
+
store = Cfg.instance.store(store_metadata.fetch("type"))
|
58
|
+
if store.respond_to?(:delete)
|
59
|
+
store.delete(store_metadata)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
|
45
66
|
class Presenter
|
46
67
|
def self.call(metadata)
|
47
68
|
new(metadata).call
|
data/lib/snapshot_archive/cfg.rb
CHANGED
@@ -4,17 +4,22 @@ require "snapshot_archive/repositories"
|
|
4
4
|
module SnapshotArchive
|
5
5
|
class StoreBuilder
|
6
6
|
class CustomStore
|
7
|
-
def initialize(backup:, restore:)
|
7
|
+
def initialize(backup:, restore:, delete:)
|
8
8
|
@backup = backup
|
9
9
|
@restore = restore
|
10
|
+
@delete = delete
|
10
11
|
end
|
11
12
|
|
12
13
|
def backup(dir)
|
13
|
-
@backup
|
14
|
+
@backup&.call(dir)
|
14
15
|
end
|
15
16
|
|
16
17
|
def restore(metadata)
|
17
|
-
@restore
|
18
|
+
@restore&.call(metadata)
|
19
|
+
end
|
20
|
+
|
21
|
+
def delete(metadata)
|
22
|
+
@delete&.call(metadata)
|
18
23
|
end
|
19
24
|
end
|
20
25
|
|
@@ -26,8 +31,12 @@ module SnapshotArchive
|
|
26
31
|
@restore = block
|
27
32
|
end
|
28
33
|
|
34
|
+
def delete(&block)
|
35
|
+
@delete = block
|
36
|
+
end
|
37
|
+
|
29
38
|
def to_store
|
30
|
-
CustomStore.new(backup: @backup, restore: @restore)
|
39
|
+
CustomStore.new(backup: @backup, restore: @restore, delete: @delete)
|
31
40
|
end
|
32
41
|
end
|
33
42
|
|
@@ -66,10 +66,13 @@ module SnapshotArchive
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def delete(id)
|
69
|
-
|
69
|
+
metadata = JSON.parse(File.read(File.join(path, id, "metadata.json")))
|
70
|
+
raise ArgumentError.new("unknown snapshot: #{id}") unless File.exist?(metadata)
|
70
71
|
|
71
|
-
|
72
|
+
Cfg.shell.info("Running delete hooks: #{id}")
|
73
|
+
Archives::Delete.call(metadata.dig("archive"))
|
72
74
|
|
75
|
+
Cfg.shell.info("Removing snapshot: #{id}")
|
73
76
|
FileUtils.rm_rf(dir)
|
74
77
|
Cfg.shell.info("Removed snapshot: #{id}")
|
75
78
|
end
|