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 DefaultLoad(ctx context.Context, h restic.Handle, length int, offset int64, ...) error
- func LoadAll(ctx context.Context, buf []byte, be restic.Backend, h restic.Handle) ([]byte, error)
- 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 DefaultLayout
- func (l *DefaultLayout) Basedir(t restic.FileType) (dirname string, subdirs bool)
- func (l *DefaultLayout) Dirname(h restic.Handle) string
- func (l *DefaultLayout) Filename(h restic.Handle) string
- func (l *DefaultLayout) Name() string
- func (l *DefaultLayout) Paths() (dirs []string)
- func (l *DefaultLayout) String() string
- type ErrorBackend
- type Filesystem
- type Layout
- type LimitedReadCloser
- type LocalFilesystem
- type RESTLayout
- func (l *RESTLayout) Basedir(t restic.FileType) (dirname string, subdirs bool)
- func (l *RESTLayout) Dirname(h restic.Handle) string
- func (l *RESTLayout) Filename(h restic.Handle) string
- func (l *RESTLayout) Name() string
- func (l *RESTLayout) Paths() (dirs []string)
- func (l *RESTLayout) String() string
- type RetryBackend
- func (be *RetryBackend) List(ctx context.Context, t restic.FileType, fn func(restic.FileInfo) error) error
- func (be *RetryBackend) Load(ctx context.Context, h restic.Handle, length int, offset int64, ...) (err error)
- func (be *RetryBackend) Remove(ctx context.Context, h restic.Handle) (err error)
- func (be *RetryBackend) Save(ctx context.Context, h restic.Handle, rd restic.RewindReader) error
- func (be *RetryBackend) Stat(ctx context.Context, h restic.Handle) (fi restic.FileInfo, err error)
- func (be *RetryBackend) Test(ctx context.Context, h restic.Handle) (exists bool, err error)
- type S3LegacyLayout
- func (l *S3LegacyLayout) Basedir(t restic.FileType) (dirname string, subdirs bool)
- func (l *S3LegacyLayout) Dirname(h restic.Handle) string
- func (l *S3LegacyLayout) Filename(h restic.Handle) string
- func (l *S3LegacyLayout) Name() string
- func (l *S3LegacyLayout) Paths() (dirs []string)
- func (l *S3LegacyLayout) String() string
- type Semaphore
- type TransportOptions
Constants ¶
This section is empty.
Variables ¶
var ErrLayoutDetectionFailed = errors.New("auto-detecting the filesystem layout failed")
ErrLayoutDetectionFailed is returned by DetectLayout() when the layout cannot be detected automatically.
var Modes = struct{ Dir, File os.FileMode }{0700, 0600}
Modes holds the default modes for directories and files for file-based backends.
var Paths = struct { Data string Snapshots string Index string Locks string Keys string Temp string Config string }{ "data", "snapshots", "index", "locks", "keys", "tmp", "config", }
Paths contains the default paths for file-based backends (e.g. local).
Functions ¶
func DefaultLoad ¶ added in v0.8.3
func DefaultLoad(ctx context.Context, h restic.Handle, length int, offset int64, openReader func(ctx context.Context, h restic.Handle, length int, offset int64) (io.ReadCloser, error), fn func(rd io.Reader) error) error
DefaultLoad implements Backend.Load using lower-level openReader func
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 SplitShellStrings ¶ added in v0.9.0
SplitShellStrings returns the list of shell strings from a shell command string.
func StartForeground ¶ added in v0.9.0
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.
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 DefaultLayout ¶
DefaultLayout implements the default layout for local and sftp backends, as described in the Design document. The `data` directory has one level of subdirs, two characters each (taken from the first two characters of the file name).
func (*DefaultLayout) Basedir ¶
func (l *DefaultLayout) Basedir(t restic.FileType) (dirname string, subdirs bool)
Basedir returns the base dir name for type t.
func (*DefaultLayout) Dirname ¶
func (l *DefaultLayout) Dirname(h restic.Handle) string
Dirname returns the directory path for a given file type and name.
func (*DefaultLayout) Filename ¶
func (l *DefaultLayout) Filename(h restic.Handle) string
Filename returns a path to a file, including its name.
func (*DefaultLayout) Name ¶
func (l *DefaultLayout) Name() string
Name returns the name for this layout.
func (*DefaultLayout) Paths ¶
func (l *DefaultLayout) Paths() (dirs []string)
Paths returns all directory names needed for a repo.
func (*DefaultLayout) String ¶
func (l *DefaultLayout) String() string
type ErrorBackend ¶ added in v0.8.0
type ErrorBackend struct { FailSave float32 FailSaveRead float32 FailLoad float32 FailStat float32 restic.Backend // contains filtered or unexported fields }
ErrorBackend is used to induce errors into various function calls and test the retry functions.
func NewErrorBackend ¶ added in v0.8.0
func NewErrorBackend(be restic.Backend, seed int64) *ErrorBackend
NewErrorBackend wraps be with a backend that returns errors according to given probabilities.
func (*ErrorBackend) Load ¶ added in v0.8.0
func (be *ErrorBackend) Load(ctx context.Context, h restic.Handle, length int, offset int64, consumer func(rd io.Reader) error) error
Load returns 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 returned. rd must be closed after use. If an error is returned, the ReadCloser must be nil.
func (*ErrorBackend) Save ¶ added in v0.8.0
func (be *ErrorBackend) Save(ctx context.Context, h restic.Handle, rd restic.RewindReader) error
Save stores the data in the backend under the given handle.
type Filesystem ¶
type Filesystem interface { Join(...string) string ReadDir(string) ([]os.FileInfo, error) IsNotExist(error) bool }
Filesystem is the abstraction of a file system used for a backend.
type Layout ¶
type Layout interface { Filename(restic.Handle) string Dirname(restic.Handle) string Basedir(restic.FileType) (dir string, subdirs bool) Paths() []string Name() string }
Layout computes paths for file name storage.
func DetectLayout ¶
func DetectLayout(repo Filesystem, dir string) (Layout, error)
DetectLayout tries to find out which layout is used in a local (or sftp) filesystem at the given path. If repo is nil, an instance of LocalFilesystem is used.
func ParseLayout ¶
func ParseLayout(repo Filesystem, layout, defaultLayout, path string) (l Layout, err error)
ParseLayout parses the config string and returns a Layout. When layout is the empty string, DetectLayout is used. If that fails, defaultLayout is used.
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 LocalFilesystem ¶
type LocalFilesystem struct { }
LocalFilesystem implements Filesystem in a local path.
func (*LocalFilesystem) IsNotExist ¶
func (l *LocalFilesystem) IsNotExist(err error) bool
IsNotExist returns true for errors that are caused by not existing files.
func (*LocalFilesystem) Join ¶
func (l *LocalFilesystem) Join(paths ...string) string
Join combines several path components to one.
type RESTLayout ¶
RESTLayout implements the default layout for the REST protocol.
func (*RESTLayout) Basedir ¶
func (l *RESTLayout) Basedir(t restic.FileType) (dirname string, subdirs bool)
Basedir returns the base dir name for files of type t.
func (*RESTLayout) Dirname ¶
func (l *RESTLayout) Dirname(h restic.Handle) string
Dirname returns the directory path for a given file type and name.
func (*RESTLayout) Filename ¶
func (l *RESTLayout) Filename(h restic.Handle) string
Filename returns a path to a file, including its name.
func (*RESTLayout) Paths ¶
func (l *RESTLayout) Paths() (dirs []string)
Paths returns all directory names
func (*RESTLayout) String ¶
func (l *RESTLayout) String() string
type RetryBackend ¶ added in v0.8.0
RetryBackend retries operations on the backend in case of an error with a backoff.
func NewRetryBackend ¶ added in v0.8.0
func NewRetryBackend(be restic.Backend, maxTries int, report func(string, error, time.Duration)) *RetryBackend
NewRetryBackend wraps be with a backend that retries operations after a backoff. report is called with a description and the error, if one occurred.
func (*RetryBackend) List ¶ added in v0.8.2
func (be *RetryBackend) List(ctx context.Context, t restic.FileType, fn func(restic.FileInfo) error) error
List runs fn for each file in the backend which has the type t. When an error is returned by the underlying backend, the request is retried. When fn returns an error, the operation is aborted and the error is returned to the caller.
func (*RetryBackend) Load ¶ added in v0.8.0
func (be *RetryBackend) Load(ctx context.Context, h restic.Handle, length int, offset int64, consumer func(rd io.Reader) error) (err error)
Load returns 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 returned. rd must be closed after use. If an error is returned, the ReadCloser must be nil.
func (*RetryBackend) Save ¶ added in v0.8.0
func (be *RetryBackend) Save(ctx context.Context, h restic.Handle, rd restic.RewindReader) error
Save stores the data in the backend under the given handle.
type S3LegacyLayout ¶
S3LegacyLayout implements the old layout used for s3 cloud storage backends, as described in the Design document.
func (*S3LegacyLayout) Basedir ¶
func (l *S3LegacyLayout) Basedir(t restic.FileType) (dirname string, subdirs bool)
Basedir returns the base dir name for type t.
func (*S3LegacyLayout) Dirname ¶
func (l *S3LegacyLayout) Dirname(h restic.Handle) string
Dirname returns the directory path for a given file type and name.
func (*S3LegacyLayout) Filename ¶
func (l *S3LegacyLayout) Filename(h restic.Handle) string
Filename returns a path to a file, including its name.
func (*S3LegacyLayout) Name ¶
func (l *S3LegacyLayout) Name() string
Name returns the name for this layout.
func (*S3LegacyLayout) Paths ¶
func (l *S3LegacyLayout) Paths() (dirs []string)
Paths returns all directory names
func (*S3LegacyLayout) String ¶
func (l *S3LegacyLayout) String() string
type Semaphore ¶
type Semaphore struct {
// contains filtered or unexported fields
}
Semaphore limits access to a restricted resource.
func NewSemaphore ¶
NewSemaphore returns a new semaphore with capacity n.
func (*Semaphore) GetToken ¶
func (s *Semaphore) GetToken()
GetToken blocks until a Token is available.
func (*Semaphore) ReleaseTokenOnClose ¶ added in v0.8.0
func (s *Semaphore) ReleaseTokenOnClose(rc io.ReadCloser, cancel context.CancelFunc) io.ReadCloser
ReleaseTokenOnClose wraps an io.ReadCloser to return a token on Close. Before returning the token, cancel, if provided, will be run to free up context resources.
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 }
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 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. |