Documentation
¶
Overview ¶
Package backup builds, encrypts, publishes and restores profile archives. The execution Node's storage owner supplies the consistent database copy.
Index ¶
- Constants
- func Export(ctx context.Context, plan Plan, packed *Packed, id string) (protocol.BackupRecord, error)
- func Fetch(ctx context.Context, plan Plan, id string, location protocol.BackupLocation, ...) (protocol.BackupRecord, *os.File, error)
- func Finish(ctx context.Context, staged *Staged, target string, retained []string) error
- func HashFile(ctx context.Context, file *os.File, size uint64) (string, error)
- func List(ctx context.Context, plan Plan) (protocol.BackupPage, error)
- func LocalTarget(value, profile string) error
- func NewRecord(packed *Packed, id string) protocol.BackupRecord
- func Open(ctx context.Context, input io.Reader, passphrase protocol.Secret) (io.Reader, error)
- func Passphrase(value *protocol.Secret) (protocol.Secret, error)
- func Prune(ctx context.Context, plan Plan, node protocol.NodeID, temporary string) (int, error)
- func TargetPath(value, profile string) (string, error)
- func Transfer(ctx context.Context, source string, destination *os.Root, manifest Manifest) error
- func ValidIdentifier(id string) bool
- func ValidateDestination(destination protocol.BackupDestination) error
- func ValidatePassphrase(value string) error
- type Auth
- type File
- type Link
- type Manifest
- type Packed
- type Plan
- type Skipped
- type Snapshot
- type Staged
Constants ¶
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 ¶
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 List ¶
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 ¶
LocalTarget refuses a local backup directory inside or around the profile.
func Open ¶
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 ¶
Passphrase accepts a stored or supplied passphrase for sealing or opening.
func Prune ¶
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 ¶
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 ¶
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 ¶
ValidIdentifier accepts only the canonical form of a backup's request identifier.
func ValidateDestination ¶
func ValidateDestination(destination protocol.BackupDestination) error
func ValidatePassphrase ¶
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 Link ¶
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"`
Skipped []Skipped `json:"skipped,omitempty"`
SkippedTotal uint32 `json:"skipped_total,omitempty"`
}
func Unpack ¶
Unpack verifies an archive into an empty private directory. Links are checked against the manifest here and created by Transfer, in the profile they belong to. A stream that does not read as an archive is reported as damaged, apart from a failure of the destination.
func (*Manifest) RefreshDatabases ¶
RefreshDatabases recomputes the database entries after restore validation checkpointed or upgraded the staged databases.
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 Snapshot ¶
type Snapshot struct {
Directory string
Manifest Manifest
// contains filtered or unexported fields
}
Snapshot is a private copy of the profile's backup content: regular files, the symbolic links among them, and a record of what could not be copied.
func (*Snapshot) Capture ¶
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) 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.
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.