uback

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2024 License: Unlicense Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SnapshotRe         = `\d{8}T\d{6}\.\d{3}`  // Regexp matching a snapshot name
	SnapshotTimeFormat = "20060102T150405.000" // Time format of a snapshot, for time.Parse / time.Format
)

Functions

func ApplyRetentionPolicies

func ApplyRetentionPolicies(policies []RetentionPolicy, subjects []RetentionPolicySubject) (map[string]struct{}, error)

Apply retention policies to a set of subjects, returning a set of retained subject names

func BuildCommand

func BuildCommand(command []string, additionalArgs ...string) *exec.Cmd

func CloseProxy added in v0.5.0

func CloseProxy(session *yamux.Session, rpcClient *rpc.Client) error

func CompareBackups

func CompareBackups(a, b Backup) int

Compare backups by the date of their snapshot

func CompareSnapshots

func CompareSnapshots(a, b Snapshot) int

Compare snapshots by date

func CopyFile

func CopyFile(dst, src string) error

This should really be in the standard library...

func LoadPrivateKey

func LoadPrivateKey(keyFile, key string) (age.Identity, error)

Load a private key either from a file (if keyFile argument is provided), or from its content (key argument)

func LoadPublicKey

func LoadPublicKey(keyFile, key string) (age.Recipient, error)

Load a public key either from a file (if keyFile argument is provided), or from its content (key argument) If the file or the content represents a private key, derive the public key from it

func MakeIndex

func MakeIndex(backups []Backup) map[string]Backup

Index a list of backups by the name of the backup snapshot

func OpenProxy added in v0.5.0

func OpenProxy(logger *logrus.Entry, command []string) (*yamux.Session, *rpc.Client, *yamux.Stream, error)

func ParseInterval

func ParseInterval(intv string) (int, error)

Parse an interval. Can be expressed in hours, days, weeks, months or years. Return the time interval in seconds.

func PruneBackups

func PruneBackups(dst Destination, backups []Backup, policies []RetentionPolicy) error

Prune backups from a destinations according to a retention policy

func PruneSnapshots

func PruneSnapshots(src Source, snapshots []Snapshot, policies []RetentionPolicy, state map[string]string) error

Prune snapshots from a source accoruding to a retention policy

func ReadPresets

func ReadPresets(presetsDir string) (map[string][]KeyValuePair, error)

Load presets from a directory

func RunCommand

func RunCommand(log *logrus.Entry, cmd *exec.Cmd) error

func StartCommand

func StartCommand(log *logrus.Entry, cmd *exec.Cmd) error

Types

type Backup

type Backup struct {
	// Snapshot from which this backup was created
	Snapshot

	// If nil, this backup is a full backup.
	// If not nil, this is an incremental backup whose base is BsaeSnapshot
	BaseSnapshot *Snapshot
}

Represents a backup

func GetFullChain

func GetFullChain(backup Backup, index map[string]Backup) ([]Backup, bool)

Create the dependencies chain from a backup:

  • for a full backup, the chain consists only of the backup itself
  • for an incremental backup, the chain consists of the backup itself and its base's chain

func GetPrunedBackups

func GetPrunedBackups(backups []Backup, policies []RetentionPolicy) ([]Backup, error)

Get backups from a destination not retained by a given retention policy

func ParseBackupFilename

func ParseBackupFilename(f string, requireExt bool) (Backup, error)

Reverse of Backup.Filename()

func SortedListBackups

func SortedListBackups(dst Destination) ([]Backup, error)

Sorted from most recent to least recent

func WrapSourceCommand

func WrapSourceCommand(backup Backup, cmd *exec.Cmd, finalize func(err error) error) (Backup, io.ReadCloser, error)

Intended to be used in a source CreateBackup(). If the created backup data is simply given by a command stdout, make a ReadCloser from an exec.Command stdout. When the subprocess is done, call finalize with the result of cmd.Wait() as an argument. The result of finalize will be the error returned by the reader on the next read/close, until the error is nil (then EOF will be returned on next read)

func (Backup) Filename

func (b Backup) Filename() string

Shorthand for Fullname() + ".ubkp"

func (Backup) FullName

func (b Backup) FullName() string

Name of a backup: (Snapshot.Name() + "-full") for a full backup, (Snapshot.Name() + "-from-" + BaseSnapshot.Name()) for an incremental backup

func (Backup) IsFull

func (b Backup) IsFull() bool

Part of RetentionPolicySubject interface

func (Backup) Name

func (b Backup) Name() string

Part of RetentionPolicySubject interface

func (Backup) Time

func (b Backup) Time() (time.Time, error)

Part of RetentionPolicySubject interface

type Destination

type Destination interface {
	// List backups present on the source
	ListBackups() ([]Backup, error)

	// Remove a backup
	RemoveBackup(backup Backup) error

	// Store a backup whose data is `data`
	SendBackup(backup Backup, data io.Reader) error

	// Retrieve the content of a previously stored backup
	ReceiveBackup(backup Backup) (io.ReadCloser, error)
}

A destination is a storage for backups

type KeyValuePair

type KeyValuePair = [2]string

func SplitOptions

func SplitOptions(options string) []KeyValuePair

Split a command line into a list of key-value pairs, separated by a comma

type Options

type Options struct {
	// All normal (non-"@"-prefixed) options
	String map[string]string

	// All noslice (non-"@"-prefixed) options
	// Keys have their "@" prefix stripped
	StrSlice map[string][]string
}

Store parsed and evaluated options

func EvalOptions

func EvalOptions(kvs []KeyValuePair, presets map[string][]KeyValuePair) (*Options, error)

Evaluate raw key-value pairs (evaluate values as a template and substitute presets)

func ProxiedOptions added in v0.5.0

func ProxiedOptions(options *Options) Options

func (*Options) GetBoolean

func (o *Options) GetBoolean(key string, defaults bool) (bool, error)

func (*Options) GetCommand

func (o *Options) GetCommand(key string, defaults []string) []string

Get a command, for @Command options This supports a shorthand, Command="sudo mycommand" (for example) where the simple string will be parsed into a slice following shell syntax

func (*Options) GetRetentionPolicies

func (o *Options) GetRetentionPolicies() ([]RetentionPolicy, error)

Parse retention policies

type ReadWriteCloser added in v0.5.0

type ReadWriteCloser struct {
	io.ReadCloser
	io.WriteCloser
}

func (*ReadWriteCloser) Close added in v0.5.0

func (rwc *ReadWriteCloser) Close() error

type RetentionPolicy

type RetentionPolicy struct {
	Interval int  // Minimum interval between two backups
	Count    int  // Maximum number of retained backups
	FullOnly bool // If true, only retain full backups
}

func ParseRetentionPolicy

func ParseRetentionPolicy(policy string) (RetentionPolicy, error)

type RetentionPolicySubject

type RetentionPolicySubject interface {
	Time() (time.Time, error)
	IsFull() bool
	Name() string
}

Can be a backup or a snapshot

type Snapshot

type Snapshot string

Represents a snapshot. Should be in the YYYYMMDDTHHMMSS.MMM format.

func GetPrunedSnapshots

func GetPrunedSnapshots(snapshots []Snapshot, policies []RetentionPolicy, state map[string]string) ([]Snapshot, error)

Get snapshots from a source not retained by a given retention policy

func SortedListSnapshots

func SortedListSnapshots(src Source) ([]Snapshot, error)

Sorted from most recent to least recent

func (Snapshot) IsFull

func (s Snapshot) IsFull() bool

Part of RetentionPolicySubject interface

func (Snapshot) Name

func (s Snapshot) Name() string

Part of RetentionPolicySubject interface

func (Snapshot) Time

func (s Snapshot) Time() (time.Time, error)

Part of RetentionPolicySubject interface

type Source

type Source interface {
	// Get all snapshots that can be used as a base snapshot for incremental backups
	ListSnapshots() ([]Snapshot, error)

	// Remove a snapshot
	RemoveSnapshot(snapshot Snapshot) error

	// Create a backup from a base snapshot (if supported by the source), or nil for a full snapshot.
	// Returns the name of the created backup, and a reader to the backup data.
	// The returned backup can be full even if baseSnapshot is not nil, but cannot
	// be an incremental backup if baseSnapshot is nil.
	CreateBackup(baseSnapshot *Snapshot) (Backup, io.ReadCloser, error)

	// Restore a backup whose name is `backup` and data is `data` onto the `target` directory.
	// If `backup` is an incremental backup, his base is guaranteed to already have been restored.
	RestoreBackup(target string, backup Backup, data io.Reader) error
}

A source is what we want to backup

Jump to

Keyboard shortcuts

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