Now that I can read a list of snapshots, I need to read a snapshot and transfer it to the destination. The three functions that allow me to do that are exec.StdinPipe(), exec.StdoutPipe(), and io.CopyBuffer().
The process consists of the following steps:
- Create an exec.Cmd representing the zfs send command
- Use exec.StdoutPipe() to connect a pipe to the output of the command created in step 1.
- Create an exec.Cmd representing the zfs receive command
- Use exec.StdinPipe() to connect a pipe to the input of the command created in step 3.
- Start both commands
- Use io.CopyBuffer() to read from the snapshot to the receiver.
You can view the code here.