snapshot

package
v1.22.9 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Overview

Package snapshot provides functionality for creating, managing, and restoring network snapshots with support for multi-node coordination, database flushing, and chunked uploads for GitHub.

Key Features:

  • Coordinated snapshots across multiple nodes
  • Database flushing for PebbleDB, BadgerDB, and LevelDB
  • Automatic chunking into 99MB pieces for GitHub upload
  • Checksum verification and metadata management
  • Parallel snapshot creation for minimal downtime

Usage:

manager := snapshot.NewSnapshotManager("~/.lux", "mainnet", 5)
err := manager.CreateSnapshot("production-backup")
if err != nil {
    // handle error
}

The snapshot system is designed to work with Lux networks of any size, providing consistent state capture for rollback and recovery scenarios.

Index

Constants

View Source
const ChunkSize = int64(99 * 1024 * 1024)

ChunkSize is the maximum size for a backup chunk (99MB to fit GitHub limits)

Variables

This section is empty.

Functions

func FormatBytes

func FormatBytes(bytes int64) string

FormatBytes formats bytes in human-readable form

func RotateLog

func RotateLog(logPath string, maxSize int64) (string, error)

RotateLog rotates a log file if it exceeds the size limit Returns the path to the rotated file, or empty string if no rotation needed

func TruncateLog

func TruncateLog(logPath string, keepBytes int64) error

TruncateLog truncates a log file to the last N bytes, preserving recent entries

Types

type CleanupConfig

type CleanupConfig struct {
	// MaxLogSize is the maximum size in bytes for netrunner-server.log files
	// Default: 100MB
	MaxLogSize int64

	// MaxLogAge is the maximum age for log files before rotation
	// Default: 7 days
	MaxLogAge time.Duration

	// MaxBackupAge is the maximum age for .backup.* directories
	// Default: 7 days
	MaxBackupAge time.Duration

	// MaxStaleRunAge is the maximum age for stale run directories
	// Default: 24 hours
	MaxStaleRunAge time.Duration

	// DryRun if true, only report what would be deleted
	DryRun bool

	// Verbose enables verbose output
	Verbose bool
}

CleanupConfig configures cleanup behavior

func DefaultCleanupConfig

func DefaultCleanupConfig() CleanupConfig

DefaultCleanupConfig returns sensible defaults

type CleanupResult

type CleanupResult struct {
	LogsDeleted        int
	LogBytesFreed      int64
	BackupsDeleted     int
	BackupBytesFreed   int64
	StaleRunsDeleted   int
	StaleRunBytesFreed int64
	Errors             []error
}

CleanupResult contains statistics from cleanup operation

func (CleanupResult) TotalBytesFreed

func (r CleanupResult) TotalBytesFreed() int64

TotalBytesFreed returns total bytes freed

type Part

type Part struct {
	Name   string `json:"name"`
	Bytes  int64  `json:"bytes"`
	SHA256 string `json:"sha256"`
}

Part represents a single file part of a split stream

type SnapshotEntry

type SnapshotEntry struct {
	Height uint64 `json:"height"`
	Since  uint64 `json:"since"`
	Parts  []Part `json:"parts"`
}

SnapshotEntry represents a backup entry (base or incremental)

type SnapshotInfo

type SnapshotInfo struct {
	Name        string
	Path        string
	Size        int64
	Incremental bool
	Created     time.Time
}

SnapshotInfo contains metadata about a snapshot

type SnapshotManager

type SnapshotManager struct {
	// contains filtered or unexported fields
}

SnapshotManager handles database snapshots

func NewSnapshotManager

func NewSnapshotManager(baseDir string) *SnapshotManager

NewSnapshotManager creates a new snapshot manager

func (*SnapshotManager) Cleanup

func (sm *SnapshotManager) Cleanup(cfg CleanupConfig) CleanupResult

Cleanup performs cleanup of logs, backups, and stale runs

func (*SnapshotManager) CreateBaseSnapshot

func (sm *SnapshotManager) CreateBaseSnapshot(
	network string,
	chainID uint64,
	db database.Database,
	height uint64,
	stateRoot string,
	snapshotID string,
) (*SnapshotManifest, error)

CreateBaseSnapshot creates a full base snapshot using streaming chunking

func (*SnapshotManager) CreateIncrementalSnapshot

func (sm *SnapshotManager) CreateIncrementalSnapshot(
	network string,
	chainID uint64,
	db database.Database,
	parent *SnapshotManifest,
	snapshotID string,
) (*SnapshotManifest, error)

CreateIncrementalSnapshot creates an incremental snapshot using streaming chunking

func (*SnapshotManager) CreateSnapshot

func (sm *SnapshotManager) CreateSnapshot(snapshotName string, incremental bool) error

CreateSnapshot creates a snapshot of all discovered local networks and nodes

func (*SnapshotManager) GetLatestManifest

func (sm *SnapshotManager) GetLatestManifest(network string, chainID uint64) (*SnapshotManifest, error)

... existing helpers ...

func (*SnapshotManager) GetLatestSnapshotDir

func (sm *SnapshotManager) GetLatestSnapshotDir(network string, chainID uint64) (string, error)

func (*SnapshotManager) GetSnapshotInfo

func (sm *SnapshotManager) GetSnapshotInfo(snapshotName string) (*SnapshotInfo, error)

GetSnapshotInfo returns information about a specific snapshot

func (*SnapshotManager) ListSnapshots

func (sm *SnapshotManager) ListSnapshots() ([]*SnapshotInfo, error)

ListSnapshots returns a list of all available snapshots

func (*SnapshotManager) RestoreChainSnapshot

func (sm *SnapshotManager) RestoreChainSnapshot(
	network string,
	chainID uint64,
	manifest *SnapshotManifest,
	dbDir string,
	snapshotID string,
) error

RestoreChainSnapshot restores a snapshot using streaming from chunks

func (*SnapshotManager) RestoreSnapshot

func (sm *SnapshotManager) RestoreSnapshot(snapshotName string) error

RestoreSnapshot restores a full snapshot (all networks/nodes)

func (*SnapshotManager) Squash

func (sm *SnapshotManager) Squash(network string, chainID uint64, snapshotName string) error

Squash combines base + incrementals into a new base

type SnapshotManifest

type SnapshotManifest struct {
	Network            string          `json:"network"`
	ChainID            uint64          `json:"chain_id"`
	Base               SnapshotEntry   `json:"base"`
	Incrementals       []SnapshotEntry `json:"incrementals"`
	StateRoot          string          `json:"state_root"`
	CreatedAt          string          `json:"created_at"`
	LastVersion        uint64          `json:"last_version"`
	PrevManifestSHA256 string          `json:"prev_manifest_sha256,omitempty"`
}

SnapshotManifest represents the manifest file for a snapshot

Jump to

Keyboard shortcuts

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