backend

package
v0.0.0-...-1a99902 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2020 License: GPL-3.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Stop is used to ask Iter to stop iteration, without it being an error.
	Stop = errors.New("stop iteration")
)

Functions

func EstimateSnapshotSize

func EstimateSnapshotSize(si *snap.Info, usernames []string) (uint64, error)

EstimateSnapshotSize calculates estimated size of the snapshot.

func Filename

func Filename(snapshot *client.Snapshot) string

Filename of the given client.Snapshot in this backend.

func Iter

func Iter(ctx context.Context, f func(*Reader) error) error

Iter loops over all snapshots in the snapshots directory, applying the given function to each. The snapshot will be closed after the function returns. If the function returns an error, iteration is stopped (and if the error isn't Stop, it's returned as the error of the iterator).

func List

func List(ctx context.Context, setID uint64, snapNames []string) ([]client.SnapshotSet, error)

List valid snapshots sets.

func MockUserLookup

func MockUserLookup(newLookup func(string) (*user.User, error)) func()

func Save

func Save(ctx context.Context, id uint64, si *snap.Info, cfg map[string]interface{}, usernames []string, flags *Flags) (*client.Snapshot, error)

Save a snapshot

Types

type Flags

type Flags struct {
	Auto bool
}

Flags encompasses extra flags for snapshots backend Save.

type Logf

type Logf func(format string, args ...interface{})

Logf is the type implemented by logging functions.

type Reader

type Reader struct {
	*os.File
	client.Snapshot
}

A Reader is a snapshot that's been opened for reading.

func Open

func Open(fn string) (reader *Reader, e error)

Open a Snapshot given its full filename.

If the returned error is nil, the caller must close the reader (or its file) when done with it.

If the returned error is non-nil, the returned Reader will be nil, *or* have a non-empty Broken; in the latter case its file will be closed.

func (*Reader) Check

func (r *Reader) Check(ctx context.Context, usernames []string) error

Check that the data contained in the snapshot matches its hashsums.

func (*Reader) Restore

func (r *Reader) Restore(ctx context.Context, current snap.Revision, usernames []string, logf Logf) (rs *RestoreState, e error)

Restore the data from the snapshot.

If successful this will replace the existing data (for the given revision, or the one in the snapshot) with that contained in the snapshot. It keeps track of the old data in the task so it can be undone (or cleaned up).

type RestoreState

type RestoreState struct {
	Done    bool     `json:"done,omitempty"`
	Created []string `json:"created,omitempty"`
	Moved   []string `json:"moved,omitempty"`
	// Config is here for convenience; this package doesn't touch it
	Config map[string]interface{} `json:"config,omitempty"`
}

RestoreState stores information that can be used to cleanly revert (or finish cleaning up) a snapshot Restore.

This is useful when a Restore is part of a chain of operations, and a later one failing necessitates undoing the Restore.

func (*RestoreState) Cleanup

func (rs *RestoreState) Cleanup()

Cleanup the backed up data from disk.

func (*RestoreState) Revert

func (rs *RestoreState) Revert()

Revert the backed up data: remove what was added, move back what was moved aside.

type SnapshotExport

type SnapshotExport struct {
	// contains filtered or unexported fields
}

func NewSnapshotExport

func NewSnapshotExport(ctx context.Context, setID uint64) (se *SnapshotExport, err error)

NewSnapshotExport will return a SnapshotExport structure. It must be Close()ed after use to avoid leaking file descriptors.

func (*SnapshotExport) Close

func (se *SnapshotExport) Close()

func (*SnapshotExport) Init

func (se *SnapshotExport) Init() error

Init will calculate the snapshot size. This can take some time so it should be called without any locks. The SnapshotExport keeps the FDs open so even files moved/deleted will be found.

func (*SnapshotExport) Size

func (se *SnapshotExport) Size() int64

func (*SnapshotExport) StreamTo

func (se *SnapshotExport) StreamTo(w io.Writer) error

Jump to

Keyboard shortcuts

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