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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cc3dfc324aec3de5085d7e01d09240ee0b8ce0e784bdb7d3fc8eebdab15c2221
4
- data.tar.gz: cfa08fdf78e57d167909b53cbf3f4689fa7add3554effb1b1731375bbb7dd461
3
+ metadata.gz: 5e7e55a13d956b69746a56a472a0bb5bf0fca87c8455622ba0486d081b84981a
4
+ data.tar.gz: 0cb06eb238ad6d518515847751f7c1dfdb98d0f234c47ab10c798ff7c828a5de
5
5
  SHA512:
6
- metadata.gz: b30ab50079a0953922611b8adbf299edc752963a37b699e911cfae53e5cb3b0d63e4f9f7b4efe29eab189b061f06d422e767766d6ffc97f627d157db0e03eeca
7
- data.tar.gz: 1d7ac776750bc468dafe87209e7e403f15c69db1217392d5c20eb893595635c263f82b8c127937530db868fae5ce689d49914c2e8fa53c2014fb7321b03af0d1
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
@@ -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.9.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.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pete Kinnecom