Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
psy0rz committed Oct 8, 2024
1 parent cf541c5 commit 4fbcc87
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions zfs_autobackup/ZfsDataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ def find_bookmark(self, snapshot_bookmark, preferred_tag):
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)
After that we return any bookmark that matches (and ignore the tag)
Args:
:rtype: ZfsDataset|None
Expand All @@ -622,6 +623,17 @@ def find_bookmark(self, snapshot_bookmark, preferred_tag):

return None

def find_exact_bookmark(self, bookmark_name):
"""find exact bookmark name, or retruns none
:rtype: ZfsDataset|None
"""

for snapshot_bookmark in self.bookmarks:
if snapshot_bookmark.name == bookmark_name:
return snapshot_bookmark
return None

def find_snapshot_index(self, snapshot):
"""find snapshot index by snapshot (can be a snapshot_name or
ZfsDataset)
Expand Down Expand Up @@ -679,15 +691,21 @@ def is_changed_ours(self, min_changed_bytes=1):
return True

def bookmark(self, tag):
"""Bookmark this snapshot, and return the bookmark."""
"""Bookmark this snapshot, and return the bookmark. If the bookmark already exist, it returns it."""
# NOTE: we use the tag to add the target_path GUID, so that we can have multiple bookmarks for the same snapshot, but for different target. This is to make sure you can send a backup to two locations, without them interfering with eachothers bookmarks.

if not self.is_snapshot:
raise (Exception("Can only bookmark a snapshot!"))

self.debug("Bookmarking")

bookmark_name = self.prefix + "#" + self.tagless_suffix + self.zfs_node.tag_seperator + tag

# does this exact bookmark (including tag) already exists?
existing_bookmark = self.find_exact_bookmark(bookmark_name)
if existing_bookmark is not None:
return existing_bookmark

self.debug("Bookmarking {}".format(bookmark_name))

cmd = [
"zfs", "bookmark", self.name, bookmark_name
]
Expand Down

0 comments on commit 4fbcc87

Please sign in to comment.