Documentation
¶
Overview ¶
Package backup is the framework the sync.store resources back objects up with, into stores declared as store#<name> sections.
A store is a tool keeping backups, plakar or a directory of tar archives, behind the Store interface. The framework decides what is backed up, when, and what is kept; a store driver only writes, lists, restores and deletes what it is told to.
One sync update of an object is a run, identified by om's snapshot id, the action session id, whatever the tool: the same id is listed, restored and deployed from on every store type. A run holds named members: one per head the run saved, named by its resource id, and the configuration of the object, named config.
Index ¶
- Constants
- Variables
- func CheckNote(s string) error
- func ComputeStats(ctx context.Context, s Store) (Stats, []ObjectStats)
- func Excluded(rel string, excludes []string) bool
- func HeadExcludes(rid string, excludes []string) []string
- func Keep(s Store) string
- func LiteralPattern(rel string) string
- func ReadMember(ctx context.Context, s Store, run Run, member string) ([]byte, error)
- func SectionName(name string) string
- func SplitPattern(pattern string) (string, bool)
- type ClusterStats
- type Driver
- type Localer
- type Member
- type MemberKind
- type NodeStats
- type NodeStatser
- type ObjectStats
- type PartialError
- type Period
- type PeriodUnit
- type Pruner
- type Retention
- type Run
- type RunFilter
- type Sharer
- type Stats
- type Statser
- type Store
- type Streamer
- type T
- func (t *T) Close() error
- func (t *T) Config() *xconfig.T
- func (t *T) Get(option string) string
- func (t *T) Key(option string) key.T
- func (t *T) Owner() naming.Path
- func (t *T) Reader() string
- func (t *T) Ref() string
- func (t *T) SetConfig(c *xconfig.T)
- func (t *T) SetName(s string)
- func (t *T) SetOwner(p naming.Path)
- func (t *T) SetReader(ns string)
- type Usage
- type Usager
Constants ¶
const ( // MemberDir is a member saved from a directory. MemberDir MemberKind = "dir" // MemberStream is a member saved from a stream. MemberStream MemberKind = "stream" // MemberConfig is the member holding the configuration of the object. MemberConfig = "config" // MemberRefs is the member holding the keys of the sec and cfg the // object references, as an object.RefsDocument. MemberRefs = "refs.json" // SectionPrefix is the prefix of the sections declaring stores. SectionPrefix = "store#" )
Variables ¶
var ( // ErrNotFound is returned when no run matches a filter asking one. ErrNotFound = errors.New("no such run") // ErrAmbiguous is returned when several runs match a filter asking // one, as a too short id prefix. ErrAmbiguous = errors.New("ambiguous run id") )
Functions ¶
func CheckNote ¶
CheckNote refuses a note no store records as written: a comma, which separates the tags a plakar snapshot holds, a line break, or a note longer than noteMax.
func ComputeStats ¶
func ComputeStats(ctx context.Context, s Store) (Stats, []ObjectStats)
ComputeStats is StoreStats, returning too the stats of the objects it summed.
func Excluded ¶
Excluded tells whether the path rel, relative to a head, slash separated, is one an exclude pattern matches: a pattern starting with or holding a slash matches the path from the head, one without matches a name at any depth. Store drivers and the framework share it, so what a run leaves out is what a restore in place leaves alone.
func HeadExcludes ¶
HeadExcludes returns the patterns of excludes applying to the head rid: the ones prefixed with "<rid>:", without the prefix, and the ones with no prefix, which apply to every head.
func LiteralPattern ¶
LiteralPattern returns the pattern matching the path rel from the head, and nothing else: anchored, its wildcards escaped.
func ReadMember ¶
ReadMember returns the content of a member saved as a file: streamed from a store taking streams, or restored into a private temporary directory otherwise, where a member saved from a directory holds a file named after it, as the configuration of an object does.
func SectionName ¶
SectionName returns the section declaring the store named name, with or without its prefix.
func SplitPattern ¶
SplitPattern returns the pattern without its leading and trailing slashes, and whether it matches the path from the head, rather than a name at any depth: a pattern starting with a slash, as "/tmp", or holding one.
Types ¶
type ClusterStats ¶
type ClusterStats struct {
ClusterID string `json:"cluster_id"`
ClusterName string `json:"cluster_name"`
Runs int `json:"runs"`
Incomplete int `json:"incomplete"`
Protected int `json:"protected"`
Objects int `json:"objects"`
LastCreatedAt time.Time `json:"last_created_at,omitzero"`
LogicalBytes int64 `json:"logical_bytes"`
}
ClusterStats are the figures of the runs one cluster wrote.
type Driver ¶
type Driver interface {
Store
SetName(string)
SetConfig(*xconfig.T)
SetOwner(naming.Path)
SetReader(string)
Close() error
}
Driver is a store driver, configured from its store#<name> section.
func NewNodesStore ¶
func NewNodesStore(driver Driver, local string, peers []string, newPeer func(string) (Driver, error), warnf func(string, ...any)) Driver
NewNodesStore returns the store local, the driver of the directory of the node named local, spread over the directories of the peers, each reached by the driver newPeer returns. warnf says the peers whose runs are not listed.
type Localer ¶
type Localer interface {
IsLocal() bool
}
Localer is a store keeping its runs on the node, as a directory. A sec does not declare one: the daemon would read and write it as root where the namespace says.
type Member ¶
type Member struct {
Name string `json:"name"`
Kind MemberKind `json:"kind"`
// Head is the directory a member saved from a directory was
// saved from, which a restore in place writes it back into.
Head string `json:"head,omitempty"`
// LogicalBytes and StoredBytes are the size of what the member
// saved, and what it takes in the store, as the run's.
LogicalBytes int64 `json:"logical_bytes,omitempty"`
StoredBytes int64 `json:"stored_bytes,omitempty"`
}
Member is a part of a run: a head saved from a directory, or a document saved from a stream.
type MemberKind ¶
type MemberKind string
MemberKind says how a member was saved, and so how it is restored.
type NodeStats ¶
type NodeStats struct {
Stats Stats
Objects []ObjectStats
}
NodeStats are the stats of the directory of one node, and the stats of the objects they sum.
type NodeStatser ¶
NodeStatser is a store keeping its runs in a directory of each node, whose stats are of each node, by node name.
type ObjectStats ¶
type ObjectStats struct {
ClusterID string `json:"cluster_id"`
ClusterName string `json:"cluster_name"`
ObjectID string `json:"object_id"`
Path string `json:"path"`
Runs int `json:"runs"`
Incomplete int `json:"incomplete"`
Protected int `json:"protected"`
Nodes []string `json:"nodes"`
FirstCreatedAt time.Time `json:"first_created_at,omitzero"`
LastCreatedAt time.Time `json:"last_created_at,omitzero"`
LogicalBytes int64 `json:"logical_bytes"`
StoredBytes int64 `json:"stored_bytes,omitempty"`
UpdatedAt time.Time `json:"updated_at"`
}
ObjectStats are the figures of the runs of one object, which the node completing or removing a run of it records beside its runs.
func MergeObjectStats ¶
func MergeObjectStats(lists ...[]ObjectStats) []ObjectStats
MergeObjectStats merges the stats of one object recorded in several directories, as the one of each node of a store keeping its runs per node: the runs of an object moved from a node to another are in both.
func NewObjectStats ¶
func NewObjectStats(clusterID, clusterName, objectID, path string, runs []Run) ObjectStats
NewObjectStats counts the runs of one object, the incomplete ones too.
type PartialError ¶
PartialError is the stats of a store read without some of its nodes, by node name, with why.
func (*PartialError) Error ¶
func (t *PartialError) Error() string
func (*PartialError) NodeNames ¶
func (t *PartialError) NodeNames() []string
NodeNames returns the nodes not read, sorted.
type Period ¶
type Period struct {
Unit PeriodUnit
Count int
}
Period keeps the latest run of each of the Count latest periods of Unit holding a run.
type PeriodUnit ¶
type PeriodUnit byte
PeriodUnit is the unit of a period: h, d, w, m or y.
const ( Hour PeriodUnit = 'h' Day PeriodUnit = 'd' Week PeriodUnit = 'w' Month PeriodUnit = 'm' Year PeriodUnit = 'y' )
type Pruner ¶
Pruner is a store deleting runs, the ones the retention om applies drops. A store without it keeps its runs as the backup server decides, and refuses a keep.
type Retention ¶
type Retention struct {
// Last is the number of latest runs kept.
Last int
// Periods are the rules keeping the latest run of each of the
// latest periods of a unit.
Periods []Period
}
Retention is the runs of an object a keep keeps: the latest ones, and the latest one of each of the latest periods.
func ParseRetention ¶
ParseRetention parses a keep: rules separated by spaces, each a number of latest runs, as 10, or a number of periods, as 24h, 7d, 4w, 6m or 1y.
func (Retention) Drop ¶
Drop returns the runs the retention does not keep, oldest first. A run kept by any rule is kept.
The periods are counted among the ones holding a run, as restic, borg and proxmox count them, rather than back from now: an object whose runs stopped for months keeps its last ones instead of losing them all at its next run. They are in UTC, of the time a run started, so runs written by different nodes fall in the same periods.
type Run ¶
type Run struct {
// ID is om's snapshot id: the session id of the action that
// wrote the run, shared by every member.
ID string `json:"id"`
// ClusterID and ClusterName are the cluster of the node that
// wrote the run: a store several clusters write holds objects of
// the same path, and of the same id, as one deployed on a drp
// cluster with its source's id.
ClusterID string `json:"cluster_id"`
ClusterName string `json:"cluster_name"`
// Path is the object the run backs up, as it was named then.
Path string `json:"path"`
// ObjectID is the id of the object, telling apart two objects
// that held the same path, as a clone deployed over a purged
// one.
ObjectID string `json:"object_id"`
// Node is the node that wrote the run.
Node string `json:"node"`
// CreatedAt is when the action writing the run began, which the
// retention periods are evaluated on: the runs one action writes
// into several stores, under one id, carry the same time.
CreatedAt time.Time `json:"created_at"`
// CompletedAt is when the run saved its last member, every
// member saved. A run failed or interrupted has none, and no
// listing or restore selects it.
CompletedAt time.Time `json:"completed_at,omitzero"`
// Members are the members the run saved.
Members []Member `json:"members"`
// Protected keeps the run from the retention: only an explicit
// removal deletes it.
Protected bool `json:"protected,omitempty"`
// Note is a text the run was marked with when written.
Note string `json:"note,omitempty"`
// LogicalBytes is the size of what the run saved, the sum of
// its members', and StoredBytes what it takes in the store, as
// written: compressed, before what a store shares between runs.
// A driver telling neither leaves them zero.
LogicalBytes int64 `json:"logical_bytes,omitempty"`
StoredBytes int64 `json:"stored_bytes,omitempty"`
}
Run is one sync update of one object, as a store holds it.
func FindRun ¶
FindRun returns the one run filter selects whose id is, or starts with, filter.ID, or the latest run filter selects when it names no id.
func FindSnapshot ¶
FindSnapshot returns the run ref names among the runs of every object of the store: its id, or a prefix of it, or else an object path, meaning the latest run of the object the store last recorded at that path. An id never holds a "/", but the path of an object of the root namespace has none either, so an id is tried first.
A path the runs of several clusters hold means the latest run of the local cluster, cluster, or of the one other cluster holding runs of it: the latest of several other clusters is not one to pick for the user.
func (Run) MemberNames ¶
MemberNames returns the names of the members of the run, in the order they were saved.
type RunFilter ¶
type RunFilter struct {
// Path selects the runs of the objects the store last recorded at
// this path, of every cluster: an object keeps its runs when it
// is renamed, and the runs it took before still say the path it
// had then. The store applies it, Match does not.
Path string
// ObjectID selects the runs of an object, whatever its path.
ObjectID string
// Cluster selects the runs the nodes of a cluster wrote, by the
// cluster id or name. A store resolves a name to the cluster it
// names now, so the runs a renamed cluster wrote are selected.
Cluster string
// ID selects the run whose id is, or starts with, ID.
ID string
// Incomplete selects the runs not completed too, as a failed
// or interrupted run left them.
Incomplete bool
// Since and Until select the runs created from Since on, and
// before Until. A driver skips what it can with them, as the
// objects with no run in the period, and Match applies them.
Since time.Time
Until time.Time
}
RunFilter selects runs. A zero field selects any.
type Sharer ¶
type Sharer interface {
}
Sharer is a store keeping its runs in a directory of the node: one every node reaches, as an nfs mount, when shared, or one per node otherwise, the directory of a peer reached over an ssh connection to it.
type Stats ¶
type Stats struct {
// Runs are the completed runs, and Incomplete the ones a failed
// or interrupted update left.
Runs int `json:"runs"`
Incomplete int `json:"incomplete"`
Protected int `json:"protected"`
// Objects are the objects with a run, counted by object id.
Objects int `json:"objects"`
FirstCreatedAt time.Time `json:"first_created_at,omitzero"`
LastCreatedAt time.Time `json:"last_created_at,omitzero"`
// LogicalBytes is the size of what the runs saved. StoredBytes
// is what they take in the store, nil when the driver can not
// tell, and FreeBytes the space left there, nil for a store not
// telling, as an object storage.
LogicalBytes int64 `json:"logical_bytes"`
StoredBytes *int64 `json:"stored_bytes,omitempty"`
FreeBytes *int64 `json:"free_bytes,omitempty"`
// CheckedAt is when the store was last reached, and CheckError
// why the last attempt failed to reach it.
CheckedAt time.Time `json:"checked_at,omitzero"`
CheckError string `json:"check_error,omitempty"`
// UpdatedAt is when these figures were computed.
UpdatedAt time.Time `json:"updated_at"`
// MissingNodes are the nodes whose directory was not read, a
// store keeping its runs in a directory of each node: the
// figures leave their runs out.
MissingNodes []string `json:"missing_nodes,omitempty"`
// Clusters break the figures down by the cluster that wrote the
// runs.
Clusters []ClusterStats `json:"clusters"`
}
Stats are the figures of a store, summed from the stats every object of it records: every cluster reading the store gets the same ones, the runs of every cluster writing it counted.
func StoreStats ¶
StoreStats computes the stats of the store s: the stats its objects record, and the space it takes and has left when it tells. The store unreachable, the stats say why, and when it was last reached is up to the caller to keep.
func SumStats ¶
func SumStats(objects []ObjectStats) Stats
SumStats sums the stats of the objects of a store. An object counts once it holds a run, a completed one or not. The stored bytes are summed when every object with a completed run tells them.
type Statser ¶
type Statser interface {
ObjectStats(ctx context.Context) ([]ObjectStats, error)
}
Statser is a store reading the stats every object of it records, of every cluster, one record per object rather than a read of every run.
type Store ¶
type Store interface {
// Ref is the reference to the store, as a store keyword or
// the --store option names it.
Ref() string
// Backup saves the directory src as the member of run, without
// the paths excludes matches, relative to src, and records head
// as the head of the member: src itself, or the head a snapshot
// at src is of.
Backup(ctx context.Context, run Run, member, src, head string, excludes []string) error
// Runs returns the runs filter selects, oldest first.
Runs(ctx context.Context, filter RunFilter) ([]Run, error)
// Complete marks the run completed, every member saved.
Complete(ctx context.Context, run Run) error
// Restore writes the member of run into the directory dst.
Restore(ctx context.Context, run Run, member string, dst string) error
// Check verifies the runs filter selects, the whole store
// with a zero filter.
Check(ctx context.Context, filter RunFilter) error
}
Store is what every store driver does.
type Streamer ¶
type Streamer interface {
BackupStream(ctx context.Context, run Run, member string, r io.Reader) error
Cat(ctx context.Context, run Run, member string) (io.ReadCloser, error)
}
Streamer is a store saving and reading members as streams, never written to a disk on the way: the configuration of an object and the keys it references.
type T ¶
type T struct {
// contains filtered or unexported fields
}
T is the base of the store drivers: the section declaring the store, the configuration holding it, the sec it is of, zero for a store of the cluster configuration, and the namespace of the object reading it, empty for a node command.
func (*T) Get ¶
Get returns the value of the option in the section of the store, evaluated, or as written when no keyword evaluates it, as in a configuration with no referrer.
func (*T) Owner ¶
Owner returns the sec declaring the store, zero for a store of the cluster configuration.
func (*T) Reader ¶
Reader returns the namespace of the object reading the store, empty for a node command.
func (*T) Ref ¶
Ref returns the reference to the store, as a store keyword names it: its name, the section without its prefix, for a store of the cluster configuration, and from <sec> store#<name> for a store of a sec.