backend

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2023 License: BSD-2-Clause Imports: 22 Imported by: 1

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 DefaultModes = Modes{Dir: 0700, File: 0600}

DefaultModes defines the default permissions to apply to new repository files and directories stored on file-based backends.

Functions

func AsBackend added in v0.1.2

func AsBackend[B Backend](b Backend) B

func IsErrDot

func IsErrDot(err error) bool

func LoadAll

func LoadAll(ctx context.Context, buf []byte, be Backend, h Handle) ([]byte, error)

LoadAll reads all data stored in the backend for the handle into the given buffer, which is truncated. If the buffer is not large enough or nil, a new one is allocated.

func ReadAt

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

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

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

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

func StartForeground

func StartForeground(cmd *exec.Cmd) (bg func() error, err error)

StartForeground runs cmd in the foreground, by temporarily switching to the new process group created for cmd. The returned function `bg` switches back to the previous process group.

The command's environment has all RESTIC_* variables removed.

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

type ApplyEnvironmenter interface {
	ApplyEnvironment(prefix string)
}

ApplyEnvironmenter fills in a backend configuration from the environment

type Backend added in v0.1.2

type Backend interface {
	// Location returns a string that describes the type and location of the
	// repository.
	Location() string

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

	// 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.1.2

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

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

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

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

func (*ByteReader) Length added in v0.1.2

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

func (b *ByteReader) Rewind() error

Rewind restarts the reader from the beginning of the data.

type FileInfo added in v0.1.2

type FileInfo struct {
	Size int64
	Name string
}

FileInfo is contains information about a file in the backend.

type FileReader added in v0.1.2

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

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

NewFileReader wraps f in a *FileReader.

func (*FileReader) Hash added in v0.1.2

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

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

func (*FileReader) Length added in v0.1.2

func (f *FileReader) Length() int64

Length returns the length of the file.

func (*FileReader) Rewind added in v0.1.2

func (f *FileReader) Rewind() error

Rewind seeks to the beginning of the file.

type FileType added in v0.1.2

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

func (t FileType) String() string

type FreezeBackend added in v0.1.2

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

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

func (h Handle) String() string

func (Handle) Valid added in v0.1.2

func (h Handle) Valid() error

Valid returns an error if h is not valid.

type LimitedReadCloser

type LimitedReadCloser struct {
	io.Closer
	io.LimitedReader
}

LimitedReadCloser wraps io.LimitedReader and exposes the Close() method.

func LimitReadCloser

func LimitReadCloser(r io.ReadCloser, n int64) *LimitedReadCloser

LimitReadCloser returns a new reader wraps r in an io.LimitedReader, but also exposes the Close() method.

type Modes

type Modes struct {
	Dir  os.FileMode
	File os.FileMode
}

func DeriveModesFromFileInfo

func DeriveModesFromFileInfo(fi os.FileInfo, err error) Modes

DeriveModesFromFileInfo will, given the mode of a regular file, compute the mode we should use for new files and directories. If the passed error is non-nil DefaultModes are returned.

type RewindReader added in v0.1.2

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

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
}

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

type Unwrapper added in v0.1.2

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