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
- func ValidKey(key string) error
- type Archive
- type Options
- type S3Options
- type Service
- func (s *Service) Backup(ctx context.Context, rt runtime.Runtime, target int64, ...) (string, error)
- func (s *Service) Create(ctx context.Context, in TargetInput) (Target, error)
- func (s *Service) Delete(ctx context.Context, id int64) error
- func (s *Service) List(ctx context.Context, target int64, namespace, volume string) ([]Archive, error)
- func (s *Service) Restore(ctx context.Context, rt runtime.Runtime, target int64, ...) error
- func (s *Service) Target(ctx context.Context, id int64) (Target, error)
- func (s *Service) Targets(ctx context.Context) ([]Target, error)
- func (s *Service) Test(ctx context.Context, id int64) error
- func (s *Service) Update(ctx context.Context, id int64, in TargetInput) (Target, error)
- type Store
- type Target
- type TargetInput
Constants ¶
const ( KindLocal = "local" KindS3 = "s3" )
Kinds of targets.
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 ¶
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) 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.
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.