go-zfs: github.com/mistifyio/go-zfs Index | Files

package zfs

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

Package zfs provides wrappers around the ZFS command line tools.

Index

Package Files

error.go utils.go utils_notsolaris.go zfs.go zpool.go

Constants

const (
    DatasetFilesystem = "filesystem"
    DatasetSnapshot   = "snapshot"
    DatasetVolume     = "volume"
)

ZFS dataset types, which can indicate if a dataset is a filesystem, snapshot, or volume.

const (
    DestroyDefault         DestroyFlag = 1 << iota
    DestroyRecursive                   = 1 << iota
    DestroyRecursiveClones             = 1 << iota
    DestroyDeferDeletion               = 1 << iota
    DestroyForceUmount                 = 1 << iota
)

Valid destroy options

const (
    ZpoolOnline   = "ONLINE"
    ZpoolDegraded = "DEGRADED"
    ZpoolFaulted  = "FAULTED"
    ZpoolOffline  = "OFFLINE"
    ZpoolUnavail  = "UNAVAIL"
    ZpoolRemoved  = "REMOVED"
)

ZFS zpool states, which can indicate if a pool is online, offline, degraded, etc. More information regarding zpool states can be found here: https://docs.oracle.com/cd/E19253-01/819-5461/gamno/index.html.

func SetLogger Uses

func SetLogger(l Logger)

SetLogger set a log handler to log all commands including arguments before they are executed

type ChangeType Uses

type ChangeType int

ChangeType is the type of inode change as reported by Diff

const (
    Removed ChangeType = iota
    Created
    Modified
    Renamed
)

Types of Changes

type Dataset Uses

type Dataset struct {
    Name          string
    Origin        string
    Used          uint64
    Avail         uint64
    Mountpoint    string
    Compression   string
    Type          string
    Written       uint64
    Volsize       uint64
    Logicalused   uint64
    Usedbydataset uint64
    Quota         uint64
    Referenced    uint64
}

Dataset is a ZFS dataset. A dataset could be a clone, filesystem, snapshot, or volume. The Type struct member can be used to determine a dataset's type.

The field definitions can be found in the ZFS manual: http://www.freebsd.org/cgi/man.cgi?zfs(8).

func CreateFilesystem Uses

func CreateFilesystem(name string, properties map[string]string) (*Dataset, error)

CreateFilesystem creates a new ZFS filesystem with the specified name and properties. A full list of available ZFS properties may be found here: https://www.freebsd.org/cgi/man.cgi?zfs(8).

func CreateVolume Uses

func CreateVolume(name string, size uint64, properties map[string]string) (*Dataset, error)

CreateVolume creates a new ZFS volume with the specified name, size, and properties. A full list of available ZFS properties may be found here: https://www.freebsd.org/cgi/man.cgi?zfs(8).

func Datasets Uses

func Datasets(filter string) ([]*Dataset, error)

Datasets returns a slice of ZFS datasets, regardless of type. A filter argument may be passed to select a dataset with the matching name, or empty string ("") may be used to select all datasets.

func Filesystems Uses

func Filesystems(filter string) ([]*Dataset, error)

Filesystems returns a slice of ZFS filesystems. A filter argument may be passed to select a filesystem with the matching name, or empty string ("") may be used to select all filesystems.

func GetDataset Uses

func GetDataset(name string) (*Dataset, error)

GetDataset retrieves a single ZFS dataset by name. This dataset could be any valid ZFS dataset type, such as a clone, filesystem, snapshot, or volume.

func ReceiveSnapshot Uses

func ReceiveSnapshot(input io.Reader, name string) (*Dataset, error)

ReceiveSnapshot receives a ZFS stream from the input io.Reader, creates a new snapshot with the specified name, and streams the input data into the newly-created snapshot.

func Snapshots Uses

func Snapshots(filter string) ([]*Dataset, error)

Snapshots returns a slice of ZFS snapshots. A filter argument may be passed to select a snapshot with the matching name, or empty string ("") may be used to select all snapshots.

func Volumes Uses

func Volumes(filter string) ([]*Dataset, error)

Volumes returns a slice of ZFS volumes. A filter argument may be passed to select a volume with the matching name, or empty string ("") may be used to select all volumes.

func (*Dataset) Children Uses

func (d *Dataset) Children(depth uint64) ([]*Dataset, error)

Children returns a slice of children of the receiving ZFS dataset. A recursion depth may be specified, or a depth of 0 allows unlimited recursion.

func (*Dataset) Clone Uses

func (d *Dataset) Clone(dest string, properties map[string]string) (*Dataset, error)

Clone clones a ZFS snapshot and returns a clone dataset. An error will be returned if the input dataset is not of snapshot type.

func (*Dataset) Destroy Uses

func (d *Dataset) Destroy(flags DestroyFlag) error

Destroy destroys a ZFS dataset. If the destroy bit flag is set, any descendents of the dataset will be recursively destroyed, including snapshots. If the deferred bit flag is set, the snapshot is marked for deferred deletion.

func (*Dataset) Diff Uses

func (d *Dataset) Diff(snapshot string) ([]*InodeChange, error)

Diff returns changes between a snapshot and the given ZFS dataset. The snapshot name must include the filesystem part as it is possible to compare clones with their origin snapshots.

func (*Dataset) GetProperty Uses

func (d *Dataset) GetProperty(key string) (string, error)

GetProperty returns the current value of a ZFS property from the receiving dataset. A full list of available ZFS properties may be found here: https://www.freebsd.org/cgi/man.cgi?zfs(8).

func (*Dataset) Mount Uses

func (d *Dataset) Mount(overlay bool, options []string) (*Dataset, error)

Mount mounts ZFS file systems.

func (*Dataset) Rename Uses

func (d *Dataset) Rename(name string, createParent bool, recursiveRenameSnapshots bool) (*Dataset, error)

Rename renames a dataset.

func (*Dataset) Rollback Uses

func (d *Dataset) Rollback(destroyMoreRecent bool) error

Rollback rolls back the receiving ZFS dataset to a previous snapshot. Optionally, intermediate snapshots can be destroyed. A ZFS snapshot rollback cannot be completed without this option, if more recent snapshots exist. An error will be returned if the input dataset is not of snapshot type.

func (*Dataset) SendSnapshot Uses

func (d *Dataset) SendSnapshot(output io.Writer) error

SendSnapshot sends a ZFS stream of a snapshot to the input io.Writer. An error will be returned if the input dataset is not of snapshot type.

func (*Dataset) SetProperty Uses

func (d *Dataset) SetProperty(key, val string) error

SetProperty sets a ZFS property on the receiving dataset. A full list of available ZFS properties may be found here: https://www.freebsd.org/cgi/man.cgi?zfs(8).

func (*Dataset) Snapshot Uses

func (d *Dataset) Snapshot(name string, recursive bool) (*Dataset, error)

Snapshot creates a new ZFS snapshot of the receiving dataset, using the specified name. Optionally, the snapshot can be taken recursively, creating snapshots of all descendent filesystems in a single, atomic operation.

func (*Dataset) Snapshots Uses

func (d *Dataset) Snapshots() ([]*Dataset, error)

Snapshots returns a slice of all ZFS snapshots of a given dataset.

func (*Dataset) Unmount Uses

func (d *Dataset) Unmount(force bool) (*Dataset, error)

Unmount unmounts currently mounted ZFS file systems.

type DestroyFlag Uses

type DestroyFlag int

DestroyFlag is the options flag passed to Destroy

type Error Uses

type Error struct {
    Err    error
    Debug  string
    Stderr string
}

Error is an error which is returned when the `zfs` or `zpool` shell commands return with a non-zero exit code.

func (Error) Error Uses

func (e Error) Error() string

Error returns the string representation of an Error.

type InodeChange Uses

type InodeChange struct {
    Change               ChangeType
    Type                 InodeType
    Path                 string
    NewPath              string
    ReferenceCountChange int
}

InodeChange represents a change as reported by Diff

type InodeType Uses

type InodeType int

InodeType is the type of inode as reported by Diff

const (
    BlockDevice InodeType = iota
    CharacterDevice
    Directory
    Door
    NamedPipe
    SymbolicLink
    EventPort
    Socket
    File
)

Types of Inodes

type Logger Uses

type Logger interface {
    Log(cmd []string)
}

Logger can be used to log commands/actions

type Zpool Uses

type Zpool struct {
    Name          string
    Health        string
    Allocated     uint64
    Size          uint64
    Free          uint64
    Fragmentation uint64
    ReadOnly      bool
    Freeing       uint64
    Leaked        uint64
    DedupRatio    float64
}

Zpool is a ZFS zpool. A pool is a top-level structure in ZFS, and can contain many descendent datasets.

func CreateZpool Uses

func CreateZpool(name string, properties map[string]string, args ...string) (*Zpool, error)

CreateZpool creates a new ZFS zpool with the specified name, properties, and optional arguments. A full list of available ZFS properties and command-line arguments may be found here: https://www.freebsd.org/cgi/man.cgi?zfs(8).

func GetZpool Uses

func GetZpool(name string) (*Zpool, error)

GetZpool retrieves a single ZFS zpool by name.

func ListZpools Uses

func ListZpools() ([]*Zpool, error)

ListZpools list all ZFS zpools accessible on the current system.

func (*Zpool) Datasets Uses

func (z *Zpool) Datasets() ([]*Dataset, error)

Datasets returns a slice of all ZFS datasets in a zpool.

func (*Zpool) Destroy Uses

func (z *Zpool) Destroy() error

Destroy destroys a ZFS zpool by name.

func (*Zpool) Snapshots Uses

func (z *Zpool) Snapshots() ([]*Dataset, error)

Snapshots returns a slice of all ZFS snapshots in a zpool.

Package zfs imports 10 packages (graph) and is imported by 693 packages. Updated 2020-03-25. Refresh now. Tools for package owners.