Documentation
¶
Overview ¶
Package backup provides backup and restore functionality for AnubisWatch data
Index ¶
- func FormatBytes(bytes int64) string
- func IsWithinDirectory(path, dir string) bool
- type Backup
- type BackupData
- type BackupInfo
- type BackupMetadata
- type BackupStorage
- type Manager
- func (m *Manager) Create(ctx context.Context, opts Options) (*Backup, string, error)
- func (m *Manager) Delete(filename string) error
- func (m *Manager) ExportToTar(ctx context.Context, w io.Writer, opts Options) error
- func (m *Manager) Get(filename string) (*Backup, error)
- func (m *Manager) ImportFromTar(storage RestoreStorage, r io.Reader, opts RestoreOptions) error
- func (m *Manager) Init() error
- func (m *Manager) List() ([]BackupInfo, error)
- func (m *Manager) Restore(ctx context.Context, storage RestoreStorage, backupPath string, ...) error
- type Options
- type RestoreOptions
- type RestoreStorage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatBytes ¶
FormatBytes formats byte size to human-readable string (exported for testing)
func IsWithinDirectory ¶
IsWithinDirectory checks if a path is within a directory (exported for testing)
Types ¶
type Backup ¶
type Backup struct {
Version string `json:"version"`
CreatedAt time.Time `json:"created_at"`
BackupType string `json:"backup_type"` // full, incremental
Checksum string `json:"checksum"`
Metadata BackupMetadata `json:"metadata"`
Data BackupData `json:"data"`
}
Backup represents a complete system backup
type BackupData ¶
type BackupData struct {
Workspaces []*core.Workspace `json:"workspaces"`
Souls []*core.Soul `json:"souls"`
AlertChannels []*core.AlertChannel `json:"alert_channels"`
AlertRules []*core.AlertRule `json:"alert_rules"`
StatusPages []*core.StatusPage `json:"status_pages"`
Journeys []*core.JourneyConfig `json:"journeys"`
SystemConfig map[string]json.RawMessage `json:"system_config,omitempty"`
}
BackupData contains all backed up data
type BackupInfo ¶
type BackupInfo struct {
Filename string `json:"filename"`
Path string `json:"path"`
Size int64 `json:"size"`
CreatedAt time.Time `json:"created_at"`
Metadata BackupMetadata `json:"metadata,omitempty"`
}
BackupInfo contains information about a backup file
type BackupMetadata ¶
type BackupMetadata struct {
NodeID string `json:"node_id,omitempty"`
ClusterID string `json:"cluster_id,omitempty"`
Version string `json:"anubis_version"`
Workspaces int `json:"workspaces_count"`
Souls int `json:"souls_count"`
AlertChannels int `json:"alert_channels_count"`
AlertRules int `json:"alert_rules_count"`
StatusPages int `json:"status_pages_count"`
Journeys int `json:"journeys_count"`
CustomFields map[string]string `json:"custom_fields,omitempty"`
}
BackupMetadata contains backup information
type BackupStorage ¶
type BackupStorage interface {
// Souls
ListSouls(ctx context.Context, workspaceID string, offset, limit int) ([]*core.Soul, error)
ListWorkspaces(ctx context.Context) ([]*core.Workspace, error)
// Alerting
ListAlertChannels() ([]*core.AlertChannel, error)
ListAlertRules() ([]*core.AlertRule, error)
// Status Pages
ListStatusPages() ([]*core.StatusPage, error)
// Journeys
ListJourneys(ctx context.Context, workspaceID string) ([]*core.JourneyConfig, error)
// Judgments (limited recent history)
ListJudgments(ctx context.Context, soulID string, start, end time.Time, limit int) ([]*core.Judgment, error)
// System config
GetSystemConfig(ctx context.Context, key string) ([]byte, error)
}
BackupStorage interface for data access
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager handles backup and restore operations
func NewManager ¶
func NewManager(storage BackupStorage, dataDir string, logger *slog.Logger) *Manager
NewManager creates a new backup manager
func (*Manager) ExportToTar ¶
ExportToTar exports backup data to a tar archive
func (*Manager) ImportFromTar ¶
func (m *Manager) ImportFromTar(storage RestoreStorage, r io.Reader, opts RestoreOptions) error
ImportFromTar imports backup data from a tar archive
func (*Manager) List ¶
func (m *Manager) List() ([]BackupInfo, error)
List returns a list of available backups
func (*Manager) Restore ¶
func (m *Manager) Restore(ctx context.Context, storage RestoreStorage, backupPath string, opts RestoreOptions) error
Restore restores data from a backup file
type Options ¶
type Options struct {
IncludeJudgments bool // Include recent judgment history
JudgmentDays int // How many days of judgment history to include
Compress bool // Compress the backup
Encrypt bool // Encrypt the backup
EncryptionKey []byte // Encryption key (if encrypting)
Metadata map[string]string // Custom metadata
}
Options for backup operations
type RestoreOptions ¶
type RestoreOptions struct {
IncludeWorkspaces bool
IncludeSouls bool
IncludeAlerts bool
IncludeStatusPages bool
IncludeJourneys bool
IncludeSystemConfig bool
ContinueOnError bool
}
RestoreOptions contains options for restore operations
func DefaultRestoreOptions ¶
func DefaultRestoreOptions() RestoreOptions
DefaultRestoreOptions returns default restore options (restore everything)
type RestoreStorage ¶
type RestoreStorage interface {
SaveSoul(ctx context.Context, soul *core.Soul) error
SaveWorkspace(ctx context.Context, ws *core.Workspace) error
SaveAlertChannel(ch *core.AlertChannel) error
SaveAlertRule(rule *core.AlertRule) error
SaveStatusPage(page *core.StatusPage) error
SaveJourney(ctx context.Context, j *core.JourneyConfig) error
SaveSystemConfig(ctx context.Context, key string, value []byte) error
}
RestoreStorage interface for restoring data