restore

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Overview

Package restore reads the platform backup generations of ADR-0203 back (ADR-0206): it lists them as a lineage, resolves a restore point, restores one offline into empty directories and leaves the platform held, and inspects one into memory engines.

Index

Constants

View Source
const (
	StateComplete   = "complete"
	StateIncomplete = "incomplete"
	StateAbandoned  = "abandoned"
	StateNewer      = "newer"
)

The states of a listed generation (Decision 3).

Variables

This section is empty.

Functions

func CheckVersion

func CheckVersion(writer, binary string) error

CheckVersion is Decision 4's rule: a generation written by funcd writer restores on funcd binary when writer's major.minor is the same or older; a newer one is fault.Invalid naming both. A stamp that is not semver ("dev", or git describe's bare hash in a clone without tags) orders nothing, so it restores and Run warns.

func Counts

func Counts(ctx context.Context, st store.Store) (map[v1.Kind]int, error)

Counts counts the objects per kind of st; a kind without one is absent.

func Diff

func Diff(from, to *View) (added, removed, changed map[v1.Kind][]v1.ObjectRef, err error)

Diff lists per kind the objects to adds, from drops and both hold with differing Export forms. Secrets that do not decode in either view compare by key only.

func Export

func Export(obj v1.Object, reveal bool) (v1.Object, error)

Export is obj as `funcdctl apply -f` recreates it (Q14): no uid, resourceVersion, creation time or status. A Secret's values are REDACTED unless reveal.

func Parent

func Parent(dataDir, timeline string) (*backup.GenRef, error)

Parent is the generation restore.json says was loaded, while timeline is the one that restore minted: ADR-0205 writes it as each generation's parent. No report, or another timeline, is nil.

func Timeline

func Timeline(ctx context.Context, st store.Store) (string, error)

Timeline is the timeline store.New minted over the loaded engine (ADR-0202 Decision 3).

Types

type Generation

type Generation struct {
	Manifest backup.Manifest
	Class    backup.Class
	State    string
}

Generation is one listed generation: its manifest (only Generation and Timeline while incomplete), its class and its state: incomplete without a manifest, abandoned on a dead branch (backup.Abandoned), newer when this funcd cannot read it (format or version), else complete.

func List

func List(ctx context.Context, src blob.Bucket) ([]Generation, error)

List lists src once and reads each complete generation's manifest, in backup.List's order.

func Resolve

func Resolve(gens []Generation, p Point) (Generation, error)

Resolve picks the generation p names among gens (Decision 3): none ⇒ fault.NotFound; latest, a time or a pin whose candidates come from two timelines neither of which descends from the other ⇒ fault.Conflict naming both. A resourceVersion <t>-<n> is the newest complete generation of t below revision n, else t's parent.

func (Generation) Ref

func (g Generation) Ref() backup.GenRef

Ref is the generation's (timeline, n).

type Options

type Options struct {
	Config          config.Config
	Source          blob.Bucket
	Identities      []age.Identity
	EscrowDir       string
	NewMasterSecret bool
	SecretsKey      []byte
	Out             io.Writer
}

Options configure Run and Inspect. Source is the target opened with the operator's restore credential (gocloud.OpenWith); Identities are envelope.ReadIdentities'; SecretsKey is --secrets-key, which only Inspect reads (Run uses secrets.encryptionKeyFile); Out takes the warnings and the credentials a new master changes.

type Point

type Point struct {
	Latest   bool
	At       time.Time
	Version  store.Version
	Gen      *backup.GenRef
	Pin      backup.Class
	Timeline string
}

Point is a parsed restore point (Decision 3): exactly one of Latest, At, Version, Gen and Pin is set. Timeline is --timeline: latest, a time and a pin keep only that timeline and those it descends from.

func ParsePoint

func ParsePoint(s string) (Point, error)

ParsePoint parses latest, pre-upgrade, verified, an RFC 3339 time, <timeline>/<n> or <timeline>-<n> (a resourceVersion); anything else is fault.Invalid.

type Report

type Report struct {
	From              backup.GenRef   `json:"from"`
	Timeline          string          `json:"timeline"`
	Funcd             string          `json:"funcd"`
	At                v1.Timestamp    `json:"at"`
	Counts            map[v1.Kind]int `json:"counts"`
	PausedByRestore   []string        `json:"pausedByRestore,omitempty"`
	AlreadyPaused     []string        `json:"alreadyPaused,omitempty"`
	RecordsWithoutRun []string        `json:"recordsWithoutRun,omitempty"`
}

Report is restore.json (Decision 2 step 5): the generation loaded, the timeline the restored metastore minted, the funcd that restored it and when, the objects per kind, and the runs Decision 7 holds as <ns>/<name>.

func Run

func Run(ctx context.Context, p Point, o Options) (_ Report, err error)

Run restores the generation p names into o.Config's empty directories and leaves the platform held (Decision 2): every check, then hold.Begin and the marker, before any part is read; each store's sha256 before its Load; the canary on the new timeline; the runs paused, the master written; restore.json, the owner, then hold.End. An error removes what it created; a kill leaves restore.inprogress, which refuses the next start.

type View

type View struct {
	Meta    store.Store
	Runs    runstate.Store
	Events  *eventstore.Store
	Secrets []v1.ObjectRef
}

View is one generation loaded into memory engines (Decision 5): Meta decodes Secrets only with a secrets key, and Secrets lists them by key either way.

func Inspect

func Inspect(ctx context.Context, g Generation, o Options) (*View, error)

Inspect reads g into memory engines and writes nothing (Decision 5). With o.SecretsKey (the escrowed key file, matched against the manifest's fingerprint) Meta decodes Secrets; without, View.Secrets lists them by key only.

func (*View) Close

func (v *View) Close() error

Close releases the memory engines.

Jump to

Keyboard shortcuts

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