labelmanager

package
v0.0.0-...-395ddcd Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package labelmanager contains a store to manage retention of backups through "labels" assigned in a specific format

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoLabelsAdded signalizes when adding an entry all possible
	// labels were already present and the entry has not been added
	ErrNoLabelsAdded = errors.New("no labels were available to add")
	// ErrNoBackupFound signalizes there was no backup older than the
	// given point-in-time
	ErrNoBackupFound = errors.New("no backup found for point-in-time")
)
View Source
var DefaultRetentionConfig = map[string]time.Duration{
	"%Y-%m":             durTwelveMonths,
	"%Y-w%V":            durOneMonth,
	"%Y-%m-%d":          durOneWeek,
	"%Y-%m-%dT%H":       durOneDay,
	"%Y-%m-%dT%H-%M-%S": time.Hour,
}

DefaultRetentionConfig defines a two-year retention schema with 24 hourly, 7 daily, 4 weekly and 12 monthly backups. Other backups are held one hour.

Functions

This section is empty.

Types

type Manager

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

Manager is a helper to organize and book-keep the entries based on a Grandfather-Father-Son principle

func New

func New(labelStorage io.Reader, retention RetentionConfig) (*Manager, error)

New creates a new Manager configured with the baseDir and the RetentionConfig defining how long to keep backups

if labelStorage is nil, an empty manager will be initialized if retention is nil, the DefaultRetentionConfig will be used

func (Manager) Add

func (m Manager) Add(entryName string) error

Add adds a new backup to the manager. When adding it is assigned labels defined by the RetentionConfig in case they are not already assigned to any other backup. This ensures the generations are kept for as long as the RetentionConfig defines

Returns ErrNoLabelsAdded in case all possible labels were already set. In this case the entry is not added to the Manager / store.

func (Manager) CleanRetentions

func (m Manager) CleanRetentions()

CleanRetentions iterates all labels present and removes labels no longer covered by their retention duration

func (Manager) GetClosestOlderBackup

func (m Manager) GetClosestOlderBackup(pointInTime time.Time) (string, error)

GetClosestOlderBackup retrieves the backup closest to the given point in time but being created BEFORE that point in time

Returns ErrNoBackupFound when there is no backup to return

func (Manager) GetRetainedEntries

func (m Manager) GetRetainedEntries() []string

GetRetainedEntries lists all entries which match IsRetained

func (Manager) GetUnretainedEntries

func (m Manager) GetUnretainedEntries() []string

GetUnretainedEntries lists all entries which do not match IsRetained

func (Manager) IsKnown

func (m Manager) IsKnown(entryName string) bool

IsKnown checks whether a backup is known to the Manager

func (Manager) IsRetained

func (m Manager) IsRetained(entryName string) bool

IsRetained checks whether there are still valid labels on the backup and therefore whether it should be retained or not. Before using IsRetained a CleanRetentions run should be executed in order to clean timed out labels.

func (Manager) Remove

func (m Manager) Remove(entryName string)

Remove removes an entry from the Manager causing IsKnown and IsRetained will return false afterwards

func (Manager) Save

func (m Manager) Save(dest io.Writer) error

Save stores the retention data to the given writer. You should take care this is an atomic write by writing into temp location and moving afterwards

type RetentionConfig

type RetentionConfig map[string]time.Duration

RetentionConfig specifies strftime formats and their respective retention periods. Ths is used to generate labels for entries and therefore define how long the entry is retained on disk

Jump to

Keyboard shortcuts

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