restic: github.com/howeyc/restic Index | Files | Directories

package restic

import "github.com/howeyc/restic"

Package restic is the top level package for the restic backup program, please see https://github.com/restic/restic for more information.

This package exposes the main components needed to create and restore a backup as well as handling things like a local cache of objects.

Index

Package Files

archiver.go cache.go doc.go lock.go lock_unix.go node.go node_linux.go node_unix.go progress.go restorer.go snapshot.go tree.go walk.go

Constants

const AT_SYMLINK_NOFOLLOW = 0x100

Variables

var (
    ErrNodeNotFound      = errors.New("named node not found")
    ErrNodeAlreadyInTree = errors.New("node already present")
)

func FindSnapshot Uses

func FindSnapshot(repo *repository.Repository, s string) (backend.ID, error)

FindSnapshot takes a string and tries to find a snapshot whose ID matches the string as closely as possible.

func IsAlreadyLocked Uses

func IsAlreadyLocked(err error) bool

IsAlreadyLocked returns true iff err is an instance of ErrAlreadyLocked.

func RemoveAllLocks Uses

func RemoveAllLocks(repo *repository.Repository) error

RemoveAllLocks removes all locks forcefully.

func RemoveStaleLocks Uses

func RemoveStaleLocks(repo *repository.Repository) error

RemoveStaleLocks deletes all locks detected as stale from the repository.

func WalkTree Uses

func WalkTree(repo TreeLoader, id backend.ID, done chan struct{}, jobCh chan<- WalkTreeJob)

WalkTree walks the tree specified by id recursively and sends a job for each file and directory it finds. When the channel done is closed, processing stops.

type Archiver Uses

type Archiver struct {
    Error        func(dir string, fi os.FileInfo, err error) error
    SelectFilter pipe.SelectFunc
    Excludes     []string
    // contains filtered or unexported fields
}

Archiver is used to backup a set of directories.

func NewArchiver Uses

func NewArchiver(repo *repository.Repository) *Archiver

NewArchiver returns a new archiver.

func (*Archiver) Save Uses

func (arch *Archiver) Save(t pack.BlobType, id backend.ID, length uint, rd io.Reader) error

Save stores a blob read from rd in the repository.

func (*Archiver) SaveFile Uses

func (arch *Archiver) SaveFile(p *Progress, node *Node) error

SaveFile stores the content of the file on the backend as a Blob by calling Save for each chunk.

func (*Archiver) SaveTreeJSON Uses

func (arch *Archiver) SaveTreeJSON(item interface{}) (backend.ID, error)

SaveTreeJSON stores a tree in the repository.

func (*Archiver) Snapshot Uses

func (arch *Archiver) Snapshot(p *Progress, paths []string, parentID *backend.ID) (*Snapshot, backend.ID, error)

Snapshot creates a snapshot of the given paths. If parentID is set, this is used to compare the files to the ones archived at the time this snapshot was taken.

type Cache Uses

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

Cache is used to locally cache items from a repository.

func NewCache Uses

func NewCache(repo *repository.Repository, cacheDir string) (*Cache, error)

NewCache returns a new cache at cacheDir. If it is the empty string, the default cache location is chosen.

func (*Cache) Clear Uses

func (c *Cache) Clear(repo *repository.Repository) error

Clear removes information from the cache that isn't present in the repository any more.

func (*Cache) Has Uses

func (c *Cache) Has(t backend.Type, subtype string, id backend.ID) (bool, error)

Has checks if the local cache has the id.

func (*Cache) Load Uses

func (c *Cache) Load(t backend.Type, subtype string, id backend.ID) (io.ReadCloser, error)

Load returns information from the cache. The returned io.ReadCloser must be closed by the caller.

func (*Cache) Store Uses

func (c *Cache) Store(t backend.Type, subtype string, id backend.ID) (io.WriteCloser, error)

Store returns an io.WriteCloser that is used to save new information to the cache. The returned io.WriteCloser must be closed by the caller after all data has been written.

type ErrAlreadyLocked Uses

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

ErrAlreadyLocked is returned when NewLock or NewExclusiveLock are unable to acquire the desired lock.

func (ErrAlreadyLocked) Error Uses

func (e ErrAlreadyLocked) Error() string

type Lock Uses

type Lock struct {
    Time      time.Time `json:"time"`
    Exclusive bool      `json:"exclusive"`
    Hostname  string    `json:"hostname"`
    Username  string    `json:"username"`
    PID       int       `json:"pid"`
    UID       uint32    `json:"uid,omitempty"`
    GID       uint32    `json:"gid,omitempty"`
    // contains filtered or unexported fields
}

Lock represents a process locking the repository for an operation.

There are two types of locks: exclusive and non-exclusive. There may be many different non-exclusive locks, but at most one exclusive lock, which can only be acquired while no non-exclusive lock is held.

A lock must be refreshed regularly to not be considered stale, this must be triggered by regularly calling Refresh.

func LoadLock Uses

func LoadLock(repo *repository.Repository, id backend.ID) (*Lock, error)

LoadLock loads and unserializes a lock from a repository.

func NewExclusiveLock Uses

func NewExclusiveLock(repo *repository.Repository) (*Lock, error)

NewExclusiveLock returns a new, exclusive lock for the repository. If another lock (normal and exclusive) is already held by another process, ErrAlreadyLocked is returned.

func NewLock Uses

func NewLock(repo *repository.Repository) (*Lock, error)

NewLock returns a new, non-exclusive lock for the repository. If an exclusive lock is already held by another process, ErrAlreadyLocked is returned.

func (*Lock) Refresh Uses

func (l *Lock) Refresh() error

Refresh refreshes the lock by creating a new file in the backend with a new timestamp. Afterwards the old lock is removed.

func (*Lock) Stale Uses

func (l *Lock) Stale() bool

Stale returns true if the lock is stale. A lock is stale if the timestamp is older than 30 minutes or if it was created on the current machine and the process isn't alive any more.

func (Lock) String Uses

func (l Lock) String() string

func (*Lock) Unlock Uses

func (l *Lock) Unlock() error

Unlock removes the lock from the repository.

type Node Uses

type Node struct {
    Name       string       `json:"name"`
    Type       string       `json:"type"`
    Mode       os.FileMode  `json:"mode,omitempty"`
    ModTime    time.Time    `json:"mtime,omitempty"`
    AccessTime time.Time    `json:"atime,omitempty"`
    ChangeTime time.Time    `json:"ctime,omitempty"`
    UID        uint32       `json:"uid"`
    GID        uint32       `json:"gid"`
    User       string       `json:"user,omitempty"`
    Group      string       `json:"group,omitempty"`
    Inode      uint64       `json:"inode,omitempty"`
    Size       uint64       `json:"size,omitempty"`
    Links      uint64       `json:"links,omitempty"`
    LinkTarget string       `json:"linktarget,omitempty"`
    Device     uint64       `json:"device,omitempty"`
    Content    []backend.ID `json:"content"`
    Subtree    *backend.ID  `json:"subtree,omitempty"`

    Error string `json:"error,omitempty"`
    // contains filtered or unexported fields
}

Node is a file, directory or other item in a backup.

func NodeFromFileInfo Uses

func NodeFromFileInfo(path string, fi os.FileInfo) (*Node, error)

NodeFromFileInfo returns a new node from the given path and FileInfo.

func (*Node) CreateAt Uses

func (node *Node) CreateAt(path string, repo *repository.Repository) error

CreateAt creates the node at the given path and restores all the meta data.

func (Node) Equals Uses

func (node Node) Equals(other Node) bool

func (Node) MarshalJSON Uses

func (node Node) MarshalJSON() ([]byte, error)

func (*Node) OpenForReading Uses

func (node *Node) OpenForReading() (*os.File, error)

func (Node) RestoreTimestamps Uses

func (node Node) RestoreTimestamps(path string) error

func (Node) String Uses

func (node Node) String() string

func (Node) Tree Uses

func (node Node) Tree() *Tree

func (*Node) UnmarshalJSON Uses

func (node *Node) UnmarshalJSON(data []byte) error

type Progress Uses

type Progress struct {
    OnStart  func()
    OnUpdate ProgressFunc
    OnDone   ProgressFunc
    // contains filtered or unexported fields
}

func NewProgress Uses

func NewProgress(d time.Duration) *Progress

NewProgress returns a new progress reporter. When Start() is called, the function OnStart is executed once. Afterwards the function OnUpdate is called when new data arrives or at least every d interval. The function OnDone is called when Done() is called. Both functions are called synchronously and can use shared state.

func (*Progress) Done Uses

func (p *Progress) Done()

Done closes the progress report.

func (*Progress) Report Uses

func (p *Progress) Report(s Stat)

Report adds the statistics from s to the current state and tries to report the accumulated statistics via the feedback channel.

func (*Progress) Reset Uses

func (p *Progress) Reset()

Reset resets all statistic counters to zero.

func (*Progress) Start Uses

func (p *Progress) Start()

Start resets and runs the progress reporter.

type ProgressFunc Uses

type ProgressFunc func(s Stat, runtime time.Duration, ticker bool)

type Restorer Uses

type Restorer struct {
    Error        func(dir string, node *Node, err error) error
    SelectFilter func(item string, dstpath string, node *Node) bool
    // contains filtered or unexported fields
}

Restorer is used to restore a snapshot to a directory.

func NewRestorer Uses

func NewRestorer(repo *repository.Repository, id backend.ID) (*Restorer, error)

NewRestorer creates a restorer preloaded with the content from the snapshot id.

func (*Restorer) RestoreTo Uses

func (res *Restorer) RestoreTo(dir string) error

RestoreTo creates the directories and files in the snapshot below dir. Before an item is created, res.Filter is called.

func (*Restorer) Snapshot Uses

func (res *Restorer) Snapshot() *Snapshot

Snapshot returns the snapshot this restorer is configured to use.

type Snapshot Uses

type Snapshot struct {
    Time     time.Time   `json:"time"`
    Parent   *backend.ID `json:"parent,omitempty"`
    Tree     *backend.ID `json:"tree"`
    Paths    []string    `json:"paths"`
    Hostname string      `json:"hostname,omitempty"`
    Username string      `json:"username,omitempty"`
    UID      uint32      `json:"uid,omitempty"`
    GID      uint32      `json:"gid,omitempty"`
    Excludes []string    `json:"excludes,omitempty"`
    // contains filtered or unexported fields
}

func LoadSnapshot Uses

func LoadSnapshot(repo *repository.Repository, id backend.ID) (*Snapshot, error)

func NewSnapshot Uses

func NewSnapshot(paths []string) (*Snapshot, error)

func (Snapshot) ID Uses

func (sn Snapshot) ID() *backend.ID

func (Snapshot) String Uses

func (sn Snapshot) String() string

type Stat Uses

type Stat struct {
    Files  uint64
    Dirs   uint64
    Bytes  uint64
    Trees  uint64
    Blobs  uint64
    Errors uint64
}

func Scan Uses

func Scan(dirs []string, filter pipe.SelectFunc, p *Progress) (Stat, error)

Scan traverses the dirs to collect Stat information while emitting progress information with p.

func (*Stat) Add Uses

func (s *Stat) Add(other Stat)

Add accumulates other into s.

func (Stat) String Uses

func (s Stat) String() string

type Tree Uses

type Tree struct {
    Nodes []*Node `json:"nodes"`
}

func LoadTree Uses

func LoadTree(repo TreeLoader, id backend.ID) (*Tree, error)

func NewTree Uses

func NewTree() *Tree

func (Tree) Equals Uses

func (t Tree) Equals(other *Tree) bool

Equals returns true if t and other have exactly the same nodes.

func (Tree) Find Uses

func (t Tree) Find(name string) (*Node, error)

func (*Tree) Insert Uses

func (t *Tree) Insert(node *Node) error

func (Tree) String Uses

func (t Tree) String() string

func (Tree) Subtrees Uses

func (t Tree) Subtrees() (trees backend.IDs)

Subtrees returns a slice of all subtree IDs of the tree.

type TreeLoader Uses

type TreeLoader interface {
    LoadJSONPack(pack.BlobType, backend.ID, interface{}) error
}

type TreeWalker Uses

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

TreeWalker traverses a tree in the repository depth-first and sends a job for each item (file or dir) that it encounters.

func NewTreeWalker Uses

func NewTreeWalker(ch chan<- loadTreeJob, out chan<- WalkTreeJob) *TreeWalker

NewTreeWalker uses ch to load trees from the repository and sends jobs to out.

func (*TreeWalker) Walk Uses

func (tw *TreeWalker) Walk(path string, id backend.ID, done chan struct{})

Walk starts walking the tree given by id. When the channel done is closed, processing stops.

type WalkTreeJob Uses

type WalkTreeJob struct {
    Path  string
    Error error

    Node *Node
    Tree *Tree
}

WalkTreeJob is a job sent from the tree walker.

Directories

PathSynopsis
backendPackage backend provides local and remote storage for restic repositories.
backend/localPackage local implements repository storage in a local directory.
backend/s3
backend/sftpPackage sftp implements repository storage in a directory on a remote server via the sftp protocol.
checker
cryptoPackage crypto provides all cryptographic operations needed in restic.
debugPackage debug provides an infrastructure for logging debug information and breakpoints.
filterPackage filter implements filters for files similar to filepath.Glob, but in contrast to filepath.Glob a pattern may specify directories.
fuse
packPackage pack provides functions for combining and parsing pack files.
pipePackage pipe implements walking a directory in a deterministic order.
repositoryPackage repository implements a restic repository on top of a backend.
testPackage test_helper provides helper functions for writing tests for restic.

Package restic imports 24 packages (graph). Updated 2016-07-15. Refresh now. Tools for package owners. This is an inactive package (no imports and no commits in at least two years).