backup

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package backup provides backup and restore functionality for AnubisWatch data

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatBytes

func FormatBytes(bytes int64) string

FormatBytes formats byte size to human-readable string (exported for testing)

func IsWithinDirectory

func IsWithinDirectory(path, dir string) bool

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) Create

func (m *Manager) Create(ctx context.Context, opts Options) (*Backup, string, error)

Create performs a full backup

func (*Manager) Delete

func (m *Manager) Delete(filename string) error

Delete removes a backup file

func (*Manager) ExportToTar

func (m *Manager) ExportToTar(ctx context.Context, w io.Writer, opts Options) error

ExportToTar exports backup data to a tar archive

func (*Manager) Get

func (m *Manager) Get(filename string) (*Backup, error)

Get retrieves a backup by filename

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) Init

func (m *Manager) Init() error

Init initializes the backup manager (creates directories)

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

func DefaultOptions

func DefaultOptions() Options

DefaultOptions returns default backup options

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

Jump to

Keyboard shortcuts

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