mirror of
https://github.com/psy0rz/zfs_autobackup.git
synced 2025-06-01 01:20:58 +03:00
preferred bookmark matching
This commit is contained in:
parent
231a390818
commit
4e7679cf2f
@ -168,6 +168,15 @@ class ZfsDataset:
|
|||||||
|
|
||||||
raise (Exception("This is not a snapshot or bookmark"))
|
raise (Exception("This is not a snapshot or bookmark"))
|
||||||
|
|
||||||
|
@property
|
||||||
|
def tag(self):
|
||||||
|
"""the tag-part of a snapshot or bookmark, if any. can return None"""
|
||||||
|
|
||||||
|
if self.is_ours and self.zfs_node.tag_seperator in self.suffix:
|
||||||
|
return self.suffix.split(self.zfs_node.tag_seperator)[1]
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_snapshot(self):
|
def is_snapshot(self):
|
||||||
"""true if this dataset is a snapshot"""
|
"""true if this dataset is a snapshot"""
|
||||||
@ -579,30 +588,33 @@ class ZfsDataset:
|
|||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def find_bookmark(self, bookmark, ignore_tag):
|
def find_bookmark(self, snapshot_bookmark, preferred_tag):
|
||||||
"""find bookmark by bookmark name (can be a suffix or a different
|
"""find bookmark by bookmark name (can be a suffix or a different
|
||||||
ZfsDataset) Returns None if it cant find it.
|
ZfsDataset) Returns None if it cant find it.
|
||||||
|
|
||||||
|
We try to find the bookmark with the preferred tag (which is usually a target path guid, to prevent conflicting bookmarks by multiple sends)
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
:rtype: ZfsDataset|None
|
:rtype: ZfsDataset|None
|
||||||
:type bookmark: str|ZfsDataset|None
|
:type snapshot_bookmark: str|ZfsDataset|None
|
||||||
:type ignore_tag: bool
|
:type ignore_tag: bool
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if bookmark is None:
|
if snapshot_bookmark is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if not isinstance(bookmark, ZfsDataset):
|
if not isinstance(snapshot_bookmark, ZfsDataset):
|
||||||
suffix = bookmark
|
tagless_suffix = snapshot_bookmark
|
||||||
else:
|
else:
|
||||||
if ignore_tag:
|
tagless_suffix = snapshot_bookmark.tagless_suffix
|
||||||
suffix = bookmark.tagless_suffix
|
|
||||||
else:
|
|
||||||
suffix = bookmark.suffix
|
|
||||||
|
|
||||||
for bookmark in self.bookmarks:
|
for snapshot_bookmark in self.bookmarks:
|
||||||
if (ignore_tag and bookmark.tagless_suffix == suffix) or (not ignore_tag and bookmark.suffix == suffix):
|
if snapshot_bookmark.tagless_suffix == tagless_suffix and snapshot_bookmark.tag == preferred_tag:
|
||||||
return bookmark
|
return snapshot_bookmark
|
||||||
|
|
||||||
|
for snapshot_bookmark in self.bookmarks:
|
||||||
|
if snapshot_bookmark.tagless_suffix == tagless_suffix:
|
||||||
|
return snapshot_bookmark
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -1047,17 +1059,14 @@ class ZfsDataset:
|
|||||||
else:
|
else:
|
||||||
for target_snapshot in reversed(target_dataset.snapshots):
|
for target_snapshot in reversed(target_dataset.snapshots):
|
||||||
|
|
||||||
# Source bookmark with same suffix?
|
# Prefer bookmarks over snapshots
|
||||||
# source_bookmark = self.find_bookmark(target_snapshot)
|
source_bookmark = self.find_bookmark(target_snapshot, preferred_tag=bookmark_tag)
|
||||||
# if source_bookmark:
|
if source_bookmark:
|
||||||
# if guid_check and source_bookmark.properties['guid'] != target_snapshot.properties['guid']:
|
if guid_check and source_bookmark.properties['guid'] != target_snapshot.properties['guid']:
|
||||||
# source_bookmark.warning("Bookmark has mismatching GUID, ignoring.")
|
source_bookmark.warning("Bookmark has mismatching GUID, ignoring.")
|
||||||
# else:
|
else:
|
||||||
# source_bookmark.debug("Common bookmark")
|
source_bookmark.debug("Common bookmark")
|
||||||
# return source_bookmark
|
return source_bookmark
|
||||||
if bookmark.exists and bookmark.properties['guid'] == target_snapshot.properties['guid']:
|
|
||||||
# FIXME: wil eigenlijk guid check opineel houden .dus bookmark name word snapshotname_targetdatasetguid
|
|
||||||
return bookmark
|
|
||||||
|
|
||||||
# Source snapshot with same suffix?
|
# Source snapshot with same suffix?
|
||||||
source_snapshot = self.find_snapshot(target_snapshot)
|
source_snapshot = self.find_snapshot(target_snapshot)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user