restic

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package restic implements the providers.BackupProvider interface for Restic repositories.

Index

Constants

View Source
const DefaultTimeout = 10 * time.Minute

DefaultTimeout is applied to every restic invocation unless the caller supplies a shorter deadline.

Variables

This section is empty.

Functions

This section is empty.

Types

type Provider

type Provider struct {
	// BinaryPath is the restic executable. Empty means "use $PATH".
	BinaryPath string
}

Provider implements providers.BackupProvider for Restic.

func NewProvider

func NewProvider() *Provider

NewProvider returns a Provider that resolves the restic binary from $PATH.

func (*Provider) GetSnapshotMetadata

func (p *Provider) GetSnapshotMetadata(ctx context.Context, source contract.Source) (*providers.SnapshotMetadata, error)

GetSnapshotMetadata returns size and file-count information for the snapshot referenced by the contract.

If restic is older than 0.17.0, HasSummary is false and TotalSize/FileCount are zero.

func (*Provider) ListSnapshots

func (p *Provider) ListSnapshots(ctx context.Context, source contract.Source) ([]providers.Snapshot, error)

ListSnapshots returns all snapshots in the repository.

func (*Provider) Name

func (p *Provider) Name() string

Name returns "restic".

func (*Provider) RestoreArtifact

func (p *Provider) RestoreArtifact(ctx context.Context, source contract.Source, destination string) (string, error)

RestoreArtifact restores the artifact referenced by the contract into the given destination directory. It returns the absolute path to the restored file.

Behavior:

  1. Runs `restic restore <snapshot>:<path> --target <destination>`
  2. Walks the destination to locate the actual artifact
  3. Rejects the result if zero or more than one file matches
  4. Rejects path traversal (artifact must be under destination)
  5. Verifies the artifact is a regular file
  6. Returns the absolute path

func (*Provider) Validate

func (p *Provider) Validate(ctx context.Context, source contract.Source) error

Validate checks that the repository is reachable and the snapshot referenced by the contract exists.

type ResticCommand

type ResticCommand struct {
	GlobalArgs []string
	Subcommand string
	Args       []string
}

ResticCommand describes a single restic invocation. Restic global flags MUST come before the subcommand:

restic [global flags] <subcommand> [subcommand flags] [args]

So `--no-lock` belongs in GlobalArgs, NOT in Args.

func NewBaseCommand

func NewBaseCommand(noLock bool) ResticCommand

NewBaseCommand builds a restic command with the standard global flags required by RestoreLab.

Restic reads RESTIC_REPOSITORY and RESTIC_PASSWORD_FILE from environment variables. We deliberately do NOT pass --repo or --password-file as flags because:

  1. exec.Command does not expand shell variables, so passing "$RESTIC_REPOSITORY" literally would make restic look for a file or repository with that exact name.
  2. Even if we resolved the values ourselves, they would appear in `ps aux` output, leaking the password file path.

The Provider sets the environment for each child process explicitly in its buildEnv method.

func (ResticCommand) Build

func (c ResticCommand) Build() []string

Build returns the argument slice to pass to exec.Command. The binary name itself is not included.

func (ResticCommand) String

func (c ResticCommand) String() string

String renders the command for logging. Any value that follows --password-file is redacted so secrets never reach the logs. (RestoreLab does not currently pass --password-file, but the redaction is kept for robustness.)

func (ResticCommand) Validate

func (c ResticCommand) Validate() error

Validate ensures the command has a subcommand and no global flags leaked into Args. This is a defensive check.

func (ResticCommand) WithSubcommand

func (c ResticCommand) WithSubcommand(sub string, args ...string) ResticCommand

WithSubcommand returns a copy of c with the given subcommand and args.

Jump to

Keyboard shortcuts

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