Documentation
¶
Index ¶
- Constants
- Variables
- func BulkLocation(dataDir string) (string, error)
- func CheckBulk(ctx context.Context, dataDir string, key []byte) error
- func Checks(dir string, opened capsule.Manifest) []recoveryclient.Check
- func Collect(ctx context.Context, cfg *config.Config, appVersion string, purpose Purpose) (recoveryclient.Payload, error)
- func CollectBulk(ctx context.Context, dataDir string, dbBytes, key []byte, purpose Purpose) ([]byte, error)
- func DrillRoot(cfg *config.Config) string
- func InitBulkRepository(ctx context.Context, dataDir string, key []byte) error
- func JoinDatabase(dataDir string) error
- func Members(cfg *config.Config) []string
- func NewSealer(cfg *config.Config) (recoveryclient.Sealer, error)
- func PruneBulk(ctx context.Context, dataDir string, key []byte, policy BulkPolicy, ...) (int, error)
- func RestoreBulk(ctx context.Context, openedDir string, repository Repository, target string) error
- func RunConfig(cfg *config.Config, appVersion string) (recoveryclient.RunConfig, error)
- func RunDrill(ctx context.Context, cfg *config.Config, payload recoveryclient.Payload) (*recoveryclient.DrillResult, error)
- func SetBulkPolicy(s recoveryclient.Settings, p BulkPolicy) error
- func Settings(ctx context.Context, s store.SettingsStore) recoveryclient.Settings
- func SizeWarning(cfg *config.Config) string
- type BulkCheck
- type BulkFile
- type BulkManifest
- type BulkPolicy
- type BulkPrune
- type Purpose
- type Repository
Constants ¶
const (
BulkManifestPath = "data/" + bulkManifestName
)
Variables ¶
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") )
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.
var ErrDrillBusy = errors.New("backup: a restore drill is already running")
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.
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 ¶
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 ¶
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 InitBulkRepository ¶
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
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 ¶
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 ¶
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 RunDrill ¶
func RunDrill(ctx context.Context, cfg *config.Config, payload recoveryclient.Payload) (*recoveryclient.DrillResult, error)
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 ¶
func Settings(ctx context.Context, s store.SettingsStore) recoveryclient.Settings
Settings binds the request context to the settings store for one call into the lib.
func SizeWarning ¶ added in v0.6.1
SizeWarning is sizeWarning for the live database file, for the status route.
Types ¶
type BulkCheck ¶
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 BulkManifest ¶
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".
type Repository ¶
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