backup

package
v0.11.13 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2025 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyOptimizations

func ApplyOptimizations(ctx context.Context, logger *logging.Logger, root string, cfg OptimizationConfig) error

ApplyOptimizations executes the requested optimizations in sequence.

func CreateManifest

func CreateManifest(ctx context.Context, logger *logging.Logger, manifest *Manifest, outputPath string) error

CreateManifest creates a manifest file with archive metadata and checksum

func FormatBytes

func FormatBytes(bytes int64) string

FormatBytes formats bytes in human-readable format

func FormatDuration

func FormatDuration(d time.Duration) string

FormatDuration formats a duration in human-readable format

func GenerateChecksum

func GenerateChecksum(ctx context.Context, logger *logging.Logger, filePath string) (string, error)

GenerateChecksum calculates SHA256 checksum of a file

func VerifyChecksum

func VerifyChecksum(ctx context.Context, logger *logging.Logger, filePath, expectedChecksum string) (bool, error)

VerifyChecksum verifies a file against a manifest's checksum

func WithLookPathOverride

func WithLookPathOverride(fn func(string) (string, error)) func()

WithLookPathOverride temporaneamente sostituisce lookPath (per i test) e restituisce una funzione di ripristino da invocare con defer.

Types

type Archiver

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

Archiver handles tar archive creation with compression

func NewArchiver

func NewArchiver(logger *logging.Logger, config *ArchiverConfig) *Archiver

NewArchiver creates a new archiver

func (*Archiver) CompressionLevel

func (a *Archiver) CompressionLevel() int

CompressionLevel returns the current compression level (already normalized).

func (*Archiver) CompressionMode

func (a *Archiver) CompressionMode() string

CompressionMode returns the active compression mode (fast/standard/maximum/ultra).

func (*Archiver) CompressionThreads

func (a *Archiver) CompressionThreads() int

CompressionThreads returns the number of threads requested for compression.

func (*Archiver) CreateArchive

func (a *Archiver) CreateArchive(ctx context.Context, sourceDir, outputPath string) error

CreateArchive creates a compressed tar archive from a directory

func (*Archiver) EffectiveCompression

func (a *Archiver) EffectiveCompression() types.CompressionType

EffectiveCompression returns the compression algorithm currently in use.

func (*Archiver) EstimateCompressionRatio

func (a *Archiver) EstimateCompressionRatio() float64

EstimateCompressionRatio returns an estimated compression ratio for the compression type

func (*Archiver) GetArchiveExtension

func (a *Archiver) GetArchiveExtension() string

GetArchiveExtension returns the appropriate file extension for the compression type

func (*Archiver) GetArchiveSize

func (a *Archiver) GetArchiveSize(archivePath string) (int64, error)

GetArchiveSize returns the size of the archive in bytes

func (*Archiver) RequestedCompression

func (a *Archiver) RequestedCompression() types.CompressionType

RequestedCompression returns the compression algorithm requested via configuration.

func (*Archiver) ResolveCompression

func (a *Archiver) ResolveCompression() types.CompressionType

ResolveCompression ensures the configured compression is available and normalizes the compression level. If the requested algorithm is unavailable it falls back to gzip, keeping the caller informed via logs.

func (*Archiver) VerifyArchive

func (a *Archiver) VerifyArchive(ctx context.Context, archivePath string) error

VerifyArchive performs comprehensive verification of the created archive

type ArchiverConfig

type ArchiverConfig struct {
	Compression        types.CompressionType
	CompressionLevel   int // 1-9 for gzip, 0-9 for xz, 1-22 for zstd
	CompressionThreads int
	CompressionMode    string
	DryRun             bool
	EncryptArchive     bool
	AgeRecipients      []age.Recipient
}

ArchiverConfig holds configuration for archive creation

func GetDefaultArchiverConfig

func GetDefaultArchiverConfig() *ArchiverConfig

GetDefaultArchiverConfig returns default archiver configuration

func (*ArchiverConfig) Validate

func (a *ArchiverConfig) Validate() error

Validate checks if the archiver configuration is valid

type ArchiverDeps

type ArchiverDeps struct {
	LookPath       func(string) (string, error)
	CommandContext func(context.Context, string, ...string) *exec.Cmd
}

ArchiverDeps groups external dependencies used by Archiver.

type CollectionStats

type CollectionStats struct {
	FilesProcessed int64
	FilesFailed    int64
	DirsCreated    int64
	BytesCollected int64
}

CollectionStats tracks statistics during backup collection

type Collector

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

Collector handles backup data collection

func NewCollector

func NewCollector(logger *logging.Logger, config *CollectorConfig, tempDir string, proxType types.ProxmoxType, dryRun bool) *Collector

NewCollector creates a new backup collector

func NewCollectorWithDeps

func NewCollectorWithDeps(logger *logging.Logger, config *CollectorConfig, tempDir string, proxType types.ProxmoxType, dryRun bool, deps CollectorDeps) *Collector

NewCollectorWithDeps creates a collector with explicit dependency overrides (for testing).

func (*Collector) CollectAll

func (c *Collector) CollectAll(ctx context.Context) error

CollectAll performs full backup collection based on Proxmox type

func (*Collector) CollectPBSConfigs

func (c *Collector) CollectPBSConfigs(ctx context.Context) error

CollectPBSConfigs collects Proxmox Backup Server specific configurations

func (*Collector) CollectPVEConfigs

func (c *Collector) CollectPVEConfigs(ctx context.Context) error

CollectPVEConfigs collects Proxmox VE specific configurations

func (*Collector) CollectSystemInfo

func (c *Collector) CollectSystemInfo(ctx context.Context) error

CollectSystemInfo collects common system information (both PVE and PBS)

func (*Collector) GetStats

func (c *Collector) GetStats() *CollectionStats

GetStats returns current collection statistics

func (*Collector) IsClusteredPVE

func (c *Collector) IsClusteredPVE() bool

IsClusteredPVE returns true if the current PVE collection detected a cluster.

type CollectorConfig

type CollectorConfig struct {
	// PVE-specific collection options
	BackupVMConfigs         bool
	BackupClusterConfig     bool
	BackupPVEFirewall       bool
	BackupVZDumpConfig      bool
	BackupPVEACL            bool
	BackupPVEJobs           bool
	BackupPVESchedules      bool
	BackupPVEReplication    bool
	BackupPVEBackupFiles    bool
	BackupSmallPVEBackups   bool
	MaxPVEBackupSizeBytes   int64
	PVEBackupIncludePattern string
	BackupCephConfig        bool
	CephConfigPath          string

	// PBS-specific collection options
	BackupDatastoreConfigs bool
	BackupUserConfigs      bool
	BackupRemoteConfigs    bool
	BackupSyncJobs         bool
	BackupVerificationJobs bool
	BackupTapeConfigs      bool
	BackupPruneSchedules   bool
	BackupPxarFiles        bool

	// System collection options
	BackupNetworkConfigs    bool
	BackupAptSources        bool
	BackupCronJobs          bool
	BackupSystemdServices   bool
	BackupSSLCerts          bool
	BackupSysctlConfig      bool
	BackupKernelModules     bool
	BackupFirewallRules     bool
	BackupInstalledPackages bool
	BackupScriptDir         bool
	BackupCriticalFiles     bool
	BackupSSHKeys           bool
	BackupZFSConfig         bool
	BackupRootHome          bool
	BackupScriptRepository  bool
	BackupUserHomes         bool
	BackupConfigFile        bool
	SystemRootPrefix        string

	// PXAR scanning tuning
	PxarDatastoreConcurrency int
	PxarIntraConcurrency     int
	PxarScanFanoutLevel      int
	PxarScanMaxRoots         int
	PxarStopOnCap            bool
	PxarEnumWorkers          int
	PxarEnumBudgetMs         int
	PxarFileIncludePatterns  []string
	PxarFileExcludePatterns  []string

	// Exclude patterns (glob patterns to skip)
	ExcludePatterns []string

	CustomBackupPaths []string
	BackupBlacklist   []string

	// Paths and overrides
	ScriptRepositoryPath string
	ConfigFilePath       string
	PVEConfigPath        string
	PVEClusterPath       string
	CorosyncConfigPath   string
	VzdumpConfigPath     string
	PBSConfigPath        string
	PBSDatastorePaths    []string

	// PBS Authentication (auto-detected)
	PBSRepository  string
	PBSPassword    string
	PBSFingerprint string
}

CollectorConfig holds configuration for backup collection

func GetDefaultCollectorConfig

func GetDefaultCollectorConfig() *CollectorConfig

GetDefaultCollectorConfig returns default collection configuration

func (*CollectorConfig) Validate

func (c *CollectorConfig) Validate() error

Validate checks if the collector configuration is valid

type CollectorDeps

type CollectorDeps struct {
	LookPath          func(string) (string, error)
	RunCommandWithEnv func(context.Context, []string, string, ...string) ([]byte, error)
	RunCommand        func(context.Context, string, ...string) ([]byte, error)
	Stat              func(string) (os.FileInfo, error)
}

CollectorDeps allows injecting external dependencies for the Collector.

type CompressionError

type CompressionError struct {
	Algorithm string
	Err       error
}

CompressionError rappresenta un errore di compressione esterna (xz/zstd)

func (*CompressionError) Error

func (e *CompressionError) Error() string

func (*CompressionError) Unwrap

func (e *CompressionError) Unwrap() error

type FileSummary

type FileSummary struct {
	RelativePath string    `json:"relative_path"`
	SizeBytes    int64     `json:"size_bytes"`
	SizeHuman    string    `json:"size_human"`
	ModTime      time.Time `json:"mod_time"`
}

FileSummary represents metadata about a sampled file

type Manifest

type Manifest struct {
	ArchivePath      string    `json:"archive_path"`
	ArchiveSize      int64     `json:"archive_size"`
	SHA256           string    `json:"sha256"`
	CreatedAt        time.Time `json:"created_at"`
	CompressionType  string    `json:"compression_type"`
	CompressionLevel int       `json:"compression_level"`
	CompressionMode  string    `json:"compression_mode,omitempty"`
	ProxmoxType      string    `json:"proxmox_type"`
	ProxmoxTargets   []string  `json:"proxmox_targets,omitempty"`
	ProxmoxVersion   string    `json:"proxmox_version,omitempty"`
	Hostname         string    `json:"hostname"`
	ScriptVersion    string    `json:"script_version,omitempty"`
	EncryptionMode   string    `json:"encryption_mode,omitempty"`
	ClusterMode      string    `json:"cluster_mode,omitempty"`
}

Manifest represents backup archive metadata with checksums

func LoadManifest

func LoadManifest(manifestPath string) (*Manifest, error)

LoadManifest loads a manifest from a JSON file

type OptimizationConfig

type OptimizationConfig struct {
	EnableChunking            bool
	EnableDeduplication       bool
	EnablePrefilter           bool
	ChunkSizeBytes            int64
	ChunkThresholdBytes       int64
	PrefilterMaxFileSizeBytes int64
}

OptimizationConfig controls optional preprocessing steps executed before archiving.

func (OptimizationConfig) Enabled

func (c OptimizationConfig) Enabled() bool

Enabled returns true if at least one optimization is active.

Jump to

Keyboard shortcuts

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