backup

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 41 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

Overview

Package backup builds, encrypts, publishes and restores profile archives. The execution Node's storage owner supplies the consistent database copy.

Index

Constants

View Source
const (
	MaxBytes    uint64 = 1024 * 1024 * 1024 * 1024
	MaxFiles           = 200_000
	MaxManifest        = 32 * 1024 * 1024
)

Variables

This section is empty.

Functions

func Export

func Export(ctx context.Context, plan Plan, packed *Packed, id string) (protocol.BackupRecord, error)

Export publishes the sealed snapshot to every enabled location.

func Fetch

func Fetch(ctx context.Context, plan Plan, id string, location protocol.BackupLocation, temporary string) (protocol.BackupRecord, *os.File, error)

Fetch downloads and verifies one sealed archive into a new file in temporary. The caller removes the returned file.

func Finish

func Finish(ctx context.Context, staged *Staged, target string, retained []string) error

Finish publishes validated staging as the target directory with one rename. retained lists staging-relative files outside the manifest that the restored profile keeps, such as the pre-upgrade database copy.

func HashFile

func HashFile(ctx context.Context, file *os.File, size uint64) (string, error)

HashFile returns the SHA-256 of an open file of a known size from its start.

func List

func List(ctx context.Context, plan Plan) (protocol.BackupPage, error)

List merges the configured locations, newest first. A location that cannot be read, a record that does not read back and copies that disagree mark the page partial instead of hiding the backups that can be restored; the call fails only when no configured location answers.

func LocalTarget

func LocalTarget(value, profile string) error

LocalTarget refuses a local backup directory inside or around the profile.

func NewRecord

func NewRecord(packed *Packed, id string) protocol.BackupRecord

func Open

func Open(ctx context.Context, input io.Reader, passphrase protocol.Secret) (io.Reader, error)

Open authenticates the archive's header with the passphrase and returns the decrypted stream; nothing plain is written. The content is authenticated chunk by chunk as it is read, and a truncated stream fails at its end. A wrong passphrase is reported apart from an input that is not an archive.

func Passphrase

func Passphrase(value *protocol.Secret) (protocol.Secret, error)

Passphrase accepts a stored or supplied passphrase for sealing or opening.

func Prune

func Prune(ctx context.Context, plan Plan, node protocol.NodeID, temporary string) (int, error)

Prune deletes the Node's own backups beyond the newest plan.Keep in every enabled location and returns how many it removed. Backups of other Nodes in a shared location, records that do not read back and every location when Keep is zero are left alone. A backup's commit marker goes first, so a half-removed backup is never listed.

func TargetPath

func TargetPath(value, profile string) (string, error)

TargetPath accepts a new or empty absolute directory for a restored profile. A non-empty profile also refuses any overlap with the running profile.

func Transfer

func Transfer(ctx context.Context, source string, destination *os.Root, manifest Manifest) error

Transfer copies verified staging into the destination's private directory and then creates the links, so that nothing is ever written through one.

func ValidIdentifier

func ValidIdentifier(id string) bool

ValidIdentifier accepts only the canonical form of a backup's request identifier.

func ValidateDestination

func ValidateDestination(destination protocol.BackupDestination) error

func ValidatePassphrase

func ValidatePassphrase(value string) error

ValidatePassphrase checks a newly chosen passphrase; existing archives keep theirs.

Types

type Auth

type Auth struct {
	Identity     *protocol.Secret
	Secret       *protocol.Secret
	SessionToken *protocol.Secret
	Passphrase   *protocol.Secret
}

Auth stays on the execution Node; no value reaches snapshots, events or faults.

type File

type File struct {
	Path   string `json:"path"`
	Size   uint64 `json:"size"`
	SHA256 string `json:"sha256"`
	Mode   uint32 `json:"mode"`
}
type Link struct {
	Path   string `json:"path"`
	Target string `json:"target"`
}

Link is a symbolic link kept as a link. Its target is stored as written and is never followed, neither by the backup nor by the restore.

type Manifest

type Manifest struct {
	Version          uint32          `json:"version"`
	Node             protocol.NodeID `json:"node"`
	OriginalProfile  string          `json:"original_profile"`
	Files            []File          `json:"files"`
	Links            []Link          `json:"links,omitempty"`
	EmptyPackageDirs []string        `json:"empty_package_dirs,omitempty"`
	Skipped          []Skipped       `json:"skipped,omitempty"`
	SkippedTotal     uint32          `json:"skipped_total,omitempty"`
}

func Unpack

func Unpack(ctx context.Context, input io.Reader, destination string) (Manifest, error)

Unpack verifies an archive into an empty private directory. Transfer creates its verified links and empty package directories in the destination profile. An unreadable stream is reported as damaged, apart from destination failures.

func (*Manifest) RefreshDatabases

func (manifest *Manifest) RefreshDatabases(ctx context.Context, root string) error

RefreshDatabases recomputes the database entries after restore validation checkpointed or upgraded the staged databases.

func (*Manifest) Validate

func (manifest *Manifest) Validate() error

type Packed

type Packed struct {
	Snapshot *Snapshot
	Path     string
	Size     uint64
	SHA256   string
}

Packed is the snapshot's sealed archive inside the snapshot directory.

type Plan

type Plan struct {
	Destination   *protocol.BackupDestination
	Local         *protocol.BackupLocal
	OnlineEnabled bool
	// Keep is how many of the Node's newest backups a location retains; zero keeps all.
	Keep      uint32
	Auth      Auth
	Transport http.RoundTripper
}

Plan is one operation's captured configuration. Transport is the Node's outbound HTTP transport and carries its proxy settings.

type Skipped

type Skipped struct {
	Path   string `json:"path"`
	Reason string `json:"reason"`
}

Skipped is content the backup left out, and why.

type Snapshot

type Snapshot struct {
	Directory string
	Manifest  Manifest
	// contains filtered or unexported fields
}

Snapshot holds the profile's staged files and the manifest that restores them.

func NewSnapshot

func NewSnapshot(profile string, node protocol.NodeID) (*Snapshot, error)

func (*Snapshot) Capture

func (snapshot *Snapshot) Capture(ctx context.Context, roots []string) error

Capture copies the profile-relative roots the storage owner listed. Only the identity is required: other content that is missing, unreadable or changing is left out and recorded.

func (*Snapshot) Close

func (snapshot *Snapshot) Close() error

func (*Snapshot) Freeze

func (snapshot *Snapshot) Freeze(ctx context.Context, name string, write func(ctx context.Context, target string) error) error

Freeze adds one database family. The storage owner writes a consistent, closed native snapshot at the supplied base path before returning.

func (*Snapshot) Pack

func (snapshot *Snapshot) Pack(ctx context.Context, passphrase protocol.Secret) (*Packed, error)

Pack writes the archive straight into its password-encrypted age stream: the manifest first, then every file and every link in path order. The plain archive never reaches the disk.

type Staged

type Staged struct {
	Directory string
	Manifest  Manifest
	Record    protocol.BackupRecord
}

Staged is a verified archive unpacked in the Node's private transfer directory, where its databases are validated before publication.

func Stage

func Stage(ctx context.Context, archive io.Reader, temporary string, known *protocol.BackupRecord, id string, size uint64, sum string) (*Staged, error)

Stage unpacks a decrypted archive stream into a new directory in temporary. A nil known record describes an uploaded archive of the given sealed size and checksum.

func (*Staged) Close

func (staged *Staged) Close() error

Jump to

Keyboard shortcuts

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