Skip to content

Enable send/receive #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/zfslib/zfslib.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,18 @@ def __init__(self, pool, name, parent=None):
super(Dataset, self).__init__(pool, name, parent)
self.dspath = self.path[len(pool.name)+1:]

# Take a pipe in and zfs receive it
# Blocks until receive is complete
# Returns the resulting processess (after it completes)
def receive(self, pipe_in):
cmd = self.pool.connection.command + ["zfs", "receive", self.path]

try:
p = subprocess.Popen(cmd, stdin=pipe_in)
p.wait()
return p
except Exception as exc:
raise exc

# get_diffs() - Gets Diffs in snapshot or between snapshots (if snap_to is specified)
# snap_from - Left side of diff
Expand Down Expand Up @@ -766,6 +778,22 @@ def resolve_snap_path(self, path):
else:
return (False, snap_path_base)

# Return a pipe with the contents of the snapshot
# Make it an incremental send if incremental_from is passed
def send(self, incremental_from=None):
if incremental_from and not isinstance(incremental_from, Snapshot):
assert 0, "incremental_from must be another snapshot"
if incremental_from:
cmd = self.pool.connection.command + ["zfs", "send", "-i", incremental_from.path, self.path]
else:
cmd = self.pool.connection.command + ["zfs", "send", self.path]

try:
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=False)
return p.stdout # When the reading starts, the subprocess will also be started
except Exception as exc:
raise exc


def __str__(self):
return "<Snapshot: %s>" % self.path
Expand Down