Documentation ¶
Index ¶
- Variables
- func ApplyRetentionPolicies(policies []RetentionPolicy, subjects []RetentionPolicySubject) (map[string]struct{}, error)
- func BuildCommand(command []string, additionalArgs ...string) *exec.Cmd
- func CloseProxy(session *yamux.Session, rpcClient *rpc.Client) error
- func CompareBackups(a, b Backup) int
- func CompareSnapshots(a, b Snapshot) int
- func CopyFile(dst, src string) error
- func LoadPrivateKey(keyFile, key string) (age.Identity, error)
- func LoadPublicKey(keyFile, key string) (age.Recipient, error)
- func MakeIndex(backups []Backup) map[string]Backup
- func OpenProxy(logger *logrus.Entry, command []string) (*yamux.Session, *rpc.Client, *yamux.Stream, error)
- func ParseInterval(intv string) (int, error)
- func PruneBackups(dst Destination, backups []Backup, policies []RetentionPolicy) error
- func PruneSnapshots(src Source, snapshots []Snapshot, policies []RetentionPolicy, ...) error
- func ReadPresets(presetsDir string) (map[string][]KeyValuePair, error)
- func RunCommand(log *logrus.Entry, cmd *exec.Cmd) error
- func StartCommand(log *logrus.Entry, cmd *exec.Cmd) error
- type Backup
- func GetFullChain(backup Backup, index map[string]Backup) ([]Backup, bool)
- func GetPrunedBackups(backups []Backup, policies []RetentionPolicy) ([]Backup, error)
- func ParseBackupFilename(f string, requireExt bool) (Backup, error)
- func SortedListBackups(dst Destination) ([]Backup, error)
- func WrapSourceCommand(backup Backup, cmd *exec.Cmd, finalize func(err error) error) (Backup, io.ReadCloser, error)
- type Destination
- type KeyValuePair
- type Options
- type ReadWriteCloser
- type RetentionPolicy
- type RetentionPolicySubject
- type Snapshot
- type Source
Constants ¶
This section is empty.
Variables ¶
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 CloseProxy ¶ added in v0.5.0
func CompareBackups ¶
Compare backups by the date of their snapshot
func LoadPrivateKey ¶
Load a private key either from a file (if keyFile argument is provided), or from its content (key argument)
func LoadPublicKey ¶
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 ParseInterval ¶
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
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 ¶
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 ¶
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)
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 (*Options) GetCommand ¶
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 ¶
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 ¶
Sorted from most recent to least recent
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