Documentation ¶
Index ¶
- Constants
- Variables
- func CleanupAbandondedImports() (cleaned int, err error)
- func EstimateSnapshotSize(si *snap.Info, usernames []string) (uint64, error)
- func Filename(snapshot *client.Snapshot) string
- func Import(ctx context.Context, id uint64, r io.Reader, flags *ImportFlags) (snapNames []string, err error)
- func Iter(ctx context.Context, f func(*Reader) error) error
- func LastSnapshotSetID() (uint64, error)
- func List(ctx context.Context, setID uint64, snapNames []string) ([]client.SnapshotSet, error)
- func MockUserLookup(newLookup func(string) (*user.User, error)) func()
- func Save(ctx context.Context, id uint64, si *snap.Info, cfg map[string]interface{}, ...) (*client.Snapshot, error)
- type DuplicatedSnapshotImportError
- type ImportFlags
- type Logf
- type Reader
- type RestoreState
- type SnapshotExport
Constants ¶
const ExtractFnameSetID = 0
ExtractFnameSetID can be passed to Open() to have set ID inferred from snapshot filename.
Variables ¶
var ErrCannotCancel = errors.New("cannot cancel: import already finished")
var ( // Stop is used to ask Iter to stop iteration, without it being an error. Stop = errors.New("stop iteration") )
Functions ¶
func CleanupAbandondedImports ¶
CleanupAbandondedImports 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 ¶
EstimateSnapshotSize calculates estimated size of the snapshot.
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 ¶
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 ¶
LastSnapshotSetID returns the highest set id number for the snapshots stored in snapshots directory; set ids are inferred from the filenames.
Types ¶
type DuplicatedSnapshotImportError ¶
func (DuplicatedSnapshotImportError) Error ¶
func (e DuplicatedSnapshotImportError) Error() string
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 ¶
A Reader is a snapshot that's been opened for reading.
func Open ¶
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) 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