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 ¶
- Variables
- func AsBackend[B Backend](b Backend) B
- func IsErrDot(err error) bool
- func LoadAll(ctx context.Context, buf []byte, be Backend, h Handle) ([]byte, error)
- func ReadAt(ctx context.Context, be Backend, h Handle, offset int64, p []byte) (n int, err error)
- func ReaderAt(ctx context.Context, be Backend, h Handle) io.ReaderAt
- func SplitShellStrings(data string) (strs []string, err error)
- func StartForeground(cmd *exec.Cmd) (bg func() error, err error)
- func Transport(opts TransportOptions) (http.RoundTripper, error)
- type ApplyEnvironmenter
- type Backend
- type ByteReader
- type FileInfo
- type FileReader
- type FileType
- type FreezeBackend
- type Handle
- type LimitedReadCloser
- type Modes
- type RewindReader
- type TransportOptions
- type Unwrapper
Constants ¶
This section is empty.
Variables ¶
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 LoadAll ¶
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 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 ¶
SplitShellStrings returns the list of shell strings from a shell command string.
func StartForeground ¶
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
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 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.
These are the different data types a backend can store.
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 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 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.
Source Files ¶
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. |