retention

package
v2.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package retention implements a stateless algorithm for determining which of a sequence of backups to retain with decreasing granularity over time. It is based on the retention algorithm used by Acronis Disaster Recovery Service.

See also: https://kb.acronis.com/content/58486

Since both "backups" and "buckets" start with "b", hereafter the word "snapshots" will be used instead of "backups" for readability.

Snapshots using this method should follow a few principals: 1. Use Config.MinInterval to schedule the snapshot jobs. 2. If a previous snapshot job has not finished yet, the next one doesn't run.

Example Use:

c := retention.Config{
	Hourly:  24,
	Daily:   6,
	Weekly:  4,
	Monthly: 11,
	Yearly:  1,
}
for range time.Tick(c.MinInterval()) {
	DoSnapshot()
	backupTimes := ListSnapshots()
	toDelete := retention.Delete(c, backupTimes)
	DeleteSnapshots(toDelete)
}

Index

Constants

View Source
const (
	// Hour duration.
	Hour = time.Hour

	// Day duration.
	Day = 24 * Hour

	// Week duration.
	Week = 7 * Day

	// Year duration.
	Year = time.Duration(365.2425 * float64(Day))

	// Month duration.
	Month = Year / 12
)

Variables

This section is empty.

Functions

func Delete

func Delete(c Config, snapshots []time.Time) []time.Time

Delete is the inverse of Keep, returning snapshots to delete.

func Keep

func Keep(c Config, snapshots []time.Time) []time.Time

Keep takes a list of times that snapshots were taken at and returns which ones should be kept.

The retention policy is based on the last snapshot time, not use the current time. Times will be returned in sorted order.

Types

type Config

type Config struct {
	// Number of hourly snapshots to retain.
	Hourly uint

	// Number of daily snapshots to retain.
	Daily uint

	// Number of weekly snapshots to retain.
	Weekly uint

	// Number of monthly snapshots to retain.
	Monthly uint

	// Number of yearly snapshots to retain.
	Yearly uint
}

Config represents the number of snapshots to retain.

func (Config) MinInterval

func (c Config) MinInterval() time.Duration

MinInterval returns the minimum duration between snapshots. This is the interval between which backup jobs should run. If no buckets are defined, returns -1.

Jump to

Keyboard shortcuts

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