restorer

package
v0.0.0-...-0265167 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2024 License: BSD-2-Clause Imports: 17 Imported by: 0

Documentation

Overview

Package restorer contains code to restore data from a repository.

The Restorer tries to keep the number of backend requests minimal. It does this by downloading all required blobs of a pack file with a single backend request and avoiding repeated downloads of the same pack. In addition, several pack files are fetched concurrently.

Here is high-level pseudo-code of how the Restorer attempts to achieve these goals:

while there are packs to process
  choose a pack to process                      [1]
  retrieve the pack from the backend            [2]
  write pack blobs to the files that need them  [3]

Retrieval of repository packs (step [2]) and writing target files (step [3]) are performed concurrently on multiple goroutines.

Implementation does not guarantee order in which blobs are written to the target files and, for example, the last blob of a file can be written to the file before any of the preceding file blobs. It is therefore possible to have gaps in the data written to the target files if restore fails or interrupted by the user.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HardlinkIndex

type HardlinkIndex[T any] struct {
	Index map[HardlinkKey]T
	// contains filtered or unexported fields
}

HardlinkIndex contains a list of inodes, devices these inodes are one, and associated file names.

func NewHardlinkIndex

func NewHardlinkIndex[T any]() *HardlinkIndex[T]

NewHardlinkIndex create a new index for hard links

func (*HardlinkIndex[T]) Add

func (idx *HardlinkIndex[T]) Add(inode uint64, device uint64, value T)

Add adds a link to the index.

func (*HardlinkIndex[T]) Has

func (idx *HardlinkIndex[T]) Has(inode uint64, device uint64) bool

Has checks whether the link already exist in the index.

func (*HardlinkIndex[T]) Remove

func (idx *HardlinkIndex[T]) Remove(inode uint64, device uint64)

Remove removes a link from the index.

func (*HardlinkIndex[T]) Value

func (idx *HardlinkIndex[T]) Value(inode uint64, device uint64) T

Value obtains the filename from the index.

type HardlinkKey

type HardlinkKey struct {
	Inode, Device uint64
}

HardlinkKey is a composed key for finding inodes on a specific device.

type Options

type Options struct {
	DryRun    bool
	Sparse    bool
	Progress  *restoreui.Progress
	Overwrite OverwriteBehavior
	Delete    bool
}

type OverwriteBehavior

type OverwriteBehavior int
const (
	OverwriteAlways OverwriteBehavior = iota
	// OverwriteIfChanged is like OverwriteAlways except that it skips restoring the content
	// of files with matching size&mtime. Metadata is always restored.
	OverwriteIfChanged
	OverwriteIfNewer
	OverwriteNever
	OverwriteInvalid
)

Constants for different overwrite behavior

func (*OverwriteBehavior) Set

func (c *OverwriteBehavior) Set(s string) error

Set implements the method needed for pflag command flag parsing.

func (*OverwriteBehavior) String

func (c *OverwriteBehavior) String() string

func (*OverwriteBehavior) Type

func (c *OverwriteBehavior) Type() string

type Restorer

type Restorer struct {
	Error func(location string, err error) error
	Warn  func(message string)
	// SelectFilter determines whether the item is selectedForRestore or whether a childMayBeSelected.
	// selectedForRestore must not depend on isDir as `removeUnexpectedFiles` always passes false to isDir.
	SelectFilter func(item string, isDir bool) (selectedForRestore bool, childMayBeSelected bool)
	// contains filtered or unexported fields
}

Restorer is used to restore a snapshot to a directory.

func NewRestorer

func NewRestorer(repo restic.Repository, sn *restic.Snapshot, opts Options) *Restorer

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

func (*Restorer) RestoreTo

func (res *Restorer) RestoreTo(ctx context.Context, dst string) error

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

func (*Restorer) Snapshot

func (res *Restorer) Snapshot() *restic.Snapshot

Snapshot returns the snapshot this restorer is configured to use.

func (*Restorer) VerifyFiles

func (res *Restorer) VerifyFiles(ctx context.Context, dst string) (int, error)

VerifyFiles checks whether all regular files in the snapshot res.sn have been successfully written to dst. It stops when it encounters an error. It returns that error and the number of files it has successfully verified.

Jump to

Keyboard shortcuts

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