config

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultEnvTemplate

func DefaultEnvTemplate() string

DefaultEnvTemplate returns the embedded configuration template used to bootstrap new installations.

Types

type Config

type Config struct {
	// General settings
	BackupEnabled            bool
	DebugLevel               types.LogLevel
	UseColor                 bool
	ColorizeStepLogs         bool
	EnableGoBackup           bool
	ProfilingEnabled         bool
	BaseDir                  string
	DryRun                   bool
	DisableNetworkPreflight  bool
	SecurityCheckEnabled     bool
	AbortOnSecurityIssues    bool
	AutoUpdateHashes         bool
	AutoFixPermissions       bool
	ContinueOnSecurityIssues bool
	SuspiciousProcesses      []string
	SafeBracketProcesses     []string
	SafeKernelProcesses      []string
	BackupUser               string
	BackupGroup              string
	SetBackupPermissions     bool

	// Compression settings
	CompressionType    types.CompressionType
	CompressionLevel   int
	CompressionThreads int
	CompressionMode    string

	// Safety settings
	MinDiskPrimaryGB   float64
	MinDiskSecondaryGB float64
	MinDiskCloudGB     float64
	SafetyFactor       float64

	// Optimization settings
	EnableSmartChunking    bool
	EnableDeduplication    bool
	EnablePrefilter        bool
	ChunkSizeMB            int
	ChunkThresholdMB       int
	PrefilterMaxFileSizeMB int

	// Paths
	BackupPath       string
	LogPath          string
	SecondaryLogPath string
	CloudLogPath     string
	LockPath         string
	SecureAccount    string
	ConfigPath       string

	// Storage settings
	SecondaryEnabled      bool
	SecondaryPath         string
	CloudEnabled          bool
	CloudRemote           string
	CloudRemotePath       string
	CloudUploadMode       string
	CloudParallelJobs     int
	CloudParallelVerify   bool
	CloudWriteHealthCheck bool

	// Rclone settings with comprehensible timeout names
	// RcloneTimeoutConnection: timeout for checking if remote is accessible (default: 30s)
	// RcloneTimeoutOperation: timeout for full upload/download operations (default: 300s)
	RcloneTimeoutConnection int
	RcloneTimeoutOperation  int
	RcloneBandwidthLimit    string
	RcloneTransfers         int
	RcloneRetries           int
	RcloneVerifyMethod      string // "primary" or "alternative"
	RcloneFlags             []string

	// Retention settings (applied to both backups and logs)
	LocalRetentionDays     int
	SecondaryRetentionDays int
	CloudRetentionDays     int
	MaxLocalBackups        int
	MaxSecondaryBackups    int
	MaxCloudBackups        int

	// Retention policy selector ("simple" or "gfs")
	RetentionPolicy string

	// GFS (Grandfather-Father-Son) retention settings
	// If ANY of these is > 0, GFS retention is enabled (overrides simple retention)
	RetentionDaily   int // Keep backups from last N days (0 = disabled)
	RetentionWeekly  int // Keep N weekly backups, one per week (0 = disabled)
	RetentionMonthly int // Keep N monthly backups, one per month (0 = disabled)
	RetentionYearly  int // Keep N yearly backups, one per year (0 = keep all yearly)

	// Batch deletion settings (cloud storage)
	CloudBatchSize  int // Number of files to delete per batch (default: 20)
	CloudBatchPause int // Pause in seconds between batches (default: 1)

	// Bundle settings for associated files
	BundleAssociatedFiles bool // Bundle .tar.xz + .sha256 + .metadata into single archive
	EncryptArchive        bool
	AgeRecipients         []string
	AgeRecipientFile      string

	// Telegram Notifications
	TelegramEnabled       bool
	TelegramBotType       string // "personal" or "centralized"
	TelegramBotToken      string // For personal mode
	TelegramChatID        string // For personal mode
	TelegramServerAPIHost string // For centralized mode
	ServerID              string // Server identifier for centralized mode

	// Email Notifications
	EmailEnabled          bool
	EmailDeliveryMethod   string // "relay", "sendmail", or "pmf"
	EmailFallbackSendmail bool
	EmailRecipient        string // Single recipient, empty = auto-detect
	EmailFrom             string

	// Gotify Notifications
	GotifyEnabled         bool
	GotifyServerURL       string
	GotifyToken           string
	GotifyPrioritySuccess int
	GotifyPriorityWarning int
	GotifyPriorityFailure int

	// Cloud Relay Configuration (hardcoded for compatibility)
	CloudflareWorkerURL   string
	CloudflareWorkerToken string
	CloudflareHMACSecret  string
	WorkerTimeout         int // seconds
	WorkerMaxRetries      int
	WorkerRetryDelay      int // seconds

	// Webhook Notifications
	WebhookEnabled       bool
	WebhookEndpointNames []string // List of endpoint names to configure
	WebhookDefaultFormat string   // Default format for all endpoints
	WebhookTimeout       int      // Timeout in seconds
	WebhookMaxRetries    int      // Max retry attempts
	WebhookRetryDelay    int      // Delay between retries in seconds

	// Metrics
	MetricsEnabled bool
	MetricsPath    string

	// Security features
	CheckNetworkSecurity bool
	CheckFirewall        bool
	CheckOpenPorts       bool
	SuspiciousPorts      []int
	PortWhitelist        []string

	// Collector options
	ExcludePatterns []string

	// 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
	PxarDatastoreConcurrency int
	PxarIntraConcurrency     int
	PxarScanFanoutLevel      int
	PxarScanMaxRoots         int
	PxarStopOnCap            bool
	PxarEnumWorkers          int
	PxarEnumBudgetMs         int
	PxarFileIncludePatterns  []string
	PxarFileExcludePatterns  []string

	// 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
	PVEConfigPath           string
	PBSConfigPath           string
	PVEClusterPath          string
	CorosyncConfigPath      string
	VzdumpConfigPath        string
	PBSDatastorePaths       []string

	CustomBackupPaths []string
	BackupBlacklist   []string

	// PBS Authentication (auto-detected, no manual input required)
	PBSRepository  string // Auto-detected from environment or generated
	PBSPassword    string // Auto-detected API token secret
	PBSFingerprint string // Auto-detected from PBS certificate
	// contains filtered or unexported fields
}

Config contiene tutta la configurazione del sistema di backup

func LoadConfig

func LoadConfig(configPath string) (*Config, error)

LoadConfig legge il file di configurazione backup.env

func (*Config) BuildWebhookConfig

func (c *Config) BuildWebhookConfig() *WebhookConfig

BuildWebhookConfig constructs a complete webhook configuration with all endpoints

func (*Config) Get

func (c *Config) Get(key string) (string, bool)

Get restituisce un valore raw dalla configurazione

func (*Config) GetRetentionPolicy

func (c *Config) GetRetentionPolicy() string

GetRetentionPolicy returns the active retention policy type Returns "gfs" if GFS retention is enabled, "simple" otherwise

func (*Config) IsGFSRetentionEnabled

func (c *Config) IsGFSRetentionEnabled() bool

IsGFSRetentionEnabled returns true if GFS retention policy is configured. GFS is enabled only when RETENTION_POLICY is explicitly set to "gfs".

func (*Config) Set

func (c *Config) Set(key, value string)

Set imposta un valore nella configurazione

type EnvMigrationSummary

type EnvMigrationSummary struct {
	OutputPath         string
	BackupPath         string
	MigratedKeys       map[string]string
	UnmappedLegacyKeys []string
	AutoDisabledCeph   bool
}

EnvMigrationSummary describes the outcome of a legacy -> Go config migration.

func MigrateLegacyEnv

func MigrateLegacyEnv(legacyPath, outputPath string) (*EnvMigrationSummary, error)

MigrateLegacyEnv creates a new Go-style backup.env by reading the legacy Bash configuration and merging it with the embedded template.

func PlanLegacyEnvMigration

func PlanLegacyEnvMigration(legacyPath, outputPath string) (*EnvMigrationSummary, string, error)

PlanLegacyEnvMigration computes what the migrated configuration would look like without writing any files.

type UpgradeResult

type UpgradeResult struct {
	// BackupPath is the path of the backup created from the previous config.
	BackupPath string
	// MissingKeys are keys that were present in the template but not in the
	// user's config; template defaults were added for these.
	MissingKeys []string
	// ExtraKeys are keys that were present in the user's config but not in the
	// template. They are preserved in a dedicated "Custom keys" section.
	ExtraKeys []string
	// PreservedValues is the number of existing key=value pairs from the user's
	// configuration that were kept during the merge for keys present in the
	// template.
	PreservedValues int
	// Changed reports whether the config file was actually modified.
	Changed bool
}

UpgradeResult describes the outcome of a configuration upgrade.

func PlanUpgradeConfigFile

func PlanUpgradeConfigFile(configPath string) (*UpgradeResult, error)

PlanUpgradeConfigFile computes what an upgrade would do without modifying the configuration file on disk.

It returns an UpgradeResult populated with:

  • MissingKeys: keys that would be added from the template.
  • ExtraKeys: keys that would be preserved in the custom section.
  • Changed: true if an upgrade would actually modify the file.

BackupPath is always empty in dry-run mode.

func UpgradeConfigFile

func UpgradeConfigFile(configPath string) (*UpgradeResult, error)

UpgradeConfigFile merges the user's configuration with the embedded template.

Goals:

  • Ensure all keys present in the template exist in the user's config.
  • Preserve all existing user values for known keys.
  • Preserve custom/legacy keys not present in the template in a dedicated section at the end of the file.
  • Keep the layout and comments of the template as much as possible.

The procedure is:

  1. Parse the existing config file and collect all KEY=VALUE entries.
  2. Walk the template line-by-line: - Comments/blank lines are copied as-is. - For KEY=VALUE lines: * If the user has values for that key, all of them are written (one KEY=VALUE per line, in original order). * Otherwise the template's line is kept and the key is recorded as "missing" (a new default added).
  3. Keys present in the user config but not in the template are appended to a "Custom keys" section at the bottom of the file.
  4. The original file is backed up before writing the new version.

type WebhookAuth

type WebhookAuth struct {
	Type   string
	Token  string
	User   string
	Pass   string
	Secret string
}

WebhookAuth holds authentication configuration for a webhook

type WebhookConfig

type WebhookConfig struct {
	Enabled       bool
	Endpoints     []WebhookEndpoint
	DefaultFormat string
	Timeout       int
	MaxRetries    int
	RetryDelay    int
}

WebhookConfig holds configuration for webhook notifications

type WebhookEndpoint

type WebhookEndpoint struct {
	Name         string
	URL          string
	Format       string
	Method       string
	Headers      map[string]string
	Auth         WebhookAuth
	CustomFields map[string]interface{}
}

WebhookEndpoint represents a single webhook endpoint configuration

Jump to

Keyboard shortcuts

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