truenas / py-libzfs

Python libzfs bindings
GNU Lesser General Public License v3.0
79 stars 24 forks source link

Documentation of available methods, especially send() and receive() #182

Open monkeyman85 opened 2 years ago

monkeyman85 commented 2 years ago

Hello py-libzfs-team, I am trying to send snapshots to a backup device using the send - receive mechanism, but I cannot figure out how to use these methods correctly. Is there any documentation (what they do, what are the input parameters)? When I open the help (help(libzfs) ), I can see the different methods available, but I do not know how to find the description of input parameters.

class ZFSSnapshot(ZFSResource)
 |  Method resolution order:
 |      ZFSSnapshot
 |      ZFSResource
 |      ZFSObject
 |      builtins.object
 |
 |  Methods defined here:
 |
 |  __getstate__(...)
 |
 |  __reduce_cython__(...)
 |
 |  __setstate_cython__(...)
 |
 |  bookmark(...)
 |
 |  clone(...)
 |
 |  delete(...)
 |
 |  get_send_progress(...)
 |
 |  hold(...)
 |
 |  release(...)
 |
 |  rollback(...)
 |
 |  send(...)

In my implementation of the send-receive mechanism, I always get the Error libzfs.ZFSException: trailing slash in name although there is no trailing slash in the name of my dataset.

  File "/usr/local/lib/python3.9/multiprocessing/process.py", line 315, in _bootstrap
    self.run()
  File "/usr/local/lib/python3.9/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "libzfs.pyx", line 1392, in libzfs.ZFS.receive
libzfs.ZFSException: trailing slash in name
Bosi1024 commented 2 years ago

Hi,

I had the same problem until I figured out that incremental snapshots fromname parameter is supposed to be the string following the dataset-path and would be equal to:

to_snapshot.send(fd=fd, fromname=from_snapshot.snapshot_name, flags={libzfs.SendFlag.DOALL, libzfs.SendFlag.REPLICATE}) 

I tried using from_snapshot.name instead, which was wrong, supposedly.

ghost commented 2 years ago

Thanks for helping!

Indeed there is no documentation for libzfs anywhere. It was never meant to be a public library, only some internal code sharing for the zfs commands. But, here we are.

If you want to know how things work, you have to read the code in openzfs/zfs. If you're lucky you might even find a comment or two.