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
- func FormatBytes(bytes int64) string
- func RotateLog(logPath string, maxSize int64) (string, error)
- func TruncateLog(logPath string, keepBytes int64) error
- type CleanupConfig
- type CleanupResult
- type Part
- type SnapshotEntry
- type SnapshotInfo
- type SnapshotManager
- func (sm *SnapshotManager) Cleanup(cfg CleanupConfig) CleanupResult
- func (sm *SnapshotManager) CreateBaseSnapshot(network string, chainID uint64, db database.Database, height uint64, ...) (*SnapshotManifest, error)
- func (sm *SnapshotManager) CreateIncrementalSnapshot(network string, chainID uint64, db database.Database, parent *SnapshotManifest, ...) (*SnapshotManifest, error)
- func (sm *SnapshotManager) CreateSnapshot(snapshotName string, incremental bool) error
- func (sm *SnapshotManager) GetLatestManifest(network string, chainID uint64) (*SnapshotManifest, error)
- func (sm *SnapshotManager) GetLatestSnapshotDir(network string, chainID uint64) (string, error)
- func (sm *SnapshotManager) GetSnapshotInfo(snapshotName string) (*SnapshotInfo, error)
- func (sm *SnapshotManager) ListSnapshots() ([]*SnapshotInfo, error)
- func (sm *SnapshotManager) RestoreChainSnapshot(network string, chainID uint64, manifest *SnapshotManifest, dbDir string, ...) error
- func (sm *SnapshotManager) RestoreSnapshot(snapshotName string) error
- func (sm *SnapshotManager) Squash(network string, chainID uint64, snapshotName string) error
- type SnapshotManifest
Constants ¶
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 ¶
FormatBytes formats bytes in human-readable form
func RotateLog ¶
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 ¶
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 ¶
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)
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