Documentation ¶
Overview ¶
Package zfs provides wrappers around the ZFS command line tools.
Index ¶
- Constants
- Variables
- func SetLogger(l Logger)
- type ChangeType
- type Dataset
- type DestroyFlag
- type Error
- type InodeChange
- type InodeType
- type Logger
- type SendFlag
- type ZfsH
- func (z *ZfsH) AbortReceive(name string) (*Dataset, error)
- func (z *ZfsH) Bookmark(d *Dataset, snapname string, bookname string, recursive bool) (*Dataset, error)
- func (z *ZfsH) Bookmarks(d *Dataset, depth int) ([]*Dataset, error)
- func (z *ZfsH) BookmarksByName(filter string, depth int) ([]*Dataset, error)
- func (z *ZfsH) Children(d *Dataset, depth uint64) ([]*Dataset, error)
- func (z *ZfsH) Clone(d *Dataset, dest string, properties map[string]string) (*Dataset, error)
- func (z *ZfsH) Close()
- func (z *ZfsH) CopyConfig(source, destination string) error
- func (z *ZfsH) CreateFilesystem(name string, properties map[string]string) (*Dataset, error)
- func (z *ZfsH) CreateVolume(name string, size uint64, properties map[string]string) (*Dataset, error)
- func (z *ZfsH) CreateZpool(name string, properties map[string]string, args ...string) (*Zpool, error)
- func (z *ZfsH) Datasets(datasettype string, filter string, depth int, recurse bool) ([]*Dataset, error)
- func (z *ZfsH) Destroy(d *Dataset, flags DestroyFlag) error
- func (z *ZfsH) DestroyZpool(zp *Zpool) error
- func (z *ZfsH) Diff(d *Dataset, snapshot string) ([]*InodeChange, error)
- func (z *ZfsH) Filesystems(filter string, depth int) ([]*Dataset, error)
- func (z *ZfsH) GetDataset(name string) (*Dataset, error)
- func (z *ZfsH) GetProperty(d *Dataset, key string) (string, error)
- func (z *ZfsH) GetZpool(name string) (*Zpool, error)
- func (z *ZfsH) InheritProperty(d *Dataset, property string) error
- func (z *ZfsH) ListZpools() ([]*Zpool, error)
- func (z *ZfsH) Lz4Send() bool
- func (z *ZfsH) Mount(d *Dataset, overlay bool, options []string) (*Dataset, error)
- func (z *ZfsH) ReceiveSnapshot(input io.Reader, name, uncompress string, props []string) (*Dataset, error)
- func (z *ZfsH) Rename(d *Dataset, name string, createParent bool, recursiveRenameSnapshots bool) (*Dataset, error)
- func (z *ZfsH) RenameDataset(d0 string, d1 string) error
- func (z *ZfsH) RenameFile(source, destination string) error
- func (z *ZfsH) Rollback(d *Dataset, destroyMoreRecent bool) error
- func (z *ZfsH) Sed(match, file string) error
- func (z *ZfsH) SendSnapshot(ds0, ds1 string, output io.Writer, sendflags SendFlag, compress string) error
- func (z *ZfsH) SetProperty(d *Dataset, key, val string) error
- func (z *ZfsH) Snapshot(d *Dataset, name string, recursive bool) (*Dataset, error)
- func (z *ZfsH) Snapshots(d *Dataset, depth int) ([]*Dataset, error)
- func (z *ZfsH) SnapshotsByName(filter string, depth int) ([]*Dataset, error)
- func (z *ZfsH) TestLz4SendSupport()
- func (z *ZfsH) Unmount(d *Dataset, force bool) (*Dataset, error)
- func (z *ZfsH) Volumes(filter string, depth int) ([]*Dataset, error)
- type Zpool
Constants ¶
const ( DatasetFilesystem = "filesystem" DatasetSnapshot = "snapshot" DatasetVolume = "volume" DatasetBookmark = "bookmark" DatasetAll = "all" )
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 ( SendDefault SendFlag = 1 << iota SendIncremental = 1 << iota SendRecursive = 1 << iota SendIntermediate = 1 << iota SendLz4 = 1 << iota SendEmbeddedData = 1 << iota SendWithToken = 1 << iota )
const ( ZpoolOnline = "ONLINE" ZpoolDegraded = "DEGRADED" ZpoolFaulted = "FAULTED" ZpoolOffline = "OFFLINE" 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.
Variables ¶
var DsPropList = []string{"name", "origin", "used", "available", "mountpoint", "compression", "type", "volsize", "quota", "written", "logicalused", "receive_resume_token", "compressratio", "usedbysnapshots", "creation", "encryption", "guid", "zsync:from", "zsync:host", "zsync:date"}
List of ZFS properties to retrieve from zfs list command on a non-Solaris platform
var ZpoolPropList = []string{"name", "health", "allocated", "size", "free"}
List of Zpool properties to retrieve from zpool list command on a non-Solaris platform
Functions ¶
Types ¶
type ChangeType ¶
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 ¶
type Dataset struct { Name string Origin string Used string Avail string Mountpoint string Compression string Type string Written string Volsize string Logicalused string Quota string ReceiveResumeToken string Compressratio string Usedbysnapshots string Creation string Encryption string Guid string ZsFrom string ZsHost string ZsDate string }
Dataset is a ZFS dataset. A dataset could be a clone, filesystem, snapshot, bookmark 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 (*Dataset) DataSetName ¶
type Error ¶
Error is an error which is returned when the `zfs` or `zpool` shell commands return with a non-zero exit code.
type InodeChange ¶
type InodeChange struct { Change ChangeType Type InodeType Path string NewPath string ReferenceCountChange int }
InodeChange represents a change as reported by Diff
type Logger ¶
type Logger interface {
Log(cmd []string)
}
Logger can be used to log commands/actions
type ZfsH ¶
type ZfsH struct { Local bool // contains filtered or unexported fields }
zfs handle used to redirect command to local or remote host over ssh
func NewLocalHandle ¶
func NewLocalHandle() *ZfsH
func NewSSHHandle ¶
func (*ZfsH) AbortReceive ¶
Mount mounts ZFS file systems.
func (*ZfsH) Bookmark ¶
func (z *ZfsH) Bookmark(d *Dataset, snapname string, bookname 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 (*ZfsH) BookmarksByName ¶
Bookmarks returns a slice of ZFS bookmarks. A filter argument may be passed to select a bookmark with the matching name, or empty string ("") may be used to select all bookmarks.
func (*ZfsH) Children ¶
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 (*ZfsH) Clone ¶
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 (*ZfsH) CopyConfig ¶
func (*ZfsH) CreateFilesystem ¶
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 (*ZfsH) CreateVolume ¶
func (z *ZfsH) 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 (*ZfsH) CreateZpool ¶
func (z *ZfsH) 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 (*ZfsH) Datasets ¶
func (z *ZfsH) Datasets(datasettype string, filter string, depth int, recurse bool) ([]*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 (*ZfsH) Destroy ¶
func (z *ZfsH) Destroy(d *Dataset, 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 (*ZfsH) DestroyZpool ¶
Destroy destroys a ZFS zpool by name.
func (*ZfsH) Diff ¶
func (z *ZfsH) Diff(d *Dataset, 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 (*ZfsH) Filesystems ¶
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 (*ZfsH) GetDataset ¶
GetDataset retrieves a single ZFS dataset by name. This dataset could be any valid ZFS dataset type, such as a clone, filesystem, snapshot, bookmark or volume.
func (*ZfsH) GetProperty ¶
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 (*ZfsH) ListZpools ¶
ListZpools list all ZFS zpools accessible on the current system.
func (*ZfsH) ReceiveSnapshot ¶
func (z *ZfsH) ReceiveSnapshot(input io.Reader, name, uncompress string, props []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. name destination dataset name uncompress uncompress prog if != "" (ex. lzop -d)
func (*ZfsH) Rename ¶
func (z *ZfsH) Rename(d *Dataset, name string, createParent bool, recursiveRenameSnapshots bool) (*Dataset, error)
Rename renames a dataset.
func (*ZfsH) RenameFile ¶
func (*ZfsH) Rollback ¶
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 (*ZfsH) SendSnapshot ¶
func (z *ZfsH) SendSnapshot(ds0, ds1 string, output io.Writer, sendflags SendFlag, compress string) 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. ds0 source snapshot ds1 previous snapshot used when sendflags is SendIncremental compression prog to pipe through if != "" (ex. lzop)
func (*ZfsH) SetProperty ¶
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 (*ZfsH) Snapshot ¶
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 (*ZfsH) SnapshotsByName ¶
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 (*ZfsH) TestLz4SendSupport ¶
func (z *ZfsH) TestLz4SendSupport()