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 DiskResolver
- type DiskState
- type LeaseState
- type Meta
- type RestoreOption
- type RestoreTarget
- type VolumeState
Constants ¶
const ( StatusDeleting = "DELETING" StatusAttached = "ATTACHED" 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 ¶
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 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 ¶
VolumeState holds the state of a disk volume entity.