From 231a3908183424043b2e738cccdb11d15762c9e3 Mon Sep 17 00:00:00 2001 From: Edwin Eefting Date: Sun, 6 Oct 2024 23:04:04 +0200 Subject: [PATCH] wip fixes --- tests/test_zfsautobackup34.py | 2 +- zfs_autobackup/ZfsAutobackup.py | 2 +- zfs_autobackup/ZfsDataset.py | 24 ++++++++++++++++++------ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/tests/test_zfsautobackup34.py b/tests/test_zfsautobackup34.py index 8e64d8b..6017ba4 100644 --- a/tests/test_zfsautobackup34.py +++ b/tests/test_zfsautobackup34.py @@ -190,7 +190,7 @@ test_target1/test_source2/fs2/sub@test-20101111000003 with mocktime("20101111000001"): self.assertFalse( ZfsAutobackup( - "test test_target1/a --no-progress --verbose --allow-empty --tag tag1".split(" ")).run()) + "test test_target1/a --no-progress --verbose --allow-empty --debug --tag tag1".split(" ")).run()) # increment, should be from bookmark with mocktime("20101111000002"): diff --git a/zfs_autobackup/ZfsAutobackup.py b/zfs_autobackup/ZfsAutobackup.py index faed90b..0b4999f 100644 --- a/zfs_autobackup/ZfsAutobackup.py +++ b/zfs_autobackup/ZfsAutobackup.py @@ -224,7 +224,7 @@ class ZfsAutobackup(ZfsAuto): # does it have other snapshots? has_others = False for snapshot in dataset.snapshots: - if not snapshot.is_ours(): + if not snapshot.is_ours: has_others = True break diff --git a/zfs_autobackup/ZfsDataset.py b/zfs_autobackup/ZfsDataset.py index 4e1b989..2213362 100644 --- a/zfs_autobackup/ZfsDataset.py +++ b/zfs_autobackup/ZfsDataset.py @@ -62,6 +62,8 @@ class ZfsDataset: return self.name def __eq__(self, dataset): + """compare the full name of the dataset""" + if not isinstance(dataset, ZfsDataset): return False @@ -145,10 +147,10 @@ class ZfsDataset: @property def tagless_suffix(self): - """snapshot or bookmark part of the name, but without the tag.""" + """snapshot or bookmark part of the name, but without the tag. (if its our snapshot we remove the tag)""" suffix = self.suffix - if self.zfs_node.tag_seperator in suffix: + if self.is_ours and self.zfs_node.tag_seperator in suffix: return suffix.split(self.zfs_node.tag_seperator)[0] else: return suffix @@ -286,6 +288,8 @@ class ZfsDataset: def find_next_snapshot(self, snapshot_bookmark): """find next snapshot in this dataset, according to snapshot or bookmark. None if it doesn't exist + + Args: :type snapshot_bookmark: ZfsDataset """ @@ -298,7 +302,7 @@ class ZfsDataset: if snapshot == snapshot_bookmark: found = True else: - if found == True and snapshot.is_snapshot: + if found and snapshot.is_snapshot: return snapshot return None @@ -417,6 +421,7 @@ class ZfsDataset: else: return True + @property def is_ours(self): """return true if this snapshot name belong to the current backup_name and snapshot formatting""" return self.timestamp is not None @@ -454,8 +459,13 @@ class ZfsDataset: :rtype: int|None """ + if self.zfs_node.tag_seperator in self.suffix: + tagless_suffix = self.suffix.split(self.zfs_node.tag_seperator)[0] + else: + tagless_suffix = self.suffix + try: - dt = datetime.strptime(self.tagless_suffix, self.zfs_node.snapshot_time_format) + dt = datetime.strptime(tagless_suffix, self.zfs_node.snapshot_time_format) except ValueError: return None @@ -526,7 +536,7 @@ class ZfsDataset: ret = [] for snapshot in self.snapshots: - if snapshot.is_ours(): + if snapshot.is_ours: ret.append(snapshot) return ret @@ -548,6 +558,8 @@ class ZfsDataset: """find snapshot by snapshot name (can be a suffix or a different ZfsDataset) Returns None if it cant find it. + Note that matches with our own snapshots will be done tagless. + Args: :rtype: ZfsDataset|None :type snapshot: str|ZfsDataset|None @@ -1206,7 +1218,7 @@ class ZfsDataset: while source_snapshot: # we want it? - if (also_other_snapshots or source_snapshot.is_ours()) and not source_snapshot.is_snapshot_excluded: + if (also_other_snapshots or source_snapshot.is_ours) and not source_snapshot.is_snapshot_excluded: # create virtual target snapshot target_snapshot = target_dataset.zfs_node.get_dataset( target_dataset.filesystem_name + source_snapshot.typed_suffix, force_exists=False)