backend

package
v0.17.2 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2024 License: BSD-2-Clause Imports: 21 Imported by: 0

Documentation

Overview

Package backend provides local and remote storage for restic repositories. All backends need to implement the Backend interface. There is a MemBackend, which stores all data in a map internally and can be used for testing.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoRepository = fmt.Errorf("repository does not exist")

Functions

func AsBackend added in v0.17.0

func AsBackend[B Backend](b Backend) B

func ReadAt added in v0.14.0

func ReadAt(ctx context.Context, be Backend, h Handle, offset int64, p []byte) (n int, err error)

ReadAt reads from the backend handle h at the given position.

func ReaderAt added in v0.14.0

func ReaderAt(ctx context.Context, be Backend, h Handle) io.ReaderAt

ReaderAt returns an io.ReaderAt for a file in the backend. The returned reader should not escape the caller function to avoid unexpected interactions with the embedded context

func SplitShellStrings added in v0.9.0

func SplitShellStrings(data string) (strs []string, err error)

SplitShellStrings returns the list of shell strings from a shell command string.

func Transport

func Transport(opts TransportOptions) (http.RoundTripper, error)

Transport returns a new http.RoundTripper with default settings applied. If a custom rootCertFilename is non-empty, it must point to a valid PEM file, otherwise the function will return an error.

Types

type ApplyEnvironmenter added in v0.17.0

type ApplyEnvironmenter interface {
	ApplyEnvironment(prefix string)
}

ApplyEnvironmenter fills in a backend configuration from the environment

type Backend added in v0.17.0

type Backend interface {
	// Connections returns the maximum number of concurrent backend operations.
	Connections() uint

	// Hasher may return a hash function for calculating a content hash for the backend
	Hasher() hash.Hash

	// HasAtomicReplace returns whether Save() can atomically replace files
	HasAtomicReplace() bool

	// Remove removes a File described by h.
	Remove(ctx context.Context, h Handle) error

	// Close the backend
	Close() error

	// Save stores the data from rd under the given handle.
	Save(ctx context.Context, h Handle, rd RewindReader) error

	// Load runs fn with a reader that yields the contents of the file at h at the
	// given offset. If length is larger than zero, only a portion of the file
	// is read. If the length is larger than zero and the file is too short to return
	// the requested length bytes, then an error MUST be returned that is recognized
	// by IsPermanentError().
	//
	// The function fn may be called multiple times during the same Load invocation
	// and therefore must be idempotent.
	//
	// Implementations are encouraged to use util.DefaultLoad
	Load(ctx context.Context, h Handle, length int, offset int64, fn func(rd io.Reader) error) error

	// Stat returns information about the File identified by h.
	Stat(ctx context.Context, h Handle) (FileInfo, error)

	// List runs fn for each file in the backend which has the type t. When an
	// error occurs (or fn returns an error), List stops and returns it.
	//
	// The function fn is called exactly once for each file during successful
	// execution and at most once in case of an error.
	//
	// The function fn is called in the same Goroutine that List() is called
	// from.
	List(ctx context.Context, t FileType, fn func(FileInfo) error) error

	// IsNotExist returns true if the error was caused by a non-existing file
	// in the backend.
	//
	// The argument may be a wrapped error. The implementation is responsible
	// for unwrapping it.
	IsNotExist(err error) bool

	// IsPermanentError returns true if the error can very likely not be resolved
	// by retrying the operation. Backends should return true if the file is missing,
	// the requested range does not (completely) exist in the file or the user is
	// not authorized to perform the requested operation.
	IsPermanentError(err error) bool

	// Delete removes all data in the backend.
	Delete(ctx context.Context) error
}

Backend is used to store and access data.

Backend operations that return an error will be retried when a Backend is wrapped in a RetryBackend. To prevent that from happening, the operations should return a github.com/cenkalti/backoff/v4.PermanentError. Errors from the context package need not be wrapped, as context cancellation is checked separately by the retrying logic.

type ByteReader added in v0.17.0

type ByteReader struct {
	*bytes.Reader
	Len int64
	// contains filtered or unexported fields
}

ByteReader implements a RewindReader for a byte slice.

func NewByteReader added in v0.17.0

func NewByteReader(buf []byte, hasher hash.Hash) *ByteReader

NewByteReader prepares a ByteReader that can then be used to read buf.

func (*ByteReader) Hash added in v0.17.0

func (b *ByteReader) Hash() []byte

Hash return a hash of the data if requested by the backed.

func (*ByteReader) Length added in v0.17.0

func (b *ByteReader) Length() int64

Length returns the number of bytes read from the reader after Rewind is called.

func (*ByteReader) Rewind added in v0.17.0

func (b *ByteReader) Rewind() error

Rewind restarts the reader from the beginning of the data.

type FileInfo added in v0.17.0

type FileInfo struct {
	Size int64
	Name string
}

FileInfo is contains information about a file in the backend.

type FileReader added in v0.17.0

type FileReader struct {
	io.ReadSeeker
	Len int64
	// contains filtered or unexported fields
}

FileReader implements a RewindReader for an open file.

func NewFileReader added in v0.17.0

func NewFileReader(f io.ReadSeeker, hash []byte) (*FileReader, error)

NewFileReader wraps f in a *FileReader.

func (*FileReader) Hash added in v0.17.0

func (f *FileReader) Hash() []byte

Hash return a hash of the data if requested by the backed.

func (*FileReader) Length added in v0.17.0

func (f *FileReader) Length() int64

Length returns the length of the file.

func (*FileReader) Rewind added in v0.17.0

func (f *FileReader) Rewind() error

Rewind seeks to the beginning of the file.

type FileType added in v0.17.0

type FileType uint8

FileType is the type of a file in the backend.

const (
	PackFile FileType = 1 + iota
	KeyFile
	LockFile
	SnapshotFile
	IndexFile
	ConfigFile
)

These are the different data types a backend can store.

func (FileType) String added in v0.17.0

func (t FileType) String() string

type FreezeBackend added in v0.17.0

type FreezeBackend interface {
	Backend
	// Freeze blocks all backend operations except those on lock files
	Freeze()
	// Unfreeze allows all backend operations to continue
	Unfreeze()
}

type Handle added in v0.17.0

type Handle struct {
	Type       FileType
	IsMetadata bool
	Name       string
}

Handle is used to store and access data in a backend.

func (Handle) String added in v0.17.0

func (h Handle) String() string

func (Handle) Valid added in v0.17.0

func (h Handle) Valid() error

Valid returns an error if h is not valid.

type RewindReader added in v0.17.0

type RewindReader interface {
	io.Reader

	// Rewind rewinds the reader so the same data can be read again from the
	// start.
	Rewind() error

	// Length returns the number of bytes that can be read from the Reader
	// after calling Rewind.
	Length() int64

	// Hash return a hash of the data if requested by the backed.
	Hash() []byte
}

RewindReader allows resetting the Reader to the beginning of the data.

type TransportOptions added in v0.8.2

type TransportOptions struct {
	// contains filenames of PEM encoded root certificates to trust
	RootCertFilenames []string

	// contains the name of a file containing the TLS client certificate and private key in PEM format
	TLSClientCertKeyFilename string

	// Skip TLS certificate verification
	InsecureTLS bool

	// Specify Custom User-Agent for the http Client
	HTTPUserAgent string

	// Timeout after which to retry stuck requests
	StuckRequestTimeout time.Duration
}

TransportOptions collects various options which can be set for an HTTP based transport.

type Unwrapper added in v0.17.0

type Unwrapper interface {
	// Unwrap returns the underlying backend or nil if there is none.
	Unwrap() Backend
}

Directories

Path Synopsis
Package gs provides a restic backend for Google Cloud Storage.
Package gs provides a restic backend for Google Cloud Storage.
Package local implements repository storage in a local directory.
Package local implements repository storage in a local directory.
Package location implements parsing the restic repository location from a string.
Package location implements parsing the restic repository location from a string.
Package sema implements semaphores.
Package sema implements semaphores.
Package sftp implements repository storage in a directory on a remote server via the sftp protocol.
Package sftp implements repository storage in a directory on a remote server via the sftp protocol.
Package test contains a test suite with benchmarks for restic backends.
Package test contains a test suite with benchmarks for restic backends.

Jump to

Keyboard shortcuts

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