Categorygithub.com/krystal/go-zfs
modulepackage
0.1.3
Repository: https://github.com/krystal/go-zfs.git
Documentation: pkg.go.dev

# README

go-zfs

Go package that enables ZFS pool and dataset management by wrapping zfs and zpool CLI commands.

Go Reference GitHub tag (latest SemVer) Actions Status Coverage GitHub last commit GitHub issues GitHub pull requests License Status

Packages

zfs

The primary package used for interacting with ZFS, through the *zfs.Manager type.

import "github.com/krystal/go-zfs"

zfsprops

A helper package which defines a long list of string constants for most native properties available, based on OpenZFS' zfsprops manpage.

import "github.com/krystal/go-zfs/zfsprops"

zpoolprops

A helper package which defines a long list of string constants for most zpool properties available, based on OpenZFS' zpoolprops manpage.

import "github.com/krystal/go-zfs/zpoolprops"

Usage

Create a new *zfs.Manager instance to manage ZFS pools and datasets with:

z := zfs.New()

Get details for a specific dataset:

ds, err := z.GetDataset(ctx, "tank/my-data")
fmt.Printf("Name: %s\n", ds.Name)
Name: tank/my-data

Get used dataset property via Used() helper method, which returns the value as a uint64 of bytes:

if v, ok := ds.Used(); ok {
	fmt.Printf("Used: %d bytes\n", v)
}
Used: 150470656 bytes

Get used dataset property by directly accessing the Properties map, returning a Property type which has a string Value.

if prop, ok := ds.Properties[zfsprops.Used]; ok {
	fmt.Printf("Used: %s bytes\n", prop.Value)
}
Used: 150470656 bytes

Create a new pool, using both zpoolprops and zfsprops helper packages:

err = z.CreatePool(ctx, &zfs.CreatePoolOptions{
	Name: "scratch",
	Properties: map[string]string{
		zpoolprops.Ashift:                   "12",
		zpoolprops.AutoTrim:                 "on",
		zpoolprops.Feature("async_destroy"): "enabled",
	},
	FilesystemProperties: map[string]string{
		zfsprops.Atime:       "off",
		zfsprops.CanMount:    "on",
		zfsprops.Compression: "lz4",
	},
	Mountpoint: "/mnt/scratch",
	Vdevs:      []string{"mirror", "/dev/sde", "/dev/sdf"},
})

Create and get a new dataset:

err = z.CreateDataset(ctx, &zfs.CreateDatasetOptions{
	Name: "scratch/http/cache",
	Properties: map[string]string{
		zfsprops.Compression: "off",
	},
	CreateParents: true,
})

ds, err = z.GetDataset(ctx, "scratch/http/cache")
fmt.Printf("Name: %s\n", ds.Name)
Name: scratch/http/cache

Set dataset quota to 100 GiB and turn on atime:

err = z.SetDatasetProperties(ctx, "scratch/http/cache", map[string]string{
	zfsprops.Quota: "100G",
	zfsprops.Atime: "on",
})

Documentation

Please see the Go Reference for documentation and examples.

License

MIT

# Packages

Package zfsprops is a helper package that privides a list of string constants for zfs native properties.
Package zpoolprops is a helper package that privides a list of string constants for zpool properties.

# Functions

Join joins the given parts with a "/" separator.
JoinTypes combines the given dataset types into a DatasetType value which can be used to query for datasets of multiple types.
New returns a new Manager instance which is used to perform all zfs and zpool operations.
No description provided by the author

# Constants

No description provided by the author
No description provided by the author
DestroyDeferDeletion indicates that the -d flag should be passed to zfs destroy.
DestroyForceUnmount indicates that the -f flag should be passed to zfs destroy.
DestroyRecursive indicates that the -r flag should be passed to zfs destroy.
DestroyRecursiveClones indicates that the -R flag should be passed to zfs destroy.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

CreateDatasetOptions are options for creating a new dataset.
CreatePoolOptions are options for creating a new zpool.
No description provided by the author
ImportPoolOptions are options for importing a pool.
Manager is used to perform all zfs and zpool operations.
No description provided by the author
Property represents a single ZFS property.

# Type aliases

No description provided by the author
DestroyDatasetFlag is a value that is passed to DestroyDataset to specify the destruction behavior for datasets.
Properties is a collection of ZFS properties, that includes typed accessor helper methods.