backend

package
v0.0.0-...-263a040 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2024 License: GPL-3.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const ExtractFnameSetID = 0

ExtractFnameSetID can be passed to Open() to have set ID inferred from snapshot filename.

Variables

View Source
var ErrCannotCancel = errors.New("cannot cancel: import already finished")
View Source
var (
	// Stop is used to ask Iter to stop iteration, without it being an error.
	Stop = errors.New("stop iteration")
)

Functions

func CleanupAbandonedImports

func CleanupAbandonedImports() (cleaned int, err error)

CleanupAbandonedImports will clean any import that is in progress. This is meant to be called at startup of snapd before any real imports happen. It is not safe to run this concurrently with any other snapshot operation.

The amount of snapshots cleaned is returned and an error if one or more cleanups did not succeed.

func EstimateSnapshotSize

func EstimateSnapshotSize(si *snap.Info, usernames []string, dirOpts *dirs.SnapDirOptions) (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 Import

func Import(ctx context.Context, id uint64, r io.Reader, flags *ImportFlags) (snapNames []string, err error)

Import a snapshot from the export file format

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 LastSnapshotSetID

func LastSnapshotSetID() (uint64, error)

LastSnapshotSetID returns the highest set id number for the snapshots stored in snapshots directory; set ids are inferred from the filenames.

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, dynSnapshotOpts *snap.SnapshotOptions, dirOpts *dirs.SnapDirOptions) (*client.Snapshot, error)

Save a snapshot

Types

type DuplicatedSnapshotImportError

type DuplicatedSnapshotImportError struct {
	SetID     uint64
	SnapNames []string
}

func (DuplicatedSnapshotImportError) Error

type ImportFlags

type ImportFlags struct {
	// noDuplicatedImportCheck tells import not to check for existing snapshot
	// with same content hash (and not report DuplicatedSnapshotImportError).
	NoDuplicatedImportCheck bool
}

ImportFlags carries extra flags to drive import behavior.

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, setID uint64) (reader *Reader, e error)

Open a Snapshot given its full filename.

The returned reader will have its setID set to the value of the argument, or inferred from the snapshot filename if ExtractFnameSetID constant is passed.

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, opts *dirs.SnapDirOptions) (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