backend

package
v0.1.0-doc Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2016 License: BSD-2-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package backend provides local and remote storage for restic repositories.

Index

Constants

View Source
const (
	Data     Type = "data"
	Key           = "key"
	Lock          = "lock"
	Snapshot      = "snapshot"
	Index         = "index"
	Config        = "config"
)
View Source
const IDSize = hashSize

IDSize contains the size of an ID, in bytes.

View Source
const (
	MinPrefixLength = 8
)

Variables

View Source
var (
	ErrNoIDPrefixFound   = errors.New("no ID found")
	ErrMultipleIDMatches = errors.New("multiple IDs with prefix found")
)
View Source
var Modes = struct{ Dir, File os.FileMode }{0700, 0600}

Default modes for file-based backends

View Source
var Paths = struct {
	Data      string
	Snapshots string
	Index     string
	Locks     string
	Keys      string
	Temp      string
	Config    string
}{
	"data",
	"snapshots",
	"index",
	"locks",
	"keys",
	"tmp",
	"config",
}

Default paths for file-based backends (e.g. local)

Functions

func Find

func Find(be Lister, t Type, prefix string) (string, error)

Find loads the list of all blobs of type t and searches for names which start with prefix. If none is found, nil and ErrNoIDPrefixFound is returned. If more than one is found, nil and ErrMultipleIDMatches is returned.

func LimitReadCloser

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

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

func PrefixLength

func PrefixLength(be Lister, t Type) (int, error)

PrefixLength returns the number of bytes required so that all prefixes of all names of type t are unique.

Types

type Backend

type Backend interface {
	// Location returns a string that specifies the location of the repository,
	// like a URL.
	Location() string

	// Create creates a new Blob. The data is available only after Finalize()
	// has been called on the returned Blob.
	Create() (Blob, error)

	// Get returns an io.ReadCloser for the Blob with the given name of type t.
	Get(t Type, name string) (io.ReadCloser, error)

	// GetReader returns an io.ReadCloser for the Blob with the given name of
	// type t at offset and length.
	GetReader(t Type, name string, offset, length uint) (io.ReadCloser, error)

	// Test a boolean value whether a Blob with the name and type exists.
	Test(t Type, name string) (bool, error)

	// Remove removes a Blob with type t and name.
	Remove(t Type, name string) error

	// Close the backend
	Close() error

	Lister
}

A Backend manages data stored somewhere.

type Blob

type Blob interface {
	io.Writer

	// Finalize moves the data blob to the final location for type and name.
	Finalize(t Type, name string) error

	// Size returns the number of bytes written to the backend so far.
	Size() uint
}

type Deleter

type Deleter interface {
	// Delete the complete repository.
	Delete() error
}

type HashAppendReader

type HashAppendReader struct {
	// contains filtered or unexported fields
}

func NewHashAppendReader

func NewHashAppendReader(r io.Reader, h hash.Hash) *HashAppendReader

func (*HashAppendReader) Read

func (h *HashAppendReader) Read(p []byte) (n int, err error)

type HashAppendWriter

type HashAppendWriter struct {
	// contains filtered or unexported fields
}

func NewHashAppendWriter

func NewHashAppendWriter(w io.Writer, h hash.Hash) *HashAppendWriter

func (*HashAppendWriter) Close

func (h *HashAppendWriter) Close() error

func (*HashAppendWriter) Write

func (h *HashAppendWriter) Write(p []byte) (n int, err error)

type HashingReader

type HashingReader struct {
	// contains filtered or unexported fields
}

func NewHashingReader

func NewHashingReader(r io.Reader, h hash.Hash) *HashingReader

func (*HashingReader) Read

func (h *HashingReader) Read(p []byte) (int, error)

func (*HashingReader) Sum

func (h *HashingReader) Sum(d []byte) []byte

type HashingWriter

type HashingWriter struct {
	// contains filtered or unexported fields
}

func NewHashingWriter

func NewHashingWriter(w io.Writer, h hash.Hash) *HashingWriter

func (*HashingWriter) Size

func (h *HashingWriter) Size() int

func (*HashingWriter) Sum

func (h *HashingWriter) Sum(d []byte) []byte

func (*HashingWriter) Write

func (h *HashingWriter) Write(p []byte) (int, error)

type ID

type ID [IDSize]byte

ID references content within a repository.

func Hash

func Hash(data []byte) ID

Hash returns the ID for data.

func IDFromData

func IDFromData(d []byte) ID

func ParseID

func ParseID(s string) (ID, error)

ParseID converts the given string to an ID.

func (ID) Compare

func (id ID) Compare(other ID) int

Compare compares this ID to another one, returning -1, 0, or 1.

func (ID) Equal

func (id ID) Equal(other ID) bool

Equal compares an ID to another other.

func (ID) EqualString

func (id ID) EqualString(other string) (bool, error)

EqualString compares this ID to another one, given as a string.

func (ID) IsNull

func (id ID) IsNull() bool

IsNull returns true iff id only consists of null bytes.

func (ID) MarshalJSON

func (id ID) MarshalJSON() ([]byte, error)

func (*ID) Str

func (id *ID) Str() string

Str returns the shortened string version of id.

func (ID) String

func (id ID) String() string

func (*ID) UnmarshalJSON

func (id *ID) UnmarshalJSON(b []byte) error

type IDs

type IDs []ID

func (IDs) Len

func (ids IDs) Len() int

func (IDs) Less

func (ids IDs) Less(i, j int) bool

func (IDs) Swap

func (ids IDs) Swap(i, j int)

type Lister

type Lister interface {
	// List returns a channel that yields all names of blobs of type t in
	// lexicographic order. A goroutine is started for this. If the channel
	// done is closed, sending stops.
	List(t Type, done <-chan struct{}) <-chan string
}

type Type

type Type string

Type is the type of a Blob.

Directories

Path Synopsis
Package local implements repository storage in a local directory.
Package local implements repository storage in a local directory.
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.

Jump to

Keyboard shortcuts

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