Documentation
¶
Overview ¶
Package restic implements the providers.BackupProvider interface for Restic repositories.
Index ¶
- Constants
- type Provider
- func (p *Provider) GetSnapshotMetadata(ctx context.Context, source contract.Source) (*providers.SnapshotMetadata, error)
- func (p *Provider) ListSnapshots(ctx context.Context, source contract.Source) ([]providers.Snapshot, error)
- func (p *Provider) Name() string
- func (p *Provider) RestoreArtifact(ctx context.Context, source contract.Source, destination string) (string, error)
- func (p *Provider) Validate(ctx context.Context, source contract.Source) error
- type ResticCommand
Constants ¶
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) 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:
- Runs `restic restore <snapshot>:<path> --target <destination>`
- Walks the destination to locate the actual artifact
- Rejects the result if zero or more than one file matches
- Rejects path traversal (artifact must be under destination)
- Verifies the artifact is a regular file
- Returns the absolute path
type ResticCommand ¶
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:
- 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.
- 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.