engine

package
v1.17.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: MIT Imports: 41 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")
)

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)

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 EnsureProfilesMaps added in v1.17.0

func EnsureProfilesMaps(cfg *ProfilesConfig)

EnsureProfilesMaps guarantees cfg's map fields are non-nil, so callers can write into them unconditionally.

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, refs ...string)

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

func SaveProfilesFile added in v1.11.0

func SaveProfilesFile(path string, cfg *ProfilesConfig) error

SaveProfilesFile writes a profiles YAML file atomically.

func SaveSnapshotCatalog added in v1.4.8

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

SaveSnapshotCatalog persists the full catalog to the store.

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, 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.

func WithVerbose

func WithVerbose() BackupOption

WithVerbose enables verbose output during backup.

type BackupProfile added in v1.11.0

type BackupProfile struct {
	Source            string   `yaml:"source"`
	Store             string   `yaml:"store,omitempty"`
	AuthRef           string   `yaml:"auth_ref,omitempty"`
	Tags              []string `yaml:"tags,omitempty"`
	Excludes          []string `yaml:"excludes,omitempty"`
	ExcludeFile       string   `yaml:"exclude_file,omitempty"`
	IgnoreEmpty       bool     `yaml:"ignore_empty,omitempty"`
	SkipNativeFiles   bool     `yaml:"skip_native_files,omitempty"`
	VolumeUUID        string   `yaml:"volume_uuid,omitempty"`
	GoogleCreds       string   `yaml:"google_credentials,omitempty"`
	GoogleCredsRef    string   `yaml:"google_credentials_ref,omitempty"`
	GoogleCredsJSON   string   `yaml:"google_credentials_json,omitempty"`
	GoogleTokenFile   string   `yaml:"google_token_file,omitempty"`
	GoogleTokenRef    string   `yaml:"google_token_ref,omitempty"`
	OneDriveClientID  string   `yaml:"onedrive_client_id,omitempty"`
	OneDriveTokenFile string   `yaml:"onedrive_token_file,omitempty"`
	OneDriveTokenRef  string   `yaml:"onedrive_token_ref,omitempty"`
	Enabled           *bool    `yaml:"enabled,omitempty"`
}

BackupProfile defines one backup job preset.

func (BackupProfile) IsEnabled added in v1.11.0

func (p BackupProfile) IsEnabled() bool

IsEnabled reports whether the profile should be included in -all-profiles.

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 WithCheckVerbose added in v1.4.7

func WithCheckVerbose() CheckOption

WithCheckVerbose logs each verified object.

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) *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.

func WithDiffVerbose added in v1.6.0

func WithDiffVerbose() DiffOption

WithDiffVerbose enables verbose output for the diff operation.

type DiffResult

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

DiffResult holds the outcome of a diff operation.

type DiscoveredSource added in v1.14.0

type DiscoveredSource struct {
	SourceURI   string `json:"source_uri"`
	DisplayName string `json:"display_name"`
	MountPoint  string `json:"mount_point"`
	DriveName   string `json:"drive_name,omitempty"`
	Identity    string `json:"identity,omitempty"`
	PathID      string `json:"path_id,omitempty"`
	FsType      string `json:"fs_type,omitempty"`
	Portable    bool   `json:"portable"`
}

DiscoveredSource describes a local source candidate that can be used for onboarding and source selection flows.

func DiscoverSources added in v1.14.0

func DiscoverSources(_ context.Context) ([]DiscoveredSource, error)

DiscoverSources returns local source candidates suitable for workstation onboarding and source-selection UX.

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) *FindManager

func (*FindManager) Run added in v1.17.0

func (fm *FindManager) Run(ctx context.Context, opts ...FindOption) (*FindResult, error)

Run executes the query.

type FindOption added in v1.17.0

type FindOption func(*findConfig)

FindOption configures a find operation.

func WithFindContentHash added in v1.17.0

func WithFindContentHash(hash string) FindOption

func WithFindFileID added in v1.17.0

func WithFindFileID(id string) FindOption

func WithFindGroupByContent added in v1.17.0

func WithFindGroupByContent() FindOption

WithFindGroupByContent regroups the same matches by content hash instead of by file identity, which is how duplicate content is found. It changes grouping only, never which entries matched.

func WithFindIgnoreCase added in v1.17.0

func WithFindIgnoreCase() FindOption

func WithFindLatest added in v1.17.0

func WithFindLatest(n int) FindOption

WithFindLatest restricts the search to the n newest selected snapshots.

func WithFindMaxResults added in v1.17.0

func WithFindMaxResults(n int) FindOption

func WithFindName added in v1.17.0

func WithFindName(pattern string) FindOption

func WithFindNewer added in v1.17.0

func WithFindNewer(spec string) FindOption

WithFindNewer and WithFindOlder filter by a file's Mtime. They accept RFC3339 or a duration such as "7d", which is read relative to now.

func WithFindNoDelta added in v1.17.0

func WithFindNoDelta() FindOption

WithFindNoDelta forces the straightforward per-snapshot walk instead of the delta scan. It exists so a suspected delta-scan bug can be confirmed against an implementation with nowhere to hide, and so the two can be compared in tests.

func WithFindOlder added in v1.17.0

func WithFindOlder(spec string) FindOption

func WithFindPath added in v1.17.0

func WithFindPath(pattern string) FindOption

func WithFindPattern added in v1.17.0

func WithFindPattern(pattern string) FindOption

WithFindPattern applies the 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.

func WithFindRef added in v1.17.0

func WithFindRef(ref string) FindOption

func WithFindRegex added in v1.17.0

func WithFindRegex(expr string) FindOption

func WithFindSince added in v1.17.0

func WithFindSince(spec string) FindOption

WithFindSince and WithFindUntil filter by a snapshot's creation time, not by any file's Mtime — that is what WithFindNewer and WithFindOlder do.

func WithFindSize added in v1.17.0

func WithFindSize(cmp SizeCompare) FindOption

func WithFindSnapshots added in v1.17.0

func WithFindSnapshots(refs ...string) FindOption

WithFindSnapshots restricts the search to the named snapshots. Refs may be full ("snapshot/<hash>"), bare hashes, unambiguous prefixes, or "latest".

func WithFindSource added in v1.17.0

func WithFindSource(uri string) FindOption

func WithFindTags added in v1.17.0

func WithFindTags(tags ...string) FindOption

func WithFindType added in v1.17.0

func WithFindType(t core.FileType) FindOption

func WithFindUntil added in v1.17.0

func WithFindUntil(spec string) FindOption

func WithFindVerbose added in v1.17.0

func WithFindVerbose() FindOption

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 QueryFromOptions added in v1.17.0

func QueryFromOptions(opts ...FindOption) FindQuery

QueryFromOptions resolves a set of options into the query they describe, defaults filled in. Run uses it; callers that want to show or record what a query will do before running it can too.

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) *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 WithForgetVerbose added in v1.6.0

func WithForgetVerbose() ForgetOption

WithForgetVerbose enables verbose output for the forget operation.

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) *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) *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.

func WithListVerbose added in v1.6.0

func WithListVerbose() ListOption

WithListVerbose enables verbose output for the 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) *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.

func WithLsVerbose added in v1.6.0

func WithLsVerbose() LsSnapshotOption

WithLsVerbose enables verbose output for the 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 ProfileAuth added in v1.11.0

type ProfileAuth struct {
	Provider          string `yaml:"provider"` // google | onedrive
	GoogleCreds       string `yaml:"google_credentials,omitempty"`
	GoogleCredsRef    string `yaml:"google_credentials_ref,omitempty"`
	GoogleCredsJSON   string `yaml:"google_credentials_json,omitempty"`
	GoogleTokenFile   string `yaml:"google_token_file,omitempty"`
	GoogleTokenRef    string `yaml:"google_token_ref,omitempty"`
	OneDriveClientID  string `yaml:"onedrive_client_id,omitempty"`
	OneDriveTokenFile string `yaml:"onedrive_token_file,omitempty"`
	OneDriveTokenRef  string `yaml:"onedrive_token_ref,omitempty"`
}

ProfileAuth defines reusable OAuth settings for cloud providers.

type ProfileStore added in v1.11.0

type ProfileStore struct {
	URI               string `yaml:"uri"`
	S3Endpoint        string `yaml:"s3_endpoint,omitempty"`
	S3Region          string `yaml:"s3_region,omitempty"`
	S3Profile         string `yaml:"s3_profile,omitempty"`
	S3AccessKey       string `yaml:"s3_access_key,omitempty"`
	S3SecretKey       string `yaml:"s3_secret_key,omitempty"`
	B2KeyID           string `yaml:"b2_key_id,omitempty"`
	B2AppKey          string `yaml:"b2_app_key,omitempty"`
	StoreSFTPPassword string `yaml:"store_sftp_password,omitempty"`
	StoreSFTPKey      string `yaml:"store_sftp_key,omitempty"`

	// Encryption: env var indirection for secrets, direct values for non-secrets.
	PasswordSecret          string `yaml:"password_secret,omitempty"`
	EncryptionKeySecret     string `yaml:"encryption_key_secret,omitempty"`
	RecoveryKeySecret       string `yaml:"recovery_key_secret,omitempty"`
	S3AccessKeySecret       string `yaml:"s3_access_key_secret,omitempty"`
	S3SecretKeySecret       string `yaml:"s3_secret_key_secret,omitempty"`
	B2KeyIDSecret           string `yaml:"b2_key_id_secret,omitempty"`
	B2AppKeySecret          string `yaml:"b2_app_key_secret,omitempty"`
	StoreSFTPPasswordSecret string `yaml:"store_sftp_password_secret,omitempty"`
	StoreSFTPKeySecret      string `yaml:"store_sftp_key_secret,omitempty"`
	KMSKeyARN               string `yaml:"kms_key_arn,omitempty"`
	KMSRegion               string `yaml:"kms_region,omitempty"`
	KMSEndpoint             string `yaml:"kms_endpoint,omitempty"`
}

ProfileStore defines reusable backend settings.

type ProfilesConfig added in v1.11.0

type ProfilesConfig struct {
	Version  int                      `yaml:"version"`
	Stores   map[string]ProfileStore  `yaml:"stores"`
	Auth     map[string]ProfileAuth   `yaml:"auth"`
	Profiles map[string]BackupProfile `yaml:"profiles"`
}

ProfilesConfig is the top-level YAML document for backup profiles.

func LoadProfilesFile added in v1.11.0

func LoadProfilesFile(path string) (*ProfilesConfig, error)

LoadProfilesFile reads and parses a profiles YAML file.

func LoadProfilesFileOrEmpty added in v1.17.0

func LoadProfilesFileOrEmpty(path string) (*ProfilesConfig, error)

LoadProfilesFileOrEmpty loads profiles from path, treating a missing file as an empty, version-1 config rather than an error. Callers that only read or manage profiles (list, setup, the TUI) want this; callers running a command against a named profile want LoadProfilesFile's hard error, since a silently-empty config there would misreport "unknown profile" instead of "no profiles file".

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

func WithPruneVerbose

func WithPruneVerbose() 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.

func WithRestoreVerbose

func WithRestoreVerbose() RestoreOption

WithRestoreVerbose logs each file/dir being written.

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) ([]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.

type WorkstationApplyResult added in v1.14.0

type WorkstationApplyResult struct {
	ProfilesCreated int      `json:"profiles_created"`
	ProfilesUpdated int      `json:"profiles_updated"`
	ProfileNames    []string `json:"profile_names,omitempty"`
}

func ApplyWorkstationSetupPlan added in v1.14.0

func ApplyWorkstationSetupPlan(cfg *ProfilesConfig, plan *WorkstationSetupPlan) (*WorkstationApplyResult, error)

type WorkstationCoverageSummary added in v1.14.0

type WorkstationCoverageSummary struct {
	ProtectedNow         []string `json:"protected_now,omitempty"`
	SkippedIntentionally []string `json:"skipped_intentionally,omitempty"`
	NotAvailableNow      []string `json:"not_available_now,omitempty"`
	Warnings             []string `json:"warnings,omitempty"`
}

type WorkstationFolderCandidate added in v1.14.0

type WorkstationFolderCandidate struct {
	Key      string `json:"key"`
	Label    string `json:"label"`
	Category string `json:"category"`
	Path     string `json:"path"`
	Selected bool   `json:"selected"`
}

type WorkstationProfileDraft added in v1.14.0

type WorkstationProfileDraft struct {
	Name         string   `json:"name"`
	SourceURI    string   `json:"source_uri"`
	StoreRef     string   `json:"store_ref,omitempty"`
	Tags         []string `json:"tags,omitempty"`
	Action       string   `json:"action"`
	DisplayLabel string   `json:"display_label,omitempty"`
	Selected     bool     `json:"selected"`
}

type WorkstationSetupOption added in v1.14.0

type WorkstationSetupOption func(*workstationSetupOptions)

func WithWorkstationDryRun added in v1.14.0

func WithWorkstationDryRun() WorkstationSetupOption

func WithWorkstationProfiles added in v1.14.0

func WithWorkstationProfiles(cfg *ProfilesConfig) WorkstationSetupOption

func WithWorkstationStoreRef added in v1.14.0

func WithWorkstationStoreRef(name string) WorkstationSetupOption

type WorkstationSetupPlan added in v1.14.0

type WorkstationSetupPlan struct {
	Hostname        string                       `json:"hostname"`
	StoreRef        string                       `json:"store_ref,omitempty"`
	StoreAction     string                       `json:"store_action"`
	Folders         []WorkstationFolderCandidate `json:"folders,omitempty"`
	PortableSources []DiscoveredSource           `json:"portable_sources,omitempty"`
	Profiles        []WorkstationProfileDraft    `json:"profiles,omitempty"`
	Coverage        WorkstationCoverageSummary   `json:"coverage"`
}

func PlanWorkstationSetup added in v1.14.0

func PlanWorkstationSetup(ctx context.Context, opts ...WorkstationSetupOption) (*WorkstationSetupPlan, error)

type WorkstationSetupResult added in v1.14.0

type WorkstationSetupResult struct {
	Plan    *WorkstationSetupPlan   `json:"plan,omitempty"`
	Applied *WorkstationApplyResult `json:"applied,omitempty"`
}

func SetupWorkstation added in v1.14.0

func SetupWorkstation(ctx context.Context, opts ...WorkstationSetupOption) (*WorkstationSetupResult, error)

Jump to

Keyboard shortcuts

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