engine

package
v1.18.0 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2026 License: MIT Imports: 38 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrSnapshotNotFound means no snapshot matched a requested reference.
	ErrSnapshotNotFound = errors.New("snapshot not found")
	// ErrSnapshotRefAmbiguous means more than one snapshot matched a hash prefix.
	ErrSnapshotRefAmbiguous = errors.New("snapshot reference is ambiguous")
)
View Source
var ErrRepoLocked = errors.New("repository is locked")

ErrRepoLocked is wrapped into every error that means the repository is currently held by another operation (exclusive or shared), as opposed to an I/O failure that merely prevented telling whether it is locked. Callers use errors.Is(err, ErrRepoLocked) to distinguish the two and point the user at `break-lock` instead of a generic failure message.

Functions

func AffinityKey added in v1.16.0

func AffinityKey(parentID, fileID string) string

AffinityKey produces a locality-preserving HAMT routing key.

parentID is the raw source-level parent identifier ("" for root-level entries); fileID is the raw source-level file identifier. Borrowing the leading routing bits from the parent makes files sharing a parent share the top levels of the trie, so backing up a single changed directory rewrites a narrow spine of metadata instead of a scattered one.

This is backup policy, not a property of the HAMT: the tree only requires a hex routing key and never interprets its structure. See RFC 0002.

func AppendSnapshotCatalog added in v1.4.8

func AppendSnapshotCatalog(s store.ObjectStore, summary core.SnapshotSummary, log *logger.Logger)

AppendSnapshotCatalog loads the current catalog, appends a new summary, and persists it. This is best-effort; errors are logged but not propagated.

func CheckRepoLock added in v1.3.0

func CheckRepoLock(ctx context.Context, s store.ObjectStore) error

CheckRepoLock returns an error if the repository is currently locked by another operation (either exclusive or shared). Callers that only need to detect conflicts use this instead of acquiring their own lock.

func ParseFindTime added in v1.17.0

func ParseFindTime(spec string) (time.Time, error)

ParseFindTime parses a time specification: an RFC3339 timestamp, a plain date ("2026-01-01"), or a duration back from now ("7d", "12h").

func RemoveFromSnapshotCatalog added in v1.4.8

func RemoveFromSnapshotCatalog(s store.ObjectStore, log *logger.Logger, refs ...string)

RemoveFromSnapshotCatalog loads the current catalog, removes entries whose refs match, and persists the result. This is best-effort.

func SaveSnapshotCatalog added in v1.4.8

func SaveSnapshotCatalog(s store.ObjectStore, catalog []core.SnapshotSummary) error

SaveSnapshotCatalog persists the full catalog to the store.

func SnapshotLogger added in v1.18.0

func SnapshotLogger(w io.Writer) *logger.Logger

SnapshotLogger returns a snapshot-catalog logger writing to w.

Types

type BackupManager

type BackupManager struct {
	// contains filtered or unexported fields
}

BackupManager orchestrates a backup: scanning a source for changes, uploading new or modified files, and persisting a snapshot backed by a Merkle-HAMT.

func NewBackupManager

func NewBackupManager(src source.Source, dest store.ObjectStore, reporter ui.Reporter, hmacKey []byte, logWriter io.Writer, opts ...BackupOption) *BackupManager

func (*BackupManager) Run

func (bm *BackupManager) Run(ctx context.Context) (*RunResult, error)

Run executes a full backup: scan the source for changes, upload new/modified files, build a new HAMT root, and persist a snapshot.

type BackupOption

type BackupOption func(*backupConfig)

BackupOption configures a backup operation.

func WithBackupDryRun

func WithBackupDryRun() BackupOption

WithBackupDryRun scans the source and reports what would change without writing to the store.

func WithExcludeHash added in v1.6.0

func WithExcludeHash(hash string) BackupOption

WithExcludeHash records the hash of the active exclude patterns. When this differs from the previous snapshot the engine forces a full rescan.

func WithGenerator

func WithGenerator(name string) BackupOption

WithGenerator overrides the default generator name in snapshot metadata.

func WithIgnoreEmptySnapshot added in v1.14.0

func WithIgnoreEmptySnapshot() BackupOption

WithIgnoreEmptySnapshot skips persisting a new snapshot when the resulting tree is identical to the previous snapshot for the same source lineage.

func WithMeta

func WithMeta(key, value string) BackupOption

WithMeta adds a key-value pair to the snapshot metadata.

func WithTags

func WithTags(tags ...string) BackupOption

WithTags adds tags to the backup snapshot.

type ChangeType

type ChangeType string

ChangeType describes how a file differs between two snapshots.

const (
	ChangeAdded    ChangeType = "A"
	ChangeRemoved  ChangeType = "D"
	ChangeModified ChangeType = "M"
)

type CheckError added in v1.4.7

type CheckError struct {
	Key     string // Object key (e.g. "chunk/abc123")
	Type    string // Error category: "missing", "read_error", "corrupt", "parse_error"
	Message string
}

CheckError describes a single integrity error found during a check.

func (CheckError) String added in v1.4.7

func (e CheckError) String() string

type CheckManager added in v1.4.7

type CheckManager struct {
	// contains filtered or unexported fields
}

CheckManager verifies the integrity of a repository by walking the full reference chain and checking that every referenced object can be read.

func NewCheckManager added in v1.4.7

func NewCheckManager(s store.ObjectStore, reporter ui.Reporter, hmacKey []byte) *CheckManager

NewCheckManager creates a CheckManager.

func (*CheckManager) Run added in v1.4.7

func (cm *CheckManager) Run(ctx context.Context, opts ...CheckOption) (*CheckResult, error)

Run verifies the repository integrity.

type CheckOption added in v1.4.7

type CheckOption func(*checkConfig)

CheckOption configures a check operation.

func WithReadData added in v1.4.7

func WithReadData() CheckOption

WithReadData enables full byte-level verification: re-hash every chunk against its key, and reconstruct each file from its content manifest to confirm it still hashes to what its filemeta records.

Without it, check verifies that every referenced object is readable and that the self-addressed ones (snapshot, node, filemeta) are the bytes their keys name. That is enough to detect a broken or substituted tree, but not enough to detect corruption inside the file data itself.

func WithSnapshotRef added in v1.4.7

func WithSnapshotRef(ref string) CheckOption

WithSnapshotRef limits the check to a single snapshot instead of all.

type CheckResult added in v1.4.7

type CheckResult struct {
	SnapshotsChecked int
	ObjectsVerified  int
	Errors           []CheckError
}

CheckResult holds the outcome of a check operation.

type Chunker

type Chunker struct {
	// contains filtered or unexported fields
}

Chunker splits a byte stream into content-defined chunks, deduplicates them, and persists the resulting Content object.

func NewChunker

func NewChunker(s store.ObjectStore, hmacKey []byte) *Chunker

func (*Chunker) CreateContentObject

func (c *Chunker) CreateContentObject(ctx context.Context, chunkRefs []string, size int64, contentHash string) (string, error)

CreateContentObject persists a Content object. The object is keyed by an HMAC of the contentHash (if encryption is enabled) to prevent hash leakage, or the plain contentHash otherwise. Returns the secure contentRef (the hex hash used).

func (*Chunker) ProcessStream

func (c *Chunker) ProcessStream(ctx context.Context, r io.Reader, onProgress func(int64)) (refs []string, size int64, hash string, err error)

ProcessStream splits r into content-defined chunks and stores each one (skipping duplicates). It returns the ordered chunk refs, total byte count, and the SHA-256 content hash over the raw stream.

onProgress is called after each chunk with the number of raw bytes consumed.

type DiffManager

type DiffManager struct {
	// contains filtered or unexported fields
}

DiffManager compares two snapshots and reports file-level changes.

func NewDiffManager

func NewDiffManager(s store.ObjectStore, logWriter io.Writer) *DiffManager

func (*DiffManager) Run

func (dm *DiffManager) Run(ctx context.Context, snapID1, snapID2 string, opts ...DiffOption) (*DiffResult, error)

Run resolves two snapshot IDs and computes the diff.

type DiffOption

type DiffOption func(*diffConfig)

DiffOption configures a diff operation.

type DiffResult

type DiffResult struct {
	Ref1    string
	Ref2    string
	Changes []FileChange
}

DiffResult holds the outcome of a diff operation.

type FileChange

type FileChange struct {
	Type ChangeType
	Path string
	Meta core.FileMeta
}

FileChange is a single entry in a diff report.

type FileMatch added in v1.17.0

type FileMatch struct {
	FileID      string           `json:"file_id,omitempty"`
	ContentHash string           `json:"content_hash,omitempty"`
	Source      *core.SourceInfo `json:"source,omitempty"`
	Type        core.FileType    `json:"type,omitempty"`
	Versions    []FileVersion    `json:"versions"` // newest first
}

FileMatch is one file, with every version of it the query matched.

The grouping key is the source FileID, which is stable across renames and moves within a source — so a renamed file is one match whose versions carry different names, rather than two unrelated results. Under GroupByContent the key is ContentHash instead and FileID is empty, since the group then spans several distinct files that happen to hold identical bytes.

func (FileMatch) LatestSnapshot added in v1.17.0

func (m FileMatch) LatestSnapshot() (SnapshotRef, bool)

LatestSnapshot returns the newest snapshot holding the newest version, which is the one a follow-up restore would name.

func (FileMatch) Path added in v1.17.0

func (m FileMatch) Path() string

Path returns the match's most representative path: the first path of its newest version.

type FileVersion added in v1.17.0

type FileVersion struct {
	Ref         string        `json:"ref"`
	FileID      string        `json:"file_id"`
	Name        string        `json:"name"`
	Paths       []string      `json:"paths"`
	ContentHash string        `json:"content_hash,omitempty"`
	Type        core.FileType `json:"type,omitempty"`
	Size        int64         `json:"size"`
	Mtime       int64         `json:"mtime"`
	Mode        uint32        `json:"mode,omitempty"`
	Snapshots   []SnapshotRef `json:"snapshots"`
	FirstSeen   string        `json:"first_seen"` // ISO8601, earliest containing snapshot
	LastSeen    string        `json:"last_seen"`  // ISO8601, latest containing snapshot
}

FileVersion is one immutable state of a file: exactly the metadata object at Ref, together with every snapshot that holds it.

Paths is a slice because core.FileMeta.Parents is a list — a Google Drive file can live in two folders at once. It is also why two versions can share a Ref: renaming an ancestor folder changes a file's path without changing its own metadata object, so the same Ref legitimately appears at different paths in different snapshots.

type FindManager added in v1.17.0

type FindManager struct {
	// contains filtered or unexported fields
}

FindManager locates files across the snapshots of a repository.

It is a pure read path: no lock is taken, nothing is written, and the repository format is not stamped.

func NewFindManager added in v1.17.0

func NewFindManager(s store.ObjectStore, logWriter io.Writer) *FindManager

func (*FindManager) Run added in v1.17.0

func (fm *FindManager) Run(ctx context.Context, q FindQuery) (*FindResult, error)

Run executes the query.

A zero FindQuery is a valid search — every file in every snapshot, capped at the default result limit. MaxResults is normalized here rather than being a required field so that filling in only the predicates you care about behaves the way the rest of this module's configuration values do.

type FindQuery added in v1.17.0

type FindQuery struct {
	// Entry predicates. All given predicates must match (conjunction).
	Name        string        `json:"name,omitempty"`
	Path        string        `json:"path,omitempty"`
	Regex       string        `json:"regex,omitempty"`
	IgnoreCase  bool          `json:"ignore_case,omitempty"`
	FileID      string        `json:"file_id,omitempty"`
	ContentHash string        `json:"content_hash,omitempty"`
	Ref         string        `json:"ref,omitempty"`
	Type        core.FileType `json:"type,omitempty"`
	Size        *SizeCompare  `json:"size,omitempty"`
	Newer       string        `json:"newer,omitempty"` // RFC3339 or a duration like "7d"
	Older       string        `json:"older,omitempty"`

	// Snapshot selectors.
	Snapshots []string `json:"snapshots,omitempty"`
	Source    string   `json:"source,omitempty"`
	Tags      []string `json:"tags,omitempty"`
	Latest    int      `json:"latest,omitempty"`
	Since     string   `json:"since,omitempty"`
	Until     string   `json:"until,omitempty"`

	// Presentation and execution.
	GroupByContent bool `json:"group_by_content,omitempty"`
	MaxResults     int  `json:"max_results,omitempty"`
	NoDelta        bool `json:"no_delta,omitempty"`
}

FindQuery is the complete, serializable description of one find. It is echoed back on FindResult so a JSON consumer can tell what produced the matches without re-deriving it from the command line.

Entry predicates (Name through Older) select files. Snapshot selectors (Snapshots through Until) select which snapshots are searched. The two are deliberately separate vocabularies: -newer/-older filter by a file's Mtime, -since/-until filter by a snapshot's creation time.

func (*FindQuery) SetPattern added in v1.18.0

func (q *FindQuery) SetPattern(pattern string)

SetPattern applies a positional pattern, routing it by shape: a pattern containing a separator constrains the full path, one without it constrains the basename. This split is what keeps the common case cheap — a basename is on the metadata object already, a path has to be reconstructed.

It is a method rather than a plain field because that routing is a decision, not a value: a caller who assigned Path directly would silently make every basename search pay for path reconstruction.

type FindResult added in v1.17.0

type FindResult struct {
	Query             FindQuery   `json:"query"`
	SnapshotsSearched int         `json:"snapshots_searched"`
	EntriesScanned    int         `json:"entries_scanned"`
	MetaFetched       int         `json:"meta_fetched"` // filemeta objects actually read
	Matches           []FileMatch `json:"matches"`
	Truncated         bool        `json:"truncated"`
	Warnings          []string    `json:"warnings,omitempty"`
	GroupedBy         string      `json:"grouped_by"` // "file" or "content"
	Elapsed           string      `json:"elapsed,omitempty"`
}

FindResult is the outcome of one query.

func (*FindResult) TotalSnapshots added in v1.17.0

func (r *FindResult) TotalSnapshots() int

TotalSnapshots counts the distinct snapshots any match was found in.

func (*FindResult) TotalVersions added in v1.17.0

func (r *FindResult) TotalVersions() int

TotalVersions counts versions across every match.

type ForgetManager

type ForgetManager struct {
	// contains filtered or unexported fields
}

ForgetManager removes a snapshot and its index pointers, optionally pruning unreachable objects afterwards.

func NewForgetManager

func NewForgetManager(s store.ObjectStore, reporter ui.Reporter, logWriter io.Writer) *ForgetManager

func (*ForgetManager) Run

func (fm *ForgetManager) Run(ctx context.Context, snapshotID string, opts ...ForgetOption) (*ForgetResult, error)

Run removes the snapshot identified by snapshotID.

func (*ForgetManager) RunPolicy

func (fm *ForgetManager) RunPolicy(ctx context.Context, opts ...ForgetOption) (*PolicyResult, error)

RunPolicy applies a retention policy to all snapshots and removes those not matched by any keep rule. Use WithKeepLast, WithKeepDaily, etc. to configure.

type ForgetOption

type ForgetOption func(*forgetConfig)

ForgetOption configures a forget operation.

func WithDryRun

func WithDryRun() ForgetOption

WithDryRun shows what would be removed without actually removing anything.

func WithFilterAccount

func WithFilterAccount(account string) ForgetOption

WithFilterAccount restricts the policy to snapshots from this account.

func WithFilterPath

func WithFilterPath(path string) ForgetOption

WithFilterPath restricts the policy to snapshots from this path.

func WithFilterSource

func WithFilterSource(source string) ForgetOption

WithFilterSource restricts the policy to snapshots from this source type.

func WithFilterTag

func WithFilterTag(tag string) ForgetOption

WithFilterTag restricts the policy to snapshots that have this tag.

func WithGroupBy

func WithGroupBy(fields string) ForgetOption

WithGroupBy sets the fields used to group snapshots for policy application. Comma-separated list of: source, account, path, tags. Empty string disables grouping.

func WithKeepDaily

func WithKeepDaily(n int) ForgetOption

WithKeepDaily keeps one snapshot per day for the last n days that have snapshots.

func WithKeepHourly

func WithKeepHourly(n int) ForgetOption

WithKeepHourly keeps one snapshot per hour for the last n hours that have snapshots.

func WithKeepLast

func WithKeepLast(n int) ForgetOption

WithKeepLast keeps the n most recent snapshots.

func WithKeepMonthly

func WithKeepMonthly(n int) ForgetOption

WithKeepMonthly keeps one snapshot per month for the last n months that have snapshots.

func WithKeepWeekly

func WithKeepWeekly(n int) ForgetOption

WithKeepWeekly keeps one snapshot per ISO week for the last n weeks that have snapshots.

func WithKeepYearly

func WithKeepYearly(n int) ForgetOption

WithKeepYearly keeps one snapshot per year for the last n years that have snapshots.

func WithPrune

func WithPrune() ForgetOption

WithPrune runs a prune pass after forgetting snapshots.

type ForgetPolicy

type ForgetPolicy struct {
	KeepLast    int
	KeepHourly  int
	KeepDaily   int
	KeepWeekly  int
	KeepMonthly int
	KeepYearly  int
}

ForgetPolicy describes which snapshots to keep.

func (ForgetPolicy) IsEmpty

func (p ForgetPolicy) IsEmpty() bool

func (ForgetPolicy) String

func (p ForgetPolicy) String() string

type ForgetResult

type ForgetResult struct {
	Prune *PruneResult // nil when prune was not requested

	// DryRun reports that nothing was written. Callers need this to tell a
	// preview from a real mutation — stamping the repository format after a
	// dry run would make a read-only command lock other machines out.
	DryRun bool
}

ForgetResult holds the outcome of a forget operation.

type GroupKey

type GroupKey struct {
	Source  string
	Account string
	Path    string
	Tags    string // sorted, comma-joined
}

GroupKey identifies a group of snapshots for policy application.

func (GroupKey) String

func (k GroupKey) String() string

type InitManager added in v1.7.0

type InitManager struct {
	// contains filtered or unexported fields
}

InitManager bootstraps a new repository: creates encryption key slots and writes the "config" marker.

func NewInitManager added in v1.7.0

func NewInitManager(s store.ObjectStore, logWriter io.Writer) *InitManager

NewInitManager creates an InitManager that operates on the raw (undecorated) object store.

func (*InitManager) Run added in v1.7.0

func (m *InitManager) Run(ctx context.Context, opts ...InitOption) (*InitResult, error)

Run executes the init operation.

type InitOption added in v1.7.0

type InitOption func(*initConfig)

InitOption configures an init operation.

func WithInitAdoptSlots added in v1.9.0

func WithInitAdoptSlots() InitOption

WithInitAdoptSlots allows initialization to succeed even if key slots already exist.

func WithInitCredentials added in v1.9.0

func WithInitCredentials(chain keychain.Chain) InitOption

WithInitCredentials configures the keychain to use for initialization.

func WithInitNoEncryption added in v1.7.0

func WithInitNoEncryption() InitOption

WithInitNoEncryption creates an unencrypted repository.

func WithInitRecovery added in v1.7.0

func WithInitRecovery() InitOption

WithInitRecovery requests generation of a recovery key during init.

type InitResult added in v1.7.0

type InitResult struct {
	Encrypted    bool
	AdoptedSlots bool   // true if existing key slots were adopted
	RecoveryKey  string // BIP39 24-word mnemonic; empty if not requested
}

InitResult holds the outcome of an init operation.

type KeepReason

type KeepReason struct {
	Entry   SnapshotEntry
	Reasons []string
}

KeepReason pairs a snapshot with the reasons it was kept.

type ListManager

type ListManager struct {
	// contains filtered or unexported fields
}

ListManager enumerates all available snapshots.

func NewListManager

func NewListManager(s store.ObjectStore, logWriter io.Writer) *ListManager

func (*ListManager) Run

func (lm *ListManager) Run(ctx context.Context, opts ...ListOption) (*ListResult, error)

Run lists every snapshot in the store.

type ListOption

type ListOption func(*listConfig)

ListOption configures a list operation.

type ListResult

type ListResult struct {
	Snapshots []SnapshotEntry
}

ListResult holds the snapshots returned by a list operation.

type LockHandle added in v1.3.0

type LockHandle struct {
	// contains filtered or unexported fields
}

LockHandle is returned by AcquireRepoLock and must be released when the operation completes. A background goroutine refreshes the lock every refreshRate so that the TTL stays short (fast recovery on crash) while supporting arbitrarily long operations.

cancel cancels the operation context returned alongside the handle. It is called by Release on normal completion, and by the refresh goroutine the moment it can no longer prove ownership of the lock — so an operation that has lost its lock (TTL expired after a sleep, or another machine took over) is aborted rather than left writing into a repository someone else now owns.

func AcquireRepoLock added in v1.3.0

func AcquireRepoLock(ctx context.Context, s store.ObjectStore, operation string) (*LockHandle, context.Context, error)

AcquireRepoLock creates an exclusive lock for operation. If another non-expired lock exists (exclusive or shared), the call returns an error.

The returned context is derived from ctx and is cancelled if the lock is ever lost while held, so the caller must run the operation under it rather than under the original ctx.

To mitigate TOCTOU races on stores without conditional writes, the lock is written and then immediately re-read to verify this process still owns it.

func AcquireSharedLock added in v1.3.0

func AcquireSharedLock(ctx context.Context, s store.ObjectStore, operation string) (*LockHandle, context.Context, error)

AcquireSharedLock creates a shared lock for an operation (like backup or restore). If an exclusive lock exists, the call returns an error. Multiple shared locks can exist simultaneously.

The returned context is derived from ctx and is cancelled if the lock is ever lost while held, so the caller must run the operation under it rather than under the original ctx.

func (*LockHandle) Release added in v1.3.0

func (h *LockHandle) Release()

Release stops the refresh goroutine and deletes the lock only if this handle still owns it (prevents deleting a lock acquired by another process after ours expired).

type LsSnapshotManager

type LsSnapshotManager struct {
	// contains filtered or unexported fields
}

LsSnapshotManager lists the file tree of a single snapshot.

func NewLsSnapshotManager

func NewLsSnapshotManager(s store.ObjectStore, logWriter io.Writer) *LsSnapshotManager

func (*LsSnapshotManager) Run

func (lm *LsSnapshotManager) Run(ctx context.Context, snapshotID string, opts ...LsSnapshotOption) (*LsSnapshotResult, error)

Run resolves the snapshot, collects metadata, and returns the tree structure.

type LsSnapshotOption

type LsSnapshotOption func(*lsSnapshotConfig)

LsSnapshotOption configures an ls-snapshot operation.

type LsSnapshotResult

type LsSnapshotResult struct {
	Ref       string
	Snapshot  core.Snapshot
	RootRefs  []string
	RefToMeta map[string]core.FileMeta
	ChildRefs map[string][]string
}

LsSnapshotResult holds the data returned by an ls-snapshot operation.

type PolicyGroupResult

type PolicyGroupResult struct {
	Key    GroupKey
	Keep   []KeepReason
	Remove []SnapshotEntry
}

PolicyGroupResult holds the policy evaluation result for a single group.

type PolicyResult

type PolicyResult struct {
	Groups []PolicyGroupResult
	Prune  *PruneResult

	// DryRun reports that nothing was written. See ForgetResult.DryRun.
	DryRun bool
}

PolicyResult holds the outcome of a policy-based forget operation.

type PruneManager

type PruneManager struct {
	// contains filtered or unexported fields
}

PruneManager implements mark-and-sweep garbage collection over the object store.

func NewPruneManager

func NewPruneManager(s store.ObjectStore, reporter ui.Reporter) *PruneManager

func (*PruneManager) Run

func (pm *PruneManager) Run(ctx context.Context, opts ...PruneOption) (*PruneResult, error)

type PruneOption

type PruneOption func(*pruneConfig)

func WithPruneDryRun

func WithPruneDryRun() PruneOption

type PruneResult

type PruneResult struct {
	BytesReclaimed int64
	ObjectsDeleted int
	ObjectsScanned int
	DryRun         bool
}

type RepoLock added in v1.3.0

type RepoLock struct {
	Operation  string `json:"operation"`
	Holder     string `json:"holder"`
	AcquiredAt string `json:"acquired_at"`
	ExpiresAt  string `json:"expires_at"`
	IsShared   bool   `json:"is_shared,omitempty"`
}

RepoLock is the JSON payload stored at index/lock (or index/lock/shared/<uuid>).

func BreakRepoLock added in v1.3.0

func BreakRepoLock(ctx context.Context, s store.ObjectStore) ([]*RepoLock, error)

BreakRepoLock forcibly removes the repository lock (exclusive and shared) regardless of who holds it. Returns the locks that were removed.

type RestoreManager

type RestoreManager struct {
	// contains filtered or unexported fields
}

RestoreManager recreates a snapshot's file tree using a RestoreWriter output format.

func NewRestoreManager

func NewRestoreManager(s store.ObjectStore, reporter ui.Reporter) *RestoreManager

func (*RestoreManager) Run

func (rm *RestoreManager) Run(ctx context.Context, writer RestoreWriter, snapshotRef string, opts ...RestoreOption) (*RestoreResult, error)

Run restores the snapshot's file tree to the provided writer format. snapshotRef can be "", "latest", a bare hash, or "snapshot/<hash>".

type RestoreOption

type RestoreOption func(*restoreConfig)

RestoreOption configures a restore operation.

func WithRestoreDryRun

func WithRestoreDryRun() RestoreOption

WithRestoreDryRun resolves the snapshot and reports what would be restored without writing output.

func WithRestoreNoVerify added in v1.16.0

func WithRestoreNoVerify() RestoreOption

WithRestoreNoVerify skips the content-hash check that restore normally runs over every file it writes. Verification is on by default; this exists as an escape hatch for the case where a snapshot records a hash that disagrees with its own content, so that the data can still be recovered.

func WithRestorePath added in v1.4.7

func WithRestorePath(p string) RestoreOption

WithRestorePath limits the restore to files matching the given path. If the path ends with "/", all files under that subtree are included. Otherwise, only the file with the exact path is restored.

type RestoreResult

type RestoreResult struct {
	SnapshotRef  string
	Root         string
	FilesWritten int
	DirsWritten  int
	BytesWritten int64
	Errors       int
	Warnings     int
	DryRun       bool
}

RestoreResult holds the outcome of a restore operation.

type RestoreWriter added in v1.12.0

type RestoreWriter interface {
	MkdirAll(path string, meta core.FileMeta) error
	WriteFile(path string, meta core.FileMeta, writeContent func(io.Writer) error) error
	BytesWritten() int64
	Close() error
}

RestoreWriter is the output abstraction for restore formats.

func NewFSRestoreWriter added in v1.12.0

func NewFSRestoreWriter(root string) (RestoreWriter, error)

func NewZipRestoreWriter added in v1.12.0

func NewZipRestoreWriter(w io.Writer) RestoreWriter

type RunResult

type RunResult struct {
	SnapshotHash         string
	SnapshotRef          string
	Root                 string
	FilesNew             int64
	FilesChanged         int64
	FilesUnmodified      int64
	FilesRemoved         int64
	DirsNew              int64
	DirsChanged          int64
	DirsUnmodified       int64
	DirsRemoved          int64
	BytesAddedRaw        int64
	BytesAddedStored     int64
	Duration             time.Duration
	DryRun               bool
	EmptySnapshotIgnored bool
}

RunResult holds the outcome of a successful backup run.

type SizeCompare added in v1.17.0

type SizeCompare struct {
	Op    SizeOp `json:"op"`
	Bytes int64  `json:"bytes"`
}

SizeCompare is a parsed size predicate.

func ParseSizeCompare added in v1.17.0

func ParseSizeCompare(spec string) (SizeCompare, error)

ParseSizeCompare parses find(1)'s size syntax: an optional "+" (at least) or "-" (at most), a number, and an optional binary suffix (k, M, G, T).

func (SizeCompare) String added in v1.17.0

func (s SizeCompare) String() string

type SizeOp added in v1.17.0

type SizeOp string

SizeOp is the comparison a size predicate applies, in find(1)'s vocabulary: "+10M" is at least, "-10M" is at most, a bare "10M" is exactly.

const (
	SizeAtLeast SizeOp = "+"
	SizeAtMost  SizeOp = "-"
	SizeExactly SizeOp = "="
)

type SnapshotEntry

type SnapshotEntry struct {
	Ref     string
	Snap    core.Snapshot
	Created time.Time
}

SnapshotEntry is a snapshot loaded for policy evaluation.

func LoadSnapshotCatalog added in v1.4.8

func LoadSnapshotCatalog(s store.ObjectStore, log *logger.Logger) ([]SnapshotEntry, error)

LoadSnapshotCatalog returns all snapshots, using the catalog index when available and falling back to individual GETs only for snapshots that are missing from the catalog. The catalog is automatically rebuilt/updated whenever a mismatch with the live snapshot keys is detected. Results are sorted newest-first by Created time.

type SnapshotRef added in v1.17.0

type SnapshotRef struct {
	Ref     string `json:"ref"`
	Seq     int    `json:"seq"`
	Created string `json:"created"` // ISO8601
}

SnapshotRef identifies one snapshot a version was found in.

Jump to

Keyboard shortcuts

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