backup

package
v0.3.0 Latest Latest
Warning

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

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

Documentation

Overview

Package backup makes, checks and restores backups of an instance (PHASE1 step 16): every database as one consistent copy (VACUUM INTO, also while the server runs), the audit databases last, a manifest with SHA-256 per file and the head of every audit chain. A restore goes only into an empty data directory and only after every check passed.

Index

Constants

View Source
const (
	ActionBackup  = "system.backup"
	ActionRestore = "system.restore"
)

Audit actions in the instance log.

View Source
const Format = "myownpki-backup/1"

Format names the layout of a backup directory.

View Source
const KindAuthKey store.Kind = "auth_key"

KindAuthKey marks auth.key in the manifest.

View Source
const ManifestFile = "manifest.json"

ManifestFile is written last: a directory without it is not a backup.

View Source
const MaxKeep = 1000

MaxKeep bounds --keep.

View Source
const UnverifiedSuffix = "-unverified"

UnverifiedSuffix marks a scheduled backup whose check failed; Prune never deletes it and it doesn't count as one of the kept backups.

View Source
const Warning = "This backup holds the CA and certificate keys, encrypted with the root key. " +
	"Keep the unseal passphrase and the recovery key apart from it – whoever has both can sign as your CAs."

Warning is shown at every backup (owner decision 2).

Variables

View Source
var ErrRefused = errors.New("the backup is refused")

ErrRefused wraps the problems of a backup that may not be restored.

Functions

func ScheduledName added in v0.2.2

func ScheduledName(t time.Time) string

ScheduledName is the directory name of a scheduled backup made at t.

Types

type File

type File struct {
	Path      string     `json:"path"`
	Kind      store.Kind `json:"kind"` // system, pki, audit; "auth_key"
	Tenant    string     `json:"tenant,omitempty"`
	SHA256    string     `json:"sha256"`
	Size      int64      `json:"size"`
	Migration int        `json:"migration,omitempty"`
}

File is one file of the backup; Path is relative to the data directory.

type Log

type Log struct {
	Scope          string                `json:"scope"`
	Path           string                `json:"path"`
	Head           string                `json:"head"` // seq:hash
	Entries        int64                 `json:"entries"`
	LastCheckpoint *audit.CheckpointInfo `json:"last_checkpoint,omitempty"`
}

Log is the state of one audit log in the backup.

type Manifest

type Manifest struct {
	Format    string   `json:"format"`
	CreatedAt string   `json:"created_at"`
	Version   string   `json:"version"`
	Tenants   []string `json:"tenants"`
	Files     []File   `json:"files"`
	Audit     []Log    `json:"audit"`
	// CheckpointKey is the fingerprint of the key that signs the audit
	// checkpoints – compare it with the one noted at init.
	CheckpointKey string `json:"checkpoint_key"`
	// AuthKey: auth.key is in the backup (it lived in the data directory).
	AuthKey bool `json:"auth_key_included"`
}

Manifest describes a backup.

func Create

func Create(ctx context.Context, dir string, o Options) (*Manifest, error)

Create writes a backup into dir, which must not exist yet.

type Options

type Options struct {
	Layout      store.Layout
	AuthKeyFile string // config auth.key_file
	Clock       clock.Clock
	Who         keys.Who
}

Options for Create and Restore.

type PruneResult added in v0.2.2

type PruneResult struct {
	Kept    []string // the newest valid scheduled backups, newest first
	Deleted []string // oldest first
	Skipped []Skipped
}

PruneResult says what Prune did (or, with dryRun, would do).

func Prune added in v0.2.2

func Prune(parent string, keep int, dryRun bool) (*PruneResult, error)

Prune keeps the newest keep scheduled backups in parent and deletes the older ones. keep must be at least 1, so the newest backup always stays.

func (*PruneResult) String added in v0.2.2

func (r *PruneResult) String() string

String sums a result up in one line.

type Report

type Report struct {
	Manifest *Manifest
	// Problems refuse a restore.
	Problems []string
	// Certificates whose name index was compared.
	Certificates int
	// Notes are for the operator (auth.key, migrations to apply).
	Notes []string
}

Report is the result of checking a backup.

func Restore

func Restore(ctx context.Context, dir, pin string, o Options) (*Report, error)

Restore checks the backup and moves it into the data directory of o, which must be empty or missing. pin as for Verify.

func Verify

func Verify(ctx context.Context, dir, pin string) (*Report, error)

Verify runs every check of a restore on a copy and writes nothing else. pin is the checkpoint key fingerprint noted at init ("" = all checkpoints must use the key the manifest names).

type Skipped added in v0.2.2

type Skipped struct {
	Name, Reason string
}

Skipped is a directory that looks like a scheduled backup but is left alone.

type TimerStatus added in v0.2.2

type TimerStatus struct {
	// Newest is the time of the newest scheduled backup (from its name);
	// zero = there is none. A backup that failed its check doesn't count.
	Newest time.Time
	// Unverified are the backups that failed their check, oldest first.
	Unverified []string
}

TimerStatus is what the dashboard shows about the scheduled backups in a directory (v0.2.2, owner 2026-10-24).

func ReadTimerStatus added in v0.2.2

func ReadTimerStatus(parent string) (TimerStatus, error)

ReadTimerStatus lists parent by name only – it opens no backup, so the dashboard can call it on every view. A missing parent is no error: the timer hasn't run yet (or isn't installed).

func (TimerStatus) Seen added in v0.2.2

func (s TimerStatus) Seen() bool

Seen reports whether the timer has ever written a backup here.

Jump to

Keyboard shortcuts

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