snapshot

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: May 20, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SnapshotJSONName = "snapshot.json"
	EnvelopeVersion  = 1
)

Variables

View Source
var ErrEnvelopeMissing = errors.New("snapshot envelope missing")

ErrEnvelopeMissing wraps the not-found case so callers can render a dir-specific error instead of a raw open failure.

View Source
var ErrNotFound = errors.New("snapshot not found")

Functions

func MarshalEnvelope added in v0.4.0

func MarshalEnvelope(cfg types.SnapshotConfig) ([]byte, error)

MarshalEnvelope returns the indented snapshot.json bytes for cfg.

func ReadSnapshotEnvelope added in v0.3.9

func ReadSnapshotEnvelope(dir string) (types.SnapshotConfig, error)

ReadSnapshotEnvelope reads <dir>/snapshot.json into a SnapshotConfig.

func WriteSnapshotEnvelope added in v0.3.9

func WriteSnapshotEnvelope(dir string, cfg types.SnapshotConfig) error

WriteSnapshotEnvelope writes <dir>/snapshot.json atomically so a concurrent reader can't see a partial write.

Types

type CompressedExporter added in v0.2.8

type CompressedExporter interface {
	ExportCompressed(ctx context.Context, ref string) (io.ReadCloser, error)
}

CompressedExporter is an optional interface for backends that support exporting with compression (e.g. gzip). The default Export produces raw tar.

type Direct

type Direct interface {
	DataDir(ctx context.Context, ref string) (string, types.SnapshotConfig, error)
}

Direct is an optional interface for snapshot backends that expose the local data directory for per-file handling (hardlink, reflink, etc.).

type DirectoryExporter added in v0.3.9

type DirectoryExporter interface {
	ExportToDir(ctx context.Context, ref, dir string) error
}

DirectoryExporter exports into a target dir with snapshot.json so rsync/NFS workflows skip the tar round-trip. Pairs with `vm clone --from-dir`.

type Snapshot

type Snapshot interface {
	Type() string

	// Create persists a snapshot from the given config and data stream, returning the snapshot ID.
	Create(ctx context.Context, cfg *types.SnapshotConfig, stream io.Reader) (string, error)
	// List returns all snapshots.
	List(ctx context.Context) ([]*types.Snapshot, error)
	// Inspect returns a single snapshot by ID or name.
	Inspect(ctx context.Context, ref string) (*types.Snapshot, error)
	// Delete removes snapshots by ID or name. Returns the list of actually deleted IDs.
	Delete(ctx context.Context, refs []string) ([]string, error)
	// Restore restores a snapshot by ID or name, returning the snapshot config and a data stream.
	Restore(ctx context.Context, ref string) (types.SnapshotConfig, io.ReadCloser, error)

	// Export streams the snapshot as a raw tar archive.
	// The archive includes a snapshot.json metadata entry followed by data files.
	Export(ctx context.Context, ref string) (io.ReadCloser, error)
	// Import reads a snapshot tar (gzip auto-detected); non-empty name/description override the envelope.
	Import(ctx context.Context, r io.Reader, name, description string) (string, error)

	RegisterGC(*gc.Orchestrator)
}

Snapshot manages snapshot lifecycle and storage.

type SnapshotIndex

type SnapshotIndex struct {
	Snapshots map[string]*SnapshotRecord `json:"snapshots"`
	Names     map[string]string          `json:"names"` // name → snapshot ID
}

SnapshotIndex is the top-level DB structure for the snapshot module.

func (*SnapshotIndex) Init

func (idx *SnapshotIndex) Init()

Init implements storage.Initer.

func (*SnapshotIndex) Resolve

func (idx *SnapshotIndex) Resolve(ref string) (string, error)

Resolve resolves a ref (exact ID, name, or ID prefix ≥3 chars) to a full snapshot ID.

func (*SnapshotIndex) ResolveMany

func (idx *SnapshotIndex) ResolveMany(refs []string) ([]string, error)

ResolveMany batch-resolves refs to exact snapshot IDs, deduplicating results.

type SnapshotRecord

type SnapshotRecord struct {
	types.Snapshot
	DataDir        string    `json:"data_dir,omitempty"`
	SizeBytes      int64     `json:"size_bytes,omitempty"`
	Pending        bool      `json:"pending,omitempty"` // true while Create is in progress
	LastAccessedAt time.Time `json:"last_accessed_at,omitzero"`
}

SnapshotRecord is the persisted record for a single snapshot.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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