A library for interacting with ZFS, made in the spirit of Pathname.
Just like Pathname, it does not represent the filesystem itself, until you try to reference it by calling methods on it. It can not, however, be relative - it is always an absolute reference to a specific pool and path.
The only exception is when trying to reference a mountpoint by using a filesystem-path. In this
case, a ZFS object is only returned if the mountpoint exists. (eg. ZFS('/tank/foo'))
ZFS is mutable, and contains potentially very destructive methods.
ZFS.pools# => [<ZFS:tank>]fs=ZFS('tank/foo')# => <ZFS:tank/foo>fs.create# creates the filesystemfs.exist?# => truefs.name# => 'tank/foo'fs.mountpoint# => '/tank/foo'ZFS('/tank/foo')# => <ZFS:tank/foo>fs.parent# => <ZFS:tank>fs.parent.parent# => nilfs.available# returns bytes available in the filesystemfs.type# => :filesystemfs.checksum=:fletcher4fs.readonly=truefs.readonly?# => true# plus all other properties defined in (currently) ZFS v28fs['org.freebsd:swap']=1# sets the custom property 'org.freebsd:swap' to 1fs['org.freebsd:swap']# => 1(fs + 'bar').create# => <ZFS:tank/foo/bar>(fs + 'bar/baz').create# => <ZFS:tank/foo/bar/baz>fs.children# => [<ZFS:tank/foo/bar]fs.children(recursive: true)# => [<ZFS:tank/foo/bar>, <ZFS:tank/foo/bar/baz>]s=fs.snapshot('snapname')# => <ZFS:tank/foo@snapname>s.parent# => <ZFS:tank/foo>fs.snapshots# => [<ZFS:tank/foo@snapname>]s.destroy!# destroys snapshot# Take a recursive snapshot ('zfs snapshot -r')fs.snapshot('snapname',children: true)# => [<ZFS:tank/foo@snapname>, <ZFS:tank/foo/bar@snapname, ...]# Destroy a snapshot recursivelyZFS('tank/foo@snapname').destroy!(children: true)s=fs.snapshot('snapname')# => <ZFS:tank/foo@snapname>fs2=s.clone('tank/bar')# => <ZFS:tank/bar>fs2.promote!fs2.rename('tank/baz')snapshot.send_to(fs)# ZFS send/receive rolled into one - needs long descriptionStillmissinginherit,mount/unmount,share/unshare,andmaybesend/receive# Shell out to `ssh`, and assume `zfs` and `zpool` is in path on remote hostZFS('tank/foo',hostname: 'foo.example.com')# Can be set to either a String or an ArrayZFS.zfs_path# => '/sbin/zfs'ZFS.zpool_path# => '/sbin/zpool'Uses a Vagrant VM with a custom Ubuntu + ZFS-on-Linux to do all the practical tests, to avoid thrashing any local ZFS-installations.
To get up and running, do the following:
- Install Vagrant (with Bundler, as a system gem, or as a package - your choice)
- Install vagrant-proxyssh
- Run
rake bundleto install gems inside the Vagrant VM - Run
rake guardto fire up guard, and run tests inside the Vagrant VM.
Optional: add custom notification options to .guardfile_private.
- Currently, ZFS-objects aren't cached, so two instances can refer to the same filesystem. If mutable actions are called, only one is updated to reflect. (eg. rename!)
- Many commands take options, but do not warn/error if given invalid options