mirror of
https://github.com/psy0rz/zfs_autobackup.git
synced 2025-08-19 22:53:40 +03:00
cleanedup and improved select-code
This commit is contained in:
parent
686bb48bda
commit
cf72de7c28
zfs_autobackup
@ -90,6 +90,35 @@ class ZfsDataset:
|
|||||||
"""true if this dataset is a snapshot"""
|
"""true if this dataset is a snapshot"""
|
||||||
return self.name.find("@") != -1
|
return self.name.find("@") != -1
|
||||||
|
|
||||||
|
def is_selected(self, value, source, inherited, ignore_received):
|
||||||
|
"""determine if dataset should be selected for backup (called from ZfsNode)"""
|
||||||
|
|
||||||
|
# sanity checks
|
||||||
|
if source not in ["local", "received", "-"]:
|
||||||
|
# probably a program error in zfs-autobackup or new feature in zfs
|
||||||
|
raise (Exception(
|
||||||
|
"{} autobackup-property has illegal source: '{}' (possible BUG)".format(self.name, source)))
|
||||||
|
if value not in ["false", "true", "child", "-"]:
|
||||||
|
# user error
|
||||||
|
raise (Exception(
|
||||||
|
"{} autobackup-property has illegal value: '{}'".format(self.name, value)))
|
||||||
|
|
||||||
|
# now determine if its actually selected
|
||||||
|
if value == "false":
|
||||||
|
self.verbose("Ignored (disabled)")
|
||||||
|
return False
|
||||||
|
elif value == "true" or (value == "child" and inherited):
|
||||||
|
if source == "local":
|
||||||
|
self.verbose("Selected")
|
||||||
|
return True
|
||||||
|
elif source == "received":
|
||||||
|
if ignore_received:
|
||||||
|
self.verbose("Ignored (local backup)")
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
self.verbose("Selected")
|
||||||
|
return True
|
||||||
|
|
||||||
@CachedProperty
|
@CachedProperty
|
||||||
def parent(self):
|
def parent(self):
|
||||||
"""get zfs-parent of this dataset. for snapshots this means it will get the filesystem/volume that it belongs
|
"""get zfs-parent of this dataset. for snapshots this means it will get the filesystem/volume that it belongs
|
||||||
|
|||||||
@ -194,7 +194,7 @@ class ZfsNode(ExecuteNode):
|
|||||||
self.run(cmd, readonly=False)
|
self.run(cmd, readonly=False)
|
||||||
|
|
||||||
@CachedProperty
|
@CachedProperty
|
||||||
def selected_datasets(self):
|
def selected_datasets(self, ignore_received=True):
|
||||||
"""determine filesystems that should be backupped by looking at the special autobackup-property, systemwide
|
"""determine filesystems that should be backupped by looking at the special autobackup-property, systemwide
|
||||||
|
|
||||||
returns: list of ZfsDataset
|
returns: list of ZfsDataset
|
||||||
@ -204,35 +204,32 @@ class ZfsNode(ExecuteNode):
|
|||||||
|
|
||||||
# get all source filesystems that have the backup property
|
# get all source filesystems that have the backup property
|
||||||
lines = self.run(tab_split=True, readonly=True, cmd=[
|
lines = self.run(tab_split=True, readonly=True, cmd=[
|
||||||
"zfs", "get", "-t", "volume,filesystem", "-o", "name,value,source", "-s", "local,inherited", "-H",
|
"zfs", "get", "-t", "volume,filesystem", "-o", "name,value,source", "-H",
|
||||||
"autobackup:" + self.backup_name
|
"autobackup:" + self.backup_name
|
||||||
])
|
])
|
||||||
|
|
||||||
# determine filesystems that should be actually backupped
|
# The returnlist of selected ZfsDataset's:
|
||||||
selected_filesystems = []
|
selected_filesystems = []
|
||||||
direct_filesystems = []
|
|
||||||
|
# list of sources, used to resolve inherited sources
|
||||||
|
sources = {}
|
||||||
|
|
||||||
for line in lines:
|
for line in lines:
|
||||||
(name, value, source) = line
|
(name, value, raw_source) = line
|
||||||
dataset = ZfsDataset(self, name)
|
dataset = ZfsDataset(self, name)
|
||||||
|
|
||||||
if value == "false":
|
# "resolve" inherited sources
|
||||||
dataset.verbose("Ignored (disabled)")
|
sources[name] = raw_source
|
||||||
|
if raw_source.find("inherited from ") == 0:
|
||||||
|
inherited = True
|
||||||
|
inherited_from = re.sub("^inherited from ", "", raw_source)
|
||||||
|
source = sources[inherited_from]
|
||||||
else:
|
else:
|
||||||
if source == "local" and (value == "true" or value == "child"):
|
inherited = False
|
||||||
direct_filesystems.append(name)
|
source = raw_source
|
||||||
|
|
||||||
if source == "local" and value == "true":
|
# determine it
|
||||||
dataset.verbose("Selected (direct selection)")
|
if dataset.is_selected(value=value, source=source, inherited=inherited, ignore_received=ignore_received):
|
||||||
selected_filesystems.append(dataset)
|
selected_filesystems.append(dataset)
|
||||||
elif source.find("inherited from ") == 0 and (value == "true" or value == "child"):
|
|
||||||
inherited_from = re.sub("^inherited from ", "", source)
|
|
||||||
if inherited_from in direct_filesystems:
|
|
||||||
selected_filesystems.append(dataset)
|
|
||||||
dataset.verbose("Selected (inherited selection)")
|
|
||||||
else:
|
|
||||||
dataset.debug("Ignored (already a backup)")
|
|
||||||
else:
|
|
||||||
dataset.verbose("Ignored (only childs)")
|
|
||||||
|
|
||||||
return selected_filesystems
|
return selected_filesystems
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user