Skip to content

Commit

Permalink
allow to only select parent dataset, non-recursively. (usefull for /v…
Browse files Browse the repository at this point in the history
…ar/lib/docker )
  • Loading branch information
psy0rz committed Aug 16, 2022
1 parent 4d3aa6d commit 564daaa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
6 changes: 6 additions & 0 deletions tests/test_zfsnode.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ def test_getselected(self):
shelltest("zfs create test_source1/fs1/subexcluded")
shelltest("zfs set autobackup:test=false test_source1/fs1/subexcluded")

# only select parent
shelltest("zfs create test_source1/fs1/onlyparent")
shelltest("zfs create test_source1/fs1/onlyparent/child")
shelltest("zfs set autobackup:test=parent test_source1/fs1/onlyparent")

# should be excluded by being unchanged
shelltest("zfs create test_source1/fs1/unchanged")
shelltest("zfs snapshot test_source1/fs1/unchanged@somesnapshot")
Expand All @@ -158,6 +163,7 @@ def test_getselected(self):

# basics
self.assertEqual(s, """[(local): test_source1/fs1,
(local): test_source1/fs1/onlyparent,
(local): test_source1/fs1/sub,
(local): test_source2/fs2/sub]""")

Expand Down
2 changes: 1 addition & 1 deletion zfs_autobackup/CliBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class CliBase(object):
Overridden in subclasses that add stuff for the specific programs."""

# also used by setup.py
VERSION = "3.2-alpha2"
VERSION = "3.2-beta1"
HEADER = "{} v{} - (c)2022 E.H.Eefting ([email protected])".format(os.path.basename(sys.argv[0]), VERSION)

def __init__(self, argv, print_arguments=True):
Expand Down
8 changes: 6 additions & 2 deletions zfs_autobackup/ZfsDataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def is_selected(self, value, source, inherited, exclude_received, exclude_paths,
:type exclude_unchanged: bool
:type min_change: bool
:param value: Value of the zfs property ("false"/"true"/"child"/"-")
:param value: Value of the zfs property ("false"/"true"/"child"/parent/"-")
:param source: Source of the zfs property ("local"/"received", "-")
:param inherited: True of the value/source was inherited from a higher dataset.
"""
Expand All @@ -142,7 +142,7 @@ def is_selected(self, value, source, inherited, exclude_received, exclude_paths,
raise (Exception(
"{} autobackup-property has illegal source: '{}' (possible BUG)".format(self.name, source)))

if value not in ["false", "true", "child", "-"]:
if value not in ["false", "true", "child", "parent", "-"]:
# user error
raise (Exception(
"{} autobackup-property has illegal value: '{}'".format(self.name, value)))
Expand All @@ -155,6 +155,10 @@ def is_selected(self, value, source, inherited, exclude_received, exclude_paths,
if value == "child" and not inherited:
return False

# only select parent, no childs, ignore
if value == "parent" and inherited:
return False

# manually excluded by property
if value == "false":
self.verbose("Excluded")
Expand Down

0 comments on commit 564daaa

Please sign in to comment.