volbackup

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: AGPL-3.0 Imports: 23 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 volbackup backs up volumes as tar.gz archives to a host directory or an S3 bucket, keeps the newest ones and restores them (#59, ADR-0050).

Index

Constants

View Source
const (
	KindLocal = "local"
	KindS3    = "s3"
)

Kinds of targets.

View Source
const (

	// DefaultKeep is how many archives of a volume are kept by default.
	DefaultKeep = 7
	// MaxKeep bounds the retention.
	MaxKeep = 1000
)

Variables

This section is empty.

Functions

func ValidKey

func ValidKey(key string) error

ValidKey checks the key of an archive given by a client.

Types

type Archive

type Archive struct {
	// Key is the archive's path in its target: <namespace>/<volume>/<volume>-<time>.tar.gz.
	Key  string    `json:"key"`
	Size int64     `json:"size"`
	Time time.Time `json:"time"`
}

Archive is a stored backup of a volume. Keep in sync with api/openapi.yaml.

type Options

type Options struct {
	// Keep is how many archives of the volume are kept after a backup (0: DefaultKeep).
	Keep int
	// StopContainers stops the running containers that use the volume while it is read or
	// written, and starts them again afterwards.
	StopContainers bool
}

Options of a backup or restore.

type S3Options

type S3Options struct {
	// Endpoint is host[:port] (HTTPS) or an http(s):// URL, e.g. s3.eu-central-1.amazonaws.com.
	Endpoint  string `json:"endpoint"`
	Region    string `json:"region,omitempty"`
	Bucket    string `json:"bucket"`
	Prefix    string `json:"prefix,omitempty"`
	AccessKey string `json:"accessKey"`
	// PathStyle addresses the bucket as endpoint/bucket (MinIO and other self-hosted servers).
	PathStyle bool `json:"pathStyle,omitempty"`
}

S3Options locate a bucket. Keep in sync with api/openapi.yaml.

type Service

type Service struct {
	Store Store
	Box   *secretbox.Box
	// InUse names the schedules that write to a target, which cannot be deleted then.
	InUse func(ctx context.Context, target int64) ([]string, error)
	Now   func() time.Time
}

Service manages targets, backups and restores.

func (*Service) Backup

func (s *Service) Backup(ctx context.Context, rt runtime.Runtime, target int64, namespace, volume string, o Options, out io.Writer) (string, error)

Backup writes an archive of a volume to a target and removes the oldest beyond Keep. It returns the archive's key.

func (*Service) Create

func (s *Service) Create(ctx context.Context, in TargetInput) (Target, error)

Create adds a target.

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, id int64) error

Delete removes a target that no schedule uses; its archives stay.

func (*Service) List

func (s *Service) List(ctx context.Context, target int64, namespace, volume string) ([]Archive, error)

List returns the archives of a volume in a target, newest first.

func (*Service) Restore

func (s *Service) Restore(ctx context.Context, rt runtime.Runtime, target int64, key, namespace, volume string, o Options, out io.Writer) error

Restore replaces the contents of a volume with an archive of a target; the volume is created when it does not exist. Running containers using it are refused unless StopContainers is set.

func (*Service) Target

func (s *Service) Target(ctx context.Context, id int64) (Target, error)

Target returns a target.

func (*Service) Targets

func (s *Service) Targets(ctx context.Context) ([]Target, error)

Targets lists the targets.

func (*Service) Test

func (s *Service) Test(ctx context.Context, id int64) error

Test writes, lists and removes a small object in a target.

func (*Service) Update

func (s *Service) Update(ctx context.Context, id int64, in TargetInput) (Target, error)

Update changes a target.

type Store

type Store interface {
	ListBackupTargets(ctx context.Context) ([]db.BackupTarget, error)
	GetBackupTarget(ctx context.Context, id int64) (db.BackupTarget, error)
	CreateBackupTarget(ctx context.Context, arg db.CreateBackupTargetParams) (db.BackupTarget, error)
	UpdateBackupTarget(ctx context.Context, arg db.UpdateBackupTargetParams) (db.BackupTarget, error)
	DeleteBackupTarget(ctx context.Context, id int64) (int64, error)
}

Store is the database; *db.Queries implements it.

type Target

type Target struct {
	ID        int64      `json:"id"`
	Name      string     `json:"name"`
	Kind      string     `json:"kind"`
	Directory string     `json:"directory,omitempty"`
	S3        *S3Options `json:"s3,omitempty"`
	// HasSecret is set for S3 targets with a stored secret key.
	HasSecret bool      `json:"hasSecret,omitempty"`
	CreatedAt time.Time `json:"createdAt"`
	UpdatedAt time.Time `json:"updatedAt"`
}

Target is where archives go. Keep in sync with api/openapi.yaml.

type TargetInput

type TargetInput struct {
	Name      string     `json:"name"`
	Kind      string     `json:"kind"`
	Directory string     `json:"directory"`
	S3        *S3Options `json:"s3"`
	SecretKey string     `json:"secretKey"`
}

TargetInput creates or changes a target; an empty SecretKey keeps the stored one.

Jump to

Keyboard shortcuts

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