Documentation
¶
Index ¶
- Constants
- Variables
- func Backup(dst io.WriteSeeker, src io.Reader, name string, sizeBytes int64, ...) (checksum string, err error)
- func RestoreImage(dst *os.File, src io.Reader, meta *Meta) error
- func WriteHeader(w io.Writer, meta *Meta) error
- type BackupTarget
- type DiskCreator
- type DiskNotFoundError
- type DiskResolver
- type DiskState
- type LeaseState
- type Meta
- type RestoreOption
- type RestoreTarget
- type VolumeState
Constants ¶
const ( StatusDeleting = "DELETING" LeaseStatusBound = "BOUND" )
const FormatVersion uint32 = 1
FormatVersion is the current snapshot format version.
Variables ¶
var Magic = [4]byte{'M', 'I', 'R', 'N'}
Magic is the file magic for miren snapshot files.
Functions ¶
func Backup ¶
func Backup(dst io.WriteSeeker, src io.Reader, name string, sizeBytes int64, filesystem string) (checksum string, err error)
Backup reads the disk image from src, computes its SHA-256 checksum, and writes a complete snapshot (header + zstd-compressed data) to dst. It uses a TeeReader to hash and compress in a single pass, then seeks back to rewrite the header with the final checksum. It returns the checksum of the uncompressed image data.
func RestoreImage ¶
RestoreImage reads zstd-compressed data from src, decompresses it, and writes to dst using sparse-aware writes. The src stream should be positioned after the snapshot header (i.e., at the start of compressed data). The SHA-256 checksum of the decompressed data is verified against meta.Checksum.
Types ¶
type BackupTarget ¶
type BackupTarget struct {
Name string
Filesystem string
ImagePath string
// VolumeID is the node-local volume identifier.
VolumeID string
// CloudVolumeID identifies the volume in miren.cloud, for backups sent
// there. Empty means the disk has not been registered with a cloud, so
// there is nowhere to upload to.
CloudVolumeID string
}
BackupTarget contains resolved and validated information needed to perform a disk backup.
func PrepareBackup ¶
func PrepareBackup(ctx context.Context, resolver DiskResolver, name string, dataPath string) (*BackupTarget, error)
PrepareBackup resolves disk entities and validates the disk is in a state suitable for backup.
type DiskCreator ¶
type DiskCreator interface {
CreateDiskAndVolume(ctx context.Context, name string, sizeBytes int64, filesystem string, dataPath string) (*RestoreTarget, error)
}
DiskCreator can create disk and volume entities for restore.
type DiskNotFoundError ¶ added in v0.17.0
type DiskNotFoundError struct {
Name string
}
DiskNotFoundError reports that no disk answers to a name.
It is a distinct type because "there is no such disk" and "I could not find out" call for opposite responses. Callers act on the first by creating the disk, or by reporting that there is nothing to recover. Acting on the second the same way turns a moment of entity-store trouble into a duplicate disk.
func (DiskNotFoundError) Error ¶ added in v0.17.0
func (e DiskNotFoundError) Error() string
type DiskResolver ¶
type DiskResolver interface {
FindDisk(ctx context.Context, name string) (*DiskState, error)
FindVolume(ctx context.Context, diskID string) (*VolumeState, error)
FindLeases(ctx context.Context, diskID string) ([]LeaseState, error)
}
DiskResolver resolves disk-related entities from the entity store.
type LeaseState ¶
LeaseState holds the state of a disk lease entity.
type Meta ¶
type Meta struct {
Name string `json:"name"`
SizeBytes int64 `json:"size_bytes"`
Filesystem string `json:"filesystem"`
Timestamp time.Time `json:"timestamp"`
Checksum string `json:"checksum"` // SHA-256 hex
Version uint32 `json:"version"`
}
Meta holds the metadata stored in a snapshot header.
type RestoreOption ¶
type RestoreOption func(*restoreConfig)
RestoreOption configures PrepareRestore behavior.
func WithCreator ¶
func WithCreator(c DiskCreator, sizeBytes int64, filesystem string) RestoreOption
WithCreator enables auto-creation of disk entities if they don't exist.
type RestoreTarget ¶
type RestoreTarget struct {
Name string
ImagePath string
Created bool // true if the disk was freshly created (no --force needed)
Finalize func(ctx context.Context) error // called after image is written to complete entity setup
Cleanup func(ctx context.Context) error // called on failure to remove entities created during restore
}
RestoreTarget contains resolved and validated information needed to perform a disk restore.
func PrepareRestore ¶
func PrepareRestore(ctx context.Context, resolver DiskResolver, name string, dataPath string, opts ...RestoreOption) (*RestoreTarget, error)
PrepareRestore resolves disk entities and validates the disk is in a state suitable for restore (not deleting, no bound leases). If the disk doesn't exist and creator is non-nil, it creates the disk and volume entities. If creator is nil and the disk doesn't exist, it returns an error.
type VolumeState ¶
type VolumeState struct {
// VolumeID is the node-local identifier. It names the volume's directory,
// so it is deliberately separate from the cloud's id for the same volume.
VolumeID string
// CloudVolumeID identifies this volume in miren.cloud, empty until the disk
// controller has registered it there.
CloudVolumeID string
ImagePath string
}
VolumeState holds the state of a disk volume entity.