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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cc3dfc324aec3de5085d7e01d09240ee0b8ce0e784bdb7d3fc8eebdab15c2221
4
- data.tar.gz: cfa08fdf78e57d167909b53cbf3f4689fa7add3554effb1b1731375bbb7dd461
3
+ metadata.gz: 0a509e2459e8eacc481040b2a3b8abfc9479a0004ab48439eefd4a2c644232e8
4
+ data.tar.gz: cb7ed097f707afc0f3fdbf69ba5ba9df13fc656d2d8f4dc4e6a9b6a77958b8b6
5
5
  SHA512:
6
- metadata.gz: b30ab50079a0953922611b8adbf299edc752963a37b699e911cfae53e5cb3b0d63e4f9f7b4efe29eab189b061f06d422e767766d6ffc97f627d157db0e03eeca
7
- data.tar.gz: 1d7ac776750bc468dafe87209e7e403f15c69db1217392d5c20eb893595635c263f82b8c127937530db868fae5ce689d49914c2e8fa53c2014fb7321b03af0d1
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| store.backup(dir)&.merge(type: name) }
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
@@ -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.call(dir)
14
+ @backup&.call(dir)
14
15
  end
15
16
 
16
17
  def restore(metadata)
17
- @restore.call(metadata)
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
- dir = File.join(path, id)
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
- raise ArgumentError.new("unknown snapshot: #{id}") unless File.exist?(dir)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SnapshotArchive
4
- VERSION = "0.8.0"
4
+ VERSION = "0.10.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snapshot_archive
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pete Kinnecom