snapshot

package
v0.1.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: May 23, 2020 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const TimestampFormat = time.RFC3339Nano

TimestampFormat represents the format of timestamps used by zsm to identify snapshots.

Variables

This section is empty.

Functions

func AssertNameFormat

func AssertNameFormat(t *testing.T, fsName, snapName string) bool

AssertNameFormat asserts that the passed snapName has the expected format for a snapshot of a filesystem with name fsName.

func EqualCreateOptions

func EqualCreateOptions(t *testing.T, expectedOpts ...CreateOption) func([]CreateOption) bool

EqualCreateOptions returns a function that checks if the passed CreateOptions match the expected create options.

EqualCreateOptions is mainly intended for use with mock.MatchedBy.

func MustParseTime

func MustParseTime(t *testing.T, layout, value string) time.Time

MustParseTime parses the passed value as a time.Time according to layout. It fails the test if the value cannot be parsed.

func Transfer

func Transfer(targetFS string, dst ListerReceiver, src ListerSender) error

Transfer transfers all snapshots not already known on dst from src to dst.

Types

type BucketConfig

type BucketConfig [nIntervals]int

BucketConfig configures the buckets for retaining snapshots.

A value >0 for each of the elements of BucketConfig signals that each corresponding bucket should be filled with that many snapshots, each apart by at least the amount signaled by the bucket name.

Example:

If the element Minute is set to 5 the Minute bucket is to be filled with 5 snapshots at least a minute apart.

type CreateOption

type CreateOption func(*createOpts)

CreateOption modifies the way CreateSnapshot creates a snapshot of one or more ZFS file systems.

func ExcludeFileSystem

func ExcludeFileSystem(fsName string) CreateOption

ExcludeFileSystem marks the passed file System as excluded from creating snapshots.

func FromFileSystem

func FromFileSystem(fsName string) CreateOption

FromFileSystem makes CreateSnapshot create a snapshot of only the passed file system. If FileSystem is passed multiple times to CreateSnapshot it creates snapshots of all the passed file systems.

type Interval

type Interval int

Interval represents the interval between two consecutive snapshots.

const (
	Minute Interval = iota
	Hour
	Day
	Week
	Month
	Year
)

Intervals in which snapshots can be kept.

func (Interval) String

func (i Interval) String() string

type Lister

type Lister interface {
	ListSnapshots() ([]Name, error)
}

Lister defines the ListSnapshots method.

type ListerReceiver

type ListerReceiver interface {
	Lister
	Receiver
}

ListerReceiver defines a type that can list all snapshots known to it and can receive additional snapshots.

type ListerSender

type ListerSender interface {
	Lister
	Sender
}

ListerSender defines a type that can list all snapshots known to it and can send snapshots.

type Manager

type Manager struct {
	ZFS ZFSAdapter
}

Manager manages ZFS snapshots.

func (*Manager) CleanSnapshots

func (m *Manager) CleanSnapshots(cfg BucketConfig) error

CleanSnapshots removes all snapshots outdated according to BucketConfig.

func (*Manager) CreateSnapshots

func (m *Manager) CreateSnapshots(opts ...CreateOption) error

CreateSnapshots creates snapshots of the ZFS file system.

By default CreateSnapshots creates snapshots of all ZFS file systems available. This behavior can be modified by passing one or more CreateOptions.

func (*Manager) ListSnapshots

func (m *Manager) ListSnapshots() ([]Name, error)

ListSnapshots returns a list of snapshot names managed by zsm.

func (*Manager) ReceiveSnapshot

func (m *Manager) ReceiveSnapshot(targetFS string, name Name, r io.Reader) error

ReceiveSnapshot receives a snapshot with the passed name.

It writes the data read from r to the snapshot. ReceiveSnapshot returns an error if name.FileSystem does not exist, or if a snapshot with the same name already exists.

func (*Manager) SendSnapshot

func (m *Manager) SendSnapshot(name Name, w io.Writer, opts ...SendOption) error

SendSnapshot writes the snapshot identified by name to w.

By passing the Reference option only data changed between the passed reference and name is written to w.

type MockManager

type MockManager struct {
	mock.Mock

	ZFS string
	// contains filtered or unexported fields
}

MockManager is a mock for Manager and provides the same methods.

MockManager is useful across various packages. It is therefore defined once in the snapshot package and not in the packages, that use the functionality.

func (*MockManager) AssertCreateOptions

func (m *MockManager) AssertCreateOptions(t *testing.T) bool

AssertCreateOptions asserts that the expected send options were actually passed.

func (*MockManager) AssertSendOptions

func (m *MockManager) AssertSendOptions(t *testing.T) bool

AssertSendOptions asserts that the expected send options were actually passed.

func (*MockManager) CleanSnapshots

func (m *MockManager) CleanSnapshots(cfg BucketConfig) error

CleanSnapshots registers a call to CleanSnapshots.

func (*MockManager) CreateSnapshots

func (m *MockManager) CreateSnapshots(opts ...CreateOption) error

CreateSnapshots registers a call to CreateSnapshots.

func (*MockManager) ExpectCreateOptions

func (m *MockManager) ExpectCreateOptions(opts ...CreateOption)

ExpectCreateOptions sets the CreateOptions expected when CreateSnapshot is called.

func (*MockManager) ExpectSendOptions

func (m *MockManager) ExpectSendOptions(opts ...SendOption)

ExpectSendOptions sets the SendOptions expected when SendSnapshot is called.

func (*MockManager) ListSnapshots

func (m *MockManager) ListSnapshots() ([]Name, error)

ListSnapshots registers a call to ListSnapshots.

func (*MockManager) ReceiveSnapshot

func (m *MockManager) ReceiveSnapshot(targetFS string, name Name, r io.Reader) error

ReceiveSnapshot registers a call to ReceiveSnapshot.

func (*MockManager) SendSnapshot

func (m *MockManager) SendSnapshot(name Name, w io.Writer, opts ...SendOption) error

SendSnapshot registers a call to SendSnapshot.

type MockZFSAdapter

type MockZFSAdapter struct {
	mock.Mock
}

MockZFSAdapter mocks calls to the ZFS executable installed on the system.

func (*MockZFSAdapter) CreateSnapshot

func (m *MockZFSAdapter) CreateSnapshot(name string) error

CreateSnapshot registers a mock call to zfs snapshot

func (*MockZFSAdapter) Destroy

func (m *MockZFSAdapter) Destroy(name string) error

Destroy registers a call to zfs destroy.

func (*MockZFSAdapter) List

func (m *MockZFSAdapter) List(typ zfs.ListType) ([]string, error)

List registers a mock call to zfs list

func (*MockZFSAdapter) Receive

func (m *MockZFSAdapter) Receive(name string, r io.Reader) error

Receive registers a call to zfs receive.

func (*MockZFSAdapter) Send

func (m *MockZFSAdapter) Send(name, ref string, w io.Writer) error

Send registers a call to zfs send.

type Name

type Name struct {
	FileSystem string    `json:"fileSystem"`
	Timestamp  time.Time `json:"timestamp"`
}

Name represents a named snapshot created by zsm.

func FakeNames

func FakeNames(t *testing.T, end Name, delta Interval, n int) []Name

FakeNames creates n fake snapshots Names. Two consecutive names are delta apart. The last snapshot Name is end.

func MustParseName

func MustParseName(t *testing.T, name string) Name

MustParseName parses the passed snapshot name using ParseName. If ParseName returns false for its second argument, MustParseName fails the test.

func ParseName

func ParseName(name string) (Name, bool)

ParseName parses a string representing a snapshot into a Name.

func ParseNameJSON

func ParseNameJSON(data []byte) (Name, error)

ParseNameJSON parses a JSON representation of a name.

func ShuffleNamesC

func ShuffleNamesC(names []Name) []Name

ShuffleNamesC returns a shuffled copy of names.

func (Name) String

func (n Name) String() string

func (Name) ToJSON

func (n Name) ToJSON() ([]byte, error)

ToJSON converts the name to a JSON representation.

func (Name) ToJSONW

func (n Name) ToJSONW(w io.Writer) error

ToJSONW converts the name to a JSON representation and writes it to w.

type Receiver

type Receiver interface {
	ReceiveSnapshot(string, Name, io.Reader) error
}

Receiver defines the ReceiveSnapshot method.

type SendOption

type SendOption func(*sendOpts)

SendOption configures the way SendSnapshot sends a snapshot to a remote host.

func Reference

func Reference(name Name) SendOption

Reference sets the name of the reference snapshot when sending snapshots.

type Sender

type Sender interface {
	SendSnapshot(Name, io.Writer, ...SendOption) error
}

Sender defines the SendSnapshot method.

type ZFSAdapter

type ZFSAdapter interface {
	CreateSnapshot(string) error
	List(zfs.ListType) ([]string, error)
	Destroy(string) error
	Receive(string, io.Reader) error
	Send(string, string, io.Writer) error
}

ZFSAdapter represents a type which is capable on performing calls to ZFS on the underlying system.

Jump to

Keyboard shortcuts

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