backup

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2026 License: Apache-2.0, BSD-3-Clause, MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecryptBackup

func DecryptBackup(encrypted []byte, password string) ([]byte, error)

DecryptBackup decrypts backup data using AES-256-GCM Per AI.md PART 24: Backup Encryption

func DecryptFile

func DecryptFile(inputPath, outputPath, password string) error

DecryptFile decrypts a file and writes to output path

func EncryptBackup

func EncryptBackup(data []byte, password string) ([]byte, error)

EncryptBackup encrypts backup data using AES-256-GCM with password-based key derivation Per AI.md PART 24: Backup Encryption (NON-NEGOTIABLE) Algorithm: AES-256-GCM Key Derivation: Argon2id (password → encryption key) Password Storage: NEVER stored - admin must remember

func EncryptFile

func EncryptFile(inputPath, outputPath, password string) error

EncryptFile encrypts a file and writes to output path

func HashPassword

func HashPassword(password string) string

HashPassword creates a SHA-256 hash of the password for verification This is NOT stored - only used to verify password hasn't changed

func IsEncrypted

func IsEncrypted(backupPath string) bool

IsEncrypted checks if a backup file is encrypted (has .enc extension) Per AI.md PART 22: .enc extension for encrypted backups

func VerifyPassword

func VerifyPassword(password, hash string) bool

VerifyPassword checks if a password matches the stored hash

Types

type BackupInfo

type BackupInfo struct {
	Filename    string    `json:"filename"`
	Path        string    `json:"path"`
	Size        int64     `json:"size"`
	CreatedAt   time.Time `json:"created_at"`
	Version     string    `json:"version,omitempty"`
	ServerTitle string    `json:"server_title,omitempty"`
	FileCount   int       `json:"file_count,omitempty"`
}

BackupInfo contains summary information about a backup

func (BackupInfo) FormatSize

func (bi BackupInfo) FormatSize() string

FormatSize returns a human-readable size

type BackupMetadata

type BackupMetadata struct {
	Version          string            `json:"version"`           // Manifest format version (e.g., "1.0.0")
	CreatedAt        time.Time         `json:"created_at"`        // When backup was created
	CreatedBy        string            `json:"created_by"`        // Who created the backup (per PART 25)
	AppVersion       string            `json:"app_version"`       // Application version (per PART 25)
	Contents         []string          `json:"contents"`          // List of files/directories in backup
	Checksums        map[string]string `json:"checksums"`         // SHA256 checksums per file
	Checksum         string            `json:"checksum"`          // Overall archive checksum (per PART 25)
	Encrypted        bool              `json:"encrypted"`         // Per AI.md PART 25
	EncryptionMethod string            `json:"encryption_method"` // "AES-256-GCM" if encrypted
	// Legacy fields for backwards compatibility
	ServerTitle string   `json:"server_title,omitempty"` // Server title (optional)
	Size        int64    `json:"size,omitempty"`         // Total size in bytes (optional)
	Files       []string `json:"files,omitempty"`        // Deprecated: use Contents
}

BackupMetadata contains information about a backup Per AI.md PART 25: manifest.json format with required fields

type Manager

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

Manager handles backup and restore operations

func NewManager

func NewManager() *Manager

NewManager creates a new backup manager

func (*Manager) ApplyRetention

func (m *Manager) ApplyRetention(policy RetentionPolicy) error

ApplyRetention applies retention policy to backups Per AI.md PART 22: Smart retention with daily/weekly/monthly/yearly buckets

func (*Manager) Create

func (m *Manager) Create(filename string) (string, error)

Create creates a new backup archive

func (*Manager) CreateAndVerify

func (m *Manager) CreateAndVerify(filename string) (string, *VerificationResult, error)

CreateAndVerify creates a backup and verifies it immediately Per AI.md PART 22: Only delete old backups if new backup passes ALL verification checks

func (*Manager) CreateEncrypted

func (m *Manager) CreateEncrypted(filename string) (string, error)

CreateEncrypted creates an encrypted backup with .enc extension Per AI.md PART 22: .enc extension for encrypted backups

func (*Manager) CreateEncryptedAndVerify

func (m *Manager) CreateEncryptedAndVerify(filename string) (string, *VerificationResult, error)

CreateEncryptedAndVerify creates an encrypted backup and verifies it Per AI.md PART 22: All encrypted backups must pass decrypt test

func (*Manager) Delete

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

Delete deletes a backup file

func (*Manager) GetMetadata

func (m *Manager) GetMetadata(backupPath string) (*BackupMetadata, error)

GetMetadata reads metadata from a backup archive Looks for manifest.json (per AI.md PART 26) or legacy backup.json

func (*Manager) List

func (m *Manager) List() ([]BackupInfo, error)

List returns all available backups

func (*Manager) Restore

func (m *Manager) Restore(backupPath string) error

Restore restores from a backup archive

func (*Manager) RestoreEncrypted

func (m *Manager) RestoreEncrypted(backupPath string) error

RestoreEncrypted restores from an encrypted backup (.enc extension) Per AI.md PART 22: .enc extension for encrypted backups

func (*Manager) ScheduledBackup

func (m *Manager) ScheduledBackup(keepCount int) error

ScheduledBackup performs a scheduled backup with cleanup of old backups

func (*Manager) ScheduledBackupWithVerification

func (m *Manager) ScheduledBackupWithVerification(keepCount int) error

ScheduledBackupWithVerification performs a scheduled backup with verification Per AI.md PART 22: Only delete old backups if new backup passes ALL verification checks

func (*Manager) SetCreatedBy

func (m *Manager) SetCreatedBy(username string)

SetCreatedBy sets the username for backup attribution (per AI.md PART 25)

func (*Manager) SetPassword

func (m *Manager) SetPassword(password string)

SetPassword sets the backup encryption password Per AI.md PART 24: Password is NEVER stored - derived on-demand

func (*Manager) VerifyBackup

func (m *Manager) VerifyBackup(backupPath string) (*VerificationResult, error)

VerifyBackup verifies backup integrity immediately after creation Per AI.md PART 22 (NON-NEGOTIABLE): - File exists - Size > 0 - Checksum valid - Manifest readable - Decrypt test (if encrypted)

type RetentionPolicy

type RetentionPolicy struct {
	Count int `json:"count" yaml:"count"` // Number of backups to keep
	Day   int `json:"day" yaml:"day"`     // Days to keep daily backups
	Week  int `json:"week" yaml:"week"`   // Weeks to keep weekly backups
	Month int `json:"month" yaml:"month"` // Months to keep monthly backups
	Year  int `json:"year" yaml:"year"`   // Years to keep yearly backups
}

RetentionPolicy defines backup retention rules per AI.md PART 22 Per AI.md PART 22: Retention policies (count, day, week, month, year)

func DefaultRetentionPolicy

func DefaultRetentionPolicy() RetentionPolicy

DefaultRetentionPolicy returns the default retention policy Per AI.md PART 22: Reasonable defaults

type VerificationResult

type VerificationResult struct {
	FileExists    bool     `json:"file_exists"`
	SizeValid     bool     `json:"size_valid"`
	ChecksumValid bool     `json:"checksum_valid"`
	ManifestValid bool     `json:"manifest_valid"`
	DecryptValid  bool     `json:"decrypt_valid"` // Only for encrypted backups
	AllPassed     bool     `json:"all_passed"`
	Errors        []string `json:"errors,omitempty"`
}

VerificationResult contains the results of backup verification Per AI.md PART 22: Backup verification is NON-NEGOTIABLE

Jump to

Keyboard shortcuts

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