snapshot_archive 0.8.0 → 0.10.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 +26 -1
- 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: 0a509e2459e8eacc481040b2a3b8abfc9479a0004ab48439eefd4a2c644232e8
|
4
|
+
data.tar.gz: cb7ed097f707afc0f3fdbf69ba5ba9df13fc656d2d8f4dc4e6a9b6a77958b8b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 797b07563f5d6328fcee8e19e7da4c137e358dfe763bf974cd6856178ad1c5d85fd1727aa1eafeee39417c3d7354589abccb9206b46ec5ac5e1695907cb7b3f9
|
7
|
+
data.tar.gz: 6820e7d7a20c4efae51144a2e31a050f69b4fbee92f4634055c369abd460e437a45fe6f892f1af42d667e4bc0bdc66c5ed887f2e92c71514ff5330b465ed1197
|
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
|
|
@@ -14,7 +14,11 @@ module SnapshotArchive
|
|
14
14
|
def call
|
15
15
|
stores_metadata = (
|
16
16
|
stores
|
17
|
-
.map { |name, store|
|
17
|
+
.map { |name, store|
|
18
|
+
store_dir = FileUtils.mkdir(File.join(dir, name))
|
19
|
+
|
20
|
+
store.backup(store_dir)&.merge(type: name)
|
21
|
+
}
|
18
22
|
.compact
|
19
23
|
)
|
20
24
|
|
@@ -42,6 +46,27 @@ module SnapshotArchive
|
|
42
46
|
end
|
43
47
|
end
|
44
48
|
|
49
|
+
class Delete
|
50
|
+
def self.call(metadata)
|
51
|
+
new(metadata).call
|
52
|
+
end
|
53
|
+
|
54
|
+
attr_reader :metadata
|
55
|
+
def initialize(metadata)
|
56
|
+
@metadata = metadata
|
57
|
+
end
|
58
|
+
|
59
|
+
def call
|
60
|
+
metadata.fetch("stores").each do |store_metadata|
|
61
|
+
store = Cfg.instance.store(store_metadata.fetch("type"))
|
62
|
+
if store.respond_to?(:delete)
|
63
|
+
store.delete(store_metadata)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
|
45
70
|
class Presenter
|
46
71
|
def self.call(metadata)
|
47
72
|
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
|