backup

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: Apache-2.0 Imports: 26 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package backup makes encrypted backups of the controller (§13) and ships them to S3. A bundle holds a consistent SQLite snapshot (VACUUM INTO) and the key material in the data directory (CA, registry token key, …), sealed with the master key. The header carries the master key wrapped by the recovery key, so restoring needs the bundle plus the recovery key only.

Index

Constants

View Source
const (

	// Ext is the bundle file extension.
	Ext = ".synbak"
)
View Source
const (

	// TopicUpdated carries Status after every backup run.
	TopicUpdated = "backup.updated"
)

Variables

View Source
var ErrNotConfigured = errors.New("backups are not configured")

ErrNotConfigured is returned when no S3 destination is set.

View Source
var ErrOtherMasterKey = errors.New("the backup was made with another master key")

ErrOtherMasterKey means a bundle was sealed with another master key (another install, or one from before a restore onto a new key).

Functions

func Create

func Create(ctx context.Context, st *store.Store, box *secrets.Box, dataDir string, w io.Writer) error

Create writes an encrypted bundle of dataDir to w.

func Download

func Download(ctx context.Context, cfg Config, name string) ([]byte, string, error)

Download fetches one backup (by name, or the newest when name is "").

func Rekey added in v0.2.0

func Rekey(bundle []byte, box *secrets.Box) ([]byte, error)

Rekey gives a bundle the box's current wrapped master key, so it opens with the current recovery key (Phase 19b). The body is checked to be sealed with the box's master key and is kept byte for byte.

func Restore

func Restore(bundle []byte, recoveryKey, dataDir string, force bool) ([]string, error)

Restore unpacks bundle into dataDir using the recovery key. dataDir must not hold a database unless force is set. It returns the restored file names.

func StoreRecoveryKey added in v0.2.0

func StoreRecoveryKey(ctx context.Context, st *store.Store, box *secrets.Box, key string) error

StoreRecoveryKey keeps key sealed in the settings.

func StoredRecoveryKey added in v0.2.0

func StoredRecoveryKey(ctx context.Context, st *store.Store, box *secrets.Box) (key string, ok bool, err error)

StoredRecoveryKey returns the kept recovery key; ok is false on installs from before keys were kept, or when the kept key no longer matches.

Types

type Config

type Config struct {
	Endpoint        string `json:"endpoint"` // e.g. https://s3.eu-central-1.amazonaws.com, http://10.0.0.5:9000
	Region          string `json:"region"`
	Bucket          string `json:"bucket"`
	Prefix          string `json:"prefix"`
	AccessKeyID     string `json:"accessKeyId"`
	SecretAccessKey string `json:"secretAccessKey,omitempty"`
	IntervalMinutes int    `json:"intervalMinutes"`
	Retain          int    `json:"retain"`
}

Config is where and how often backups go. The secret is stored sealed.

type Manager

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

func NewManager

func NewManager(st *store.Store, box *secrets.Box, dataDir string, bus *events.Bus, log *slog.Logger) *Manager

func (*Manager) Config

func (m *Manager) Config() (Config, bool)

Config returns the configuration without the secret.

func (*Manager) Disable

func (m *Manager) Disable(ctx context.Context) error

Disable turns backups off (existing objects are kept).

func (*Manager) List

func (m *Manager) List(ctx context.Context) ([]Object, error)

List returns stored backups, newest first.

func (*Manager) Load

func (m *Manager) Load(ctx context.Context) error

Load reads the stored configuration and last status.

func (*Manager) RekeyAll added in v0.2.0

func (m *Manager) RekeyAll(ctx context.Context) (RekeyResult, error)

RekeyAll re-keys every stored backup in place so it opens with the current recovery key (Phase 19b). Backups are not run meanwhile.

func (*Manager) Run

func (m *Manager) Run(ctx context.Context)

Run takes a backup whenever one is due, until ctx ends.

func (*Manager) RunNow

func (m *Manager) RunNow(ctx context.Context) (Object, error)

RunNow uploads a backup and applies retention.

func (*Manager) SetConfig

func (m *Manager) SetConfig(ctx context.Context, c Config) error

SetConfig validates c, checks that the bucket is reachable, stores it and triggers a first backup.

func (*Manager) Status

func (m *Manager) Status() Status

func (*Manager) WriteBundle

func (m *Manager) WriteBundle(ctx context.Context, w io.Writer) error

WriteBundle streams a fresh backup bundle (for downloads without S3).

type Object

type Object struct {
	Name      string    `json:"name"`
	Size      int64     `json:"size"`
	CreatedAt time.Time `json:"createdAt"`
}

type RekeyResult added in v0.2.0

type RekeyResult struct {
	Rekeyed int `json:"rekeyed"`
	// Skipped were made with another master key and left as they are.
	Skipped []string `json:"skipped"`
	// Failed could not be read or written (name: error).
	Failed []string `json:"failed"`
}

RekeyResult is the outcome of re-keying the stored backups.

type Status

type Status struct {
	LastRunAt     *time.Time `json:"lastRunAt"`
	LastSuccessAt *time.Time `json:"lastSuccessAt"`
	LastError     string     `json:"lastError"`
	LastObject    string     `json:"lastObject"`
	LastSize      int64      `json:"lastSize"`
}

Jump to

Keyboard shortcuts

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