zfs_mgmt 0.2.6 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b5c67b730a6425cce0f548ebb67c1e17a8448ea12cdf276e54d4f182bb30a17e
4
- data.tar.gz: 4cbe541a5c8f12c57b0fbc5b3879d782debf596fb8afe85f0e702bda55d349e6
3
+ metadata.gz: 2de1f11ed73e026b52fa86c015ddc14ae82cfe1ac26cd97fee0b02407fb39cd4
4
+ data.tar.gz: 881ad0dff3a3008146b5fc7332f1f1aee7811c8a334eef4c6dde14876b65625d
5
5
  SHA512:
6
- metadata.gz: 66328802d68ac95c5ef12f9ed8a51705367adba6857a1f20fda7fc2237013d0abe76d7a2ef7d44e7056ddf72c30ce5922f4f5dd9df1757ce7eb80a9b34eb5a9e
7
- data.tar.gz: c6aa92723d903ea2d5192193350c8c41db116c307347308834895061e6eb7d2380e4501d663a2563c46d8869ebd60b832e49699f3dc38c57991818d07791a4a8
6
+ metadata.gz: 215c743791ac41d0c6d94d54dbf87124c8c846a552b5ec41c3840eeba0673619554f5105532712f573a4a81a30df5aafaf2a55d9d1cbfc8ba4360aa5595464b1
7
+ data.tar.gz: 12c041e55ebbd35318c21afb883f22e686b8c37f571d2a92f5eeb56a1fc44a3ee54ef7c09fa0fb611a1317250223f84c6cb140bc4d8b3e72f1249cecd5fb5ff2
data/README.md CHANGED
@@ -165,6 +165,18 @@ to match the specified policy for the zfs, nor will they be deleted.
165
165
  The intended use is match zfs send/recv snapshots or hand-created
166
166
  snapshots, etc. ie: ^syncoid_
167
167
 
168
+ ### zfsmgmt:prefersnaps
169
+ Prefer snapshots matching this regexp pattern. The oldest/youngest
170
+ snapshot matching this pattern will be used depending on strategy, but
171
+ if no snapshots are found matching this pattern use any snapshot as
172
+ constrained by the matchsnaps and ignoresnaps options (if set.)
173
+
174
+ ### zfsmgmt:strategy (default: oldest)
175
+ Save the oldest snapshot fitting a given time frame as specificed by
176
+ the policy, unless this value is set to "youngest" in which case use
177
+ the most recent snapshot for any given time frame. The default is
178
+ oldest and unless the property is set to youngest oldest will be used.
179
+
168
180
  ### zfsmgmt:snapshot
169
181
  If this property is 'true' then create a snapshot in the format of
170
182
  zfsmgmt-%FT%T%z. If this property is 'recursive' then create a
@@ -44,6 +44,7 @@ module ZfsMgmt
44
44
  'minage',
45
45
  'matchsnaps',
46
46
  'ignoresnaps',
47
+ 'prefersnaps',
47
48
  'snapshot',
48
49
  'snap_prefix',
49
50
  'snap_timestamp',
@@ -117,13 +118,11 @@ module ZfsMgmt
117
118
  if props.has_key?('zfsmgmt:minage')
118
119
  minage = timespec_to_seconds(props['zfsmgmt:minage'])
119
120
  end
120
- strategy = 'youngest'
121
- if props.has_key?('zfsmgmt:strategy') and props['zfsmgmt:strategy'] == 'oldest'
122
- strategy = 'oldest'
121
+ strategy = 'oldest'
122
+ if props.has_key?('zfsmgmt:strategy') and props['zfsmgmt:strategy'] == 'youngest'
123
+ strategy = 'youngest'
123
124
  end
124
125
  sorted = snaps.keys.sort { |a,b| snaps[b]['creation'] <=> snaps[a]['creation'] }
125
- # never consider the latest snapshot for anything
126
- newest_snapshot_name = sorted.shift
127
126
 
128
127
  counters = policy_parser(props['zfsmgmt:policy'])
129
128
  $logger.debug(counters)
@@ -147,12 +146,16 @@ module ZfsMgmt
147
146
  $date_patterns.each do |d,p|
148
147
  pat = snaptime.strftime(p)
149
148
  if saved[d].has_key?(pat)
150
- if strategy == 'youngest'
149
+ #pp props['zfsmgmt:prefersnaps'],snap_name.split('@')[1], saved[d][pat].split('@')[1]
150
+ if props.has_key?('zfsmgmt:prefersnaps') and /#{props['zfsmgmt:prefersnaps']}/ !~ saved[d][pat].split('@')[1] and /#{props['zfsmgmt:prefersnaps']}/ =~ snap_name.split('@')[1]
151
+ $logger.debug("updating the saved snapshot, we prefer this one: \"#{pat}\" to #{snap_name} at #{snaptime}")
152
+ saved[d][pat] = snap_name
153
+ elsif strategy == 'oldest' and ( not props.has_key?('zfsmgmt:prefersnaps') or /#{props['zfsmgmt:prefersnaps']}/ =~ snap_name.split('@')[1] )
151
154
  # update the existing current save snapshot for this timeframe
152
155
  $logger.debug("updating the saved snapshot for \"#{pat}\" to #{snap_name} at #{snaptime}")
153
156
  saved[d][pat] = snap_name
154
157
  else
155
- $logger.debug("not updating the saved snapshot for \"#{pat}\" to #{snap_name} at #{snaptime}, we have an older snap")
158
+ $logger.debug("not updating the saved snapshot for \"#{pat}\" to #{snap_name} at #{snaptime}, we have a younger snap")
156
159
  end
157
160
  elsif counters[d] > 0
158
161
  # new pattern, and we want to save more snaps of this type
@@ -179,6 +182,9 @@ module ZfsMgmt
179
182
  elsif minage > 0 and Time.at(snaps[snap]['creation'] + minage) > Time.now()
180
183
  $logger.debug("skipping due to minage: #{snap} #{local_epoch_to_datetime(snaps[snap]['creation']).strftime('%F %T')}")
181
184
  false
185
+ elsif snap == sorted[0] # the very newest snap
186
+ $logger.debug("skipping due to newest: #{snap} #{local_epoch_to_datetime(snaps[snap]['creation']).strftime('%F %T')}")
187
+ false
182
188
  else
183
189
  true
184
190
  end
@@ -1,3 +1,3 @@
1
1
  module ZfsMgmt
2
- VERSION = "0.2.6"
2
+ VERSION = "0.2.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zfs_mgmt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aran Cox
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-06 00:00:00.000000000 Z
11
+ date: 2020-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler