zfs

package module
v3.1.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 1, 2022 License: Apache-2.0 Imports: 9 Imported by: 2

README

Go Wrapper for ZFS

Simple wrappers for ZFS command line tools.

This repository was initially created as a fork of mistifyio/go-zfs. After a while I decided that I really don't like how that library was designed. I decided to redo almost everything, remove functionality I don't need and add missing parts I do.

To learn how to use the library look at the unit tests located in ./zfs_test.go and ./zpool_test.go.

Documentation

Overview

Package zfs provides wrappers around the ZFS command line tools.

Package zfs provides wrappers around the ZFS command line tools.

Index

Constants

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

Valid destroy options

Variables

This section is empty.

Functions

This section is empty.

Types

type CloneOptions added in v3.1.0

type CloneOptions struct {
	Properties map[string]string
}

CloneOptions stores options passed to Clone method

type CreateFilesystemOptions added in v3.1.0

type CreateFilesystemOptions struct {
	Properties map[string]string
	Password   string
}

CreateFilesystemOptions stores options passed to CreateFilesystem function

type DestroyFlag

type DestroyFlag int

DestroyFlag is the options flag passed to Destroy

type Filesystem

type Filesystem struct {
	Info Info
}

Filesystem is a ZFS filesystem

func CreateFilesystem

func CreateFilesystem(ctx context.Context, name string, options CreateFilesystemOptions) (*Filesystem, 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 Filesystems

func Filesystems(ctx context.Context) ([]*Filesystem, 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 GetFilesystem

func GetFilesystem(ctx context.Context, name string) (*Filesystem, error)

GetFilesystem retrieves a single ZFS filesystem by name

func (*Filesystem) Children

func (d *Filesystem) Children(ctx context.Context) ([]*Filesystem, error)

Children returns a slice of children of the receiving ZFS dataset.

func (*Filesystem) Destroy

func (d *Filesystem) Destroy(ctx context.Context, 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 (*Filesystem) GetProperty

func (d *Filesystem) GetProperty(ctx context.Context, key string) (string, bool, 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 (*Filesystem) LoadKey

func (d *Filesystem) LoadKey(ctx context.Context, password string) error

LoadKey loads encryption key for dataset

func (*Filesystem) Mount

func (d *Filesystem) Mount(ctx context.Context) error

Mount mounts ZFS filesystem

func (*Filesystem) SetProperty

func (d *Filesystem) SetProperty(ctx context.Context, 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 (*Filesystem) Snapshot

func (d *Filesystem) Snapshot(ctx context.Context, name string) (*Snapshot, 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 (*Filesystem) Snapshots

func (d *Filesystem) Snapshots(ctx context.Context) ([]*Snapshot, error)

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

func (*Filesystem) UnloadKey

func (d *Filesystem) UnloadKey(ctx context.Context) error

UnloadKey unloads encryption key for dataset

func (*Filesystem) Unmount

func (d *Filesystem) Unmount(ctx context.Context) error

Unmount unmounts ZFS filesystem

type Info

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

Info contains dataset info

type Pool added in v3.0.2

type Pool struct {
	Name string
}

Pool represents ZPool

func GetPool added in v3.0.2

func GetPool(ctx context.Context, name string) (*Pool, error)

GetPool returns ZPool by name

func ImportPool added in v3.0.2

func ImportPool(ctx context.Context, name string) (*Pool, error)

ImportPool imports ZPool

func Pools added in v3.0.2

func Pools(ctx context.Context) ([]*Pool, error)

Pools returns list of imported ZPools

func (*Pool) Export added in v3.0.2

func (p *Pool) Export(ctx context.Context) error

Export exports ZPool

type SendOptions added in v3.1.0

type SendOptions struct {
	Raw           bool
	Properties    bool
	IncrementFrom *Snapshot
}

SendOptions is the set of options available for Send command

type Snapshot

type Snapshot struct {
	Info Info
}

Snapshot is a ZFS snapshot

func GetSnapshot

func GetSnapshot(ctx context.Context, name string) (*Snapshot, error)

GetSnapshot retrieves a single ZFS snapshot by name

func ReceiveSnapshot

func ReceiveSnapshot(ctx context.Context, input io.ReadCloser, name string) (*Snapshot, 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

func Snapshots(ctx context.Context) ([]*Snapshot, 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 (*Snapshot) Clone

func (d *Snapshot) Clone(ctx context.Context, dest string, options CloneOptions) (*Filesystem, error)

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

func (*Snapshot) Destroy

func (d *Snapshot) Destroy(ctx context.Context, 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 (*Snapshot) GetProperty

func (d *Snapshot) GetProperty(ctx context.Context, key string) (string, bool, 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 (*Snapshot) Hold added in v3.0.1

func (d *Snapshot) Hold(ctx context.Context, tag string) error

Hold holds the snapshot

func (*Snapshot) Holds added in v3.0.1

func (d *Snapshot) Holds(ctx context.Context) ([]string, error)

Holds returns holds on snapshot

func (*Snapshot) Release added in v3.0.1

func (d *Snapshot) Release(ctx context.Context, tag string) error

Release releases the snapshot

func (*Snapshot) Rollback

func (d *Snapshot) Rollback(ctx context.Context) error

Rollback rolls back the receiving ZFS filesystem to a previous snapshot. Intermediate snapshots can be destroyed.

func (*Snapshot) Send

func (d *Snapshot) Send(ctx context.Context, options SendOptions, output io.WriteCloser) error

Send 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 (*Snapshot) SetProperty

func (d *Snapshot) SetProperty(ctx context.Context, 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).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL