backup

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 27 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

Index

Constants

View Source
const (
	BulkManifestPath = "data/" + bulkManifestName
)

Variables

View Source
var (
	ErrBadBulkPolicy = errors.New("backup: each bulk retention count must be between 0 and 1000")
	ErrBulkBusy      = errors.New("backup: another bulk backup operation is running")
)
View Source
var ErrDatabaseParts = errors.New("backup: database parts are incomplete or inconsistent")

ErrDatabaseParts refuses a split database that is incomplete, out of order or beside a whole one.

View Source
var ErrDrillBusy = errors.New("backup: a restore drill is already running")
View Source
var ErrForeignBulkRepository = errors.New("bulk repository exists but this deployment's key does not open it")

ErrForeignBulkRepository means a repository exists at the configured location but neither the derived password nor the pre-upgrade raw key opens it.

View Source
var ErrNoDatabaseSnapshot = errors.New("backup: no consistent database snapshot for this driver")

ErrNoDatabaseSnapshot is returned when the payload cannot carry a consistent copy of the database, so a capsule without one is never sealed as if it were a backup.

Functions

func BulkLocation

func BulkLocation(dataDir string) (string, error)

BulkLocation is the configured repository as the Recovery screen shows it: credentials never appear in it, since they cannot be part of an accepted location.

func CheckBulk

func CheckBulk(ctx context.Context, dataDir string, key []byte) error

CheckBulk verifies the repository's structure and reads back a random 5% of its data, so a destination that silently loses or corrupts packs shows within a few weekly runs. Another bulk operation holding the lock returns ErrBulkBusy.

func Checks

func Checks(dir string, opened capsule.Manifest) []recoveryclient.Check

Checks validates the recipe from the capsule that was actually opened. A malformed recipe is a failed drill, never permission to omit a required product check.

func Collect

func Collect(ctx context.Context, cfg *config.Config, appVersion string, purpose Purpose) (recoveryclient.Payload, error)

Collect assembles the payload every sealing caller uses: the local application files (SQLite database, configuration) plus the members that may only ever travel inside a sealed capsule (the encryption key, the pinned recovery public key). Nothing that returns from here may leave the process except through a Sealer. purpose tags the bulk snapshot.

func CollectBulk

func CollectBulk(ctx context.Context, dataDir string, dbBytes, key []byte, purpose Purpose) ([]byte, error)

func DrillRoot

func DrillRoot(cfg *config.Config) string

DrillRoot is KY_DRILL_DIR, by default beneath the deployment's data directory.

func InitBulkRepository

func InitBulkRepository(ctx context.Context, dataDir string, key []byte) error

InitBulkRepository creates the bulk repository. One the deployment key already opens, with the derived password or the raw key the next backup moves, is left unchanged.

func JoinDatabase added in v0.6.1

func JoinDatabase(dataDir string) error

JoinDatabase reassembles a database, and a bulk manifest, sealed as parts into dataDir/ky_server.db (dataDir/drive-bulk.json) and removes the parts, before anything opens them. Without parts it does nothing, so a single-member capsule or an already joined directory passes unchanged. It refuses a missing, extra or renumbered part, and parts beside a whole file.

func Members

func Members(cfg *config.Config) []string

Members names what a capsule carries, for the screen; it is what Collect would seal now.

func NewSealer

func NewSealer(cfg *config.Config) (recoveryclient.Sealer, error)

NewSealer seals the KyRecovery token under the deployment key, domain-separated so a row copied from another setting will not open.

func PruneBulk

func PruneBulk(ctx context.Context, dataDir string, key []byte, policy BulkPolicy, keepLast int) (int, error)

PruneBulk forgets bulk snapshots outside policy, then prunes unreferenced data. Off forgets nothing. The newest keepLast deposit snapshots, and the newest keepLast of any kind (which covers untagged ones a retained local copy may still name), are never forgotten. Prune runs even when nothing was forgotten, so a run that died after forget is finished by the next. Another bulk operation holding the lock returns ErrBulkBusy.

func RestoreBulk

func RestoreBulk(ctx context.Context, openedDir string, repository Repository, target string) error

RestoreBulk accepts only a manifest from an opened, verified capsule. It checks every referenced blob before publishing the restored directory; absence never becomes success.

func RunConfig

func RunConfig(cfg *config.Config, appVersion string) (recoveryclient.RunConfig, error)

RunConfig is what Run needs from the scaffold's configuration.

func RunDrill

RunDrill serializes HTTP and CLI drills sharing a data directory, and holds the bulk lock across the drill so its restore never meets a prune.

func SetBulkPolicy

func SetBulkPolicy(s recoveryclient.Settings, p BulkPolicy) error

func Settings

Settings binds the request context to the settings store for one call into the lib.

func SizeWarning added in v0.6.1

func SizeWarning(cfg *config.Config) string

SizeWarning is sizeWarning for the live database file, for the status route.

Types

type BulkCheck

type BulkCheck struct {
	At    time.Time `json:"at"`
	Error string    `json:"error,omitempty"`
}

BulkCheck records the last integrity check, failed or not.

func CheckBulkIfDue

func CheckBulkIfDue(ctx context.Context, cfg *config.Config, s recoveryclient.Settings, now time.Time) (BulkCheck, bool, error)

CheckBulkIfDue runs CheckBulk at most once a week and records the attempt. It does not run (false) without a bulk repository, within a week of the last attempt, or while another bulk operation holds the lock (ErrBulkBusy; tried again after the next deposit).

func LastBulkCheck

func LastBulkCheck(s recoveryclient.Settings) (BulkCheck, bool, error)

type BulkFile

type BulkFile struct {
	Blob   string `json:"blob"`
	Digest string `json:"digest"`
	Size   int64  `json:"size"`
	Sealed bool   `json:"sealed,omitempty"`
}

type BulkManifest

type BulkManifest struct {
	Version  int        `json:"version"`
	Snapshot string     `json:"snapshot"`
	Root     string     `json:"root"`
	Files    []BulkFile `json:"files"`
}

type BulkPolicy

type BulkPolicy struct {
	Daily   int `json:"keep_daily"`
	Weekly  int `json:"keep_weekly"`
	Monthly int `json:"keep_monthly"`
}

BulkPolicy is the admin's opt-in bulk snapshot retention. All zero is off, the default.

func LoadBulkPolicy

func LoadBulkPolicy(s recoveryclient.Settings) (BulkPolicy, error)

LoadBulkPolicy returns off when unset; an unreadable row is an error, so nothing is forgotten.

func (BulkPolicy) Off

func (p BulkPolicy) Off() bool

type BulkPrune

type BulkPrune struct {
	At        time.Time `json:"at"`
	Forgotten int       `json:"forgotten"`
	Error     string    `json:"error,omitempty"`
}

BulkPrune records the last attempt, failed or not.

func LastBulkPrune

func LastBulkPrune(s recoveryclient.Settings) (BulkPrune, bool, error)

func PruneBulkIfDue

func PruneBulkIfDue(ctx context.Context, cfg *config.Config, s recoveryclient.Settings, now time.Time) (BulkPrune, bool, error)

PruneBulkIfDue runs PruneBulk under the stored policy at most once a day and records the attempt, so a repository that refuses prune is retried daily, not after every deposit. It does not run (false) when the policy is off, a run was recorded in the last 24 hours, or another bulk operation holds the lock (ErrBulkBusy; tried again after the next deposit).

type Purpose

type Purpose string

Purpose tags a bulk snapshot with why it was taken, so retention treats deposits apart from drills and exports. Snapshots from before tagging carry only "kydrive".

const (
	PurposeDeposit Purpose = "deposit"
	PurposeDrill   Purpose = "drill"
	PurposeExport  Purpose = "export"
)

type Repository

type Repository struct {
	URL string
	Env []string // KEY=VALUE, keys from credentialKeys
}

Repository is a bulk Restic repository and the credentials restic needs to reach it. Only URL is ever printed; Env reaches the restic child alone.

func CapsuleRepository

func CapsuleRepository(openedDir string) (repo Repository, ok bool, err error)

CapsuleRepository is the repository an opened capsule names, its credentials checked as a file's are. ok is false for a capsule sealed before capsules carried it.

func (Repository) String

func (r Repository) String() string

Jump to

Keyboard shortcuts

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