snapshot_archive 0.7.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/Gemfile.lock +2 -1
- data/README.md +15 -1
- data/exe/snap +5 -1
- data/lib/snapshot_archive/archives.rb +21 -0
- data/lib/snapshot_archive/cfg.rb +22 -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/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -6,7 +6,7 @@ snapshot and restore it later! Build your own snapshotting behavior in a
|
|
6
6
|
configuration file so that you can snapshot any stateful service you use during
|
7
7
|
development.
|
8
8
|
|
9
|
-
By default will make mysql backups for any development databases for the rails
|
9
|
+
By default will make mysql backups for any development databases for the rails
|
10
10
|
app in your CWD.
|
11
11
|
|
12
12
|
## Installation
|
@@ -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
|
|
@@ -155,5 +166,8 @@ SnapshotArchive.configure do |config|
|
|
155
166
|
# snap backup mysql:db_1,db_2
|
156
167
|
|
157
168
|
config.register_store("my_backup", "mysql:db_1,db_2")
|
169
|
+
|
170
|
+
# You can also alias an array of stores:
|
171
|
+
config.register_store("my_backup_2", ["mysql:db_1,db_2", "other_stuff"])
|
158
172
|
end
|
159
173
|
```
|
data/exe/snap
CHANGED
@@ -64,7 +64,11 @@ module SnapshotArchive
|
|
64
64
|
|
65
65
|
stores = (
|
66
66
|
if args.count > 0
|
67
|
-
args
|
67
|
+
args
|
68
|
+
.map { |arg| SnapshotArchive::Cfg.resolve_alias(arg) }
|
69
|
+
.flatten
|
70
|
+
.map { |arg| SnapshotArchive::Cfg.parse_store(arg) }
|
71
|
+
.to_h
|
68
72
|
else
|
69
73
|
SnapshotArchive::Cfg.stores
|
70
74
|
end
|
@@ -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
|
|
@@ -40,6 +49,7 @@ module SnapshotArchive
|
|
40
49
|
[
|
41
50
|
:bind_backup,
|
42
51
|
:load,
|
52
|
+
:resolve_alias,
|
43
53
|
:parse_store,
|
44
54
|
:pwd,
|
45
55
|
:repository,
|
@@ -65,6 +75,14 @@ module SnapshotArchive
|
|
65
75
|
Kernel.load(config_path) if File.exist?(config_path)
|
66
76
|
end
|
67
77
|
|
78
|
+
def resolve_alias(name)
|
79
|
+
if store_registry[name].is_a?(Array)
|
80
|
+
store_registry[name]
|
81
|
+
else
|
82
|
+
name
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
68
86
|
def register_store(name, klass_or_alias=nil, active_by_default: true, &block)
|
69
87
|
store = (
|
70
88
|
if klass_or_alias.is_a?(String)
|
@@ -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
|