restic

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: May 27, 2021 License: BSD-3-Clause Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// prometheus
	Namespace = "baas"
	Subsystem = "backup_restic"

	// general
	Hostname = "HOSTNAME"

	BackupDirEnv = "BACKUP_DIR"

	// Restore
	RestoreS3EndpointEnv     = "RESTORE_S3ENDPOINT"
	RestoreS3AccessKeyIDEnv  = "RESTORE_ACCESSKEYID"
	RestoreS3SecretAccessKey = "RESTORE_SECRETACCESSKEY"
	RestoreDirEnv            = "RESTORE_DIR"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ArrayOpts added in v0.2.0

type ArrayOpts []string

func (*ArrayOpts) BuildArgs added in v0.2.0

func (a *ArrayOpts) BuildArgs() []string

func (*ArrayOpts) Set added in v0.2.0

func (a *ArrayOpts) Set(value string) error

func (*ArrayOpts) String added in v0.2.0

func (a *ArrayOpts) String() string

type BackupStats added in v0.2.0

type BackupStats struct {
	Name          string      `json:"name,omitempty"`
	BucketName    string      `json:"bucket_name,omitempty"`
	BackupMetrics *RawMetrics `json:"backup_metrics,omitempty"`
	Snapshots     []Snapshot  `json:"snapshots,omitempty"`
}

func (*BackupStats) ToJson added in v0.2.0

func (b *BackupStats) ToJson() []byte

func (*BackupStats) ToProm added in v0.2.0

func (b *BackupStats) ToProm() []prometheus.Collector

type Command added in v0.2.0

type Command struct {
	FatalError error
	Errors     []error
	// contains filtered or unexported fields
}

Command can handle a given command.

func NewCommand added in v0.2.0

func NewCommand(ctx context.Context, log logr.Logger, commandOptions CommandOptions) *Command

NewCommand returns a new command

func (*Command) Configure added in v0.2.0

func (c *Command) Configure()

Configure will setup the command object. Mainly set the env vars and wire the right stdins/outs.

func (*Command) Run added in v0.2.0

func (c *Command) Run()

Run will run the currently configured command and wait for its completion.

func (*Command) Start added in v0.2.0

func (c *Command) Start()

Start starts the specified command but does not wait for it to complete.

func (*Command) Wait added in v0.2.0

func (c *Command) Wait()

Wait waits for the command to exit and waits for any copying to stdin or copying from stdout or stderr to complete.

type CommandOptions added in v0.2.0

type CommandOptions struct {
	Path   string    // path where the command is to be executed
	StdIn  io.Reader // set the StdIn for the command
	StdOut io.Writer // set the StdOut for the command
	StdErr io.Writer // set StdErr for the command
	Args   []string
}

CommandOptions contains options for the command struct.

type Flags added in v0.3.0

type Flags map[string][]string

Flags stores arguments to pass to `restic` and can return them as array, see ApplyToCommand().

func Combine added in v0.3.0

func Combine(first, second Flags) Flags

Combine returns a new Flags instance that contains the flags and their values of both, the given Flags and the Flags instance

func (Flags) AddFlag added in v0.3.0

func (f Flags) AddFlag(key string, values ...string)

AddFlag appends the given values to the existing flag (identified by key) if it exists or appends it and it's values to the end of the list of globalFlags otherwise.

func (Flags) ApplyToCommand added in v0.3.0

func (f Flags) ApplyToCommand(command string, commandArgs ...string) []string

ApplyToCommand applies the globalFlags to the given command and it's arguments, such that `newArgs = [command, globalFlags..., commandArgs...]`, in order the returning array to be passed to the `restic` process.

type Lock added in v0.2.0

type Lock struct {
	Time      time.Time `json:"time"`
	Exclusive bool      `json:"exclusive"`
	Hostname  string    `json:"hostname"`
	Username  string    `json:"username"`
	Pid       int       `json:"pid"`
	UID       int       `json:"uid"`
	Gid       int       `json:"gid"`
}

type PromMetrics added in v0.2.0

type PromMetrics struct {
	Errors             *prometheus.GaugeVec
	AvailableSnapshots prometheus.Gauge
	NewFiles           *prometheus.GaugeVec
	ChangedFiles       *prometheus.GaugeVec
	UnmodifiedFiles    *prometheus.GaugeVec
	NewDirs            *prometheus.GaugeVec
	ChangedDirs        *prometheus.GaugeVec
	UnmodifiedDirs     *prometheus.GaugeVec
	DataTransferred    *prometheus.GaugeVec
}

func (*PromMetrics) ToProm added in v0.2.0

func (p *PromMetrics) ToProm() []prometheus.Collector

type PrometheusProvider added in v0.2.0

type PrometheusProvider interface {
	ToProm() []prometheus.Collector
}

type RawMetrics added in v0.2.0

type RawMetrics struct {
	BackupStartTimestamp float64  `json:"backup_start_timestamp"`
	BackupEndTimestamp   float64  `json:"backup_end_timestamp"`
	Errors               float64  `json:"errors"`
	NewFiles             float64  `json:"new_files"`
	ChangedFiles         float64  `json:"changed_files"`
	UnmodifiedFiles      float64  `json:"unmodified_files"`
	NewDirs              float64  `json:"new_dirs"`
	ChangedDirs          float64  `json:"changed_dirs"`
	UnmodifiedDirs       float64  `json:"unmodified_dirs"`
	DataTransferred      float64  `json:"data_transferred"`
	MountedPVCs          []string `json:"mounted_PVCs"`

	Folder string

	ID string `json:"id"`
	// contains filtered or unexported fields
}

RawMetrics contains the raw metrics that can be obtained at the end of a backup. Webhookdata and prometheus statistics are derived from it.

type Restic

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

func New

func New(ctx context.Context, logger logr.Logger, statsHandler StatsHandler) *Restic

New returns a new Restic reference

func (*Restic) Archive added in v0.2.0

func (r *Restic) Archive(restoreFilter string, verifyRestore bool, tags ArrayOpts) error

Archive uploads the last version of each snapshot to S3.

func (*Restic) Backup added in v0.2.0

func (r *Restic) Backup(backupDir string, tags ArrayOpts) error

Backup backup to the repository. It will loop through all subfolders of backupdir and trigger a snapshot for each of them.

func (*Restic) Check added in v0.2.0

func (r *Restic) Check() error

Check will check the repository for errors

func (*Restic) Init added in v0.2.0

func (r *Restic) Init() error

Init initialises a repository, checks if the repositor exists and will initialise it if not. It's save to call this every time.

func (*Restic) LastSnapshots added in v0.2.0

func (r *Restic) LastSnapshots(tags ArrayOpts) error

LastSnapshots only returns the latests snapshots for a given set of tags.

func (*Restic) Prune added in v0.2.0

func (r *Restic) Prune(tags ArrayOpts) error

Prune will enforce the retention policy onto the repository

func (*Restic) Restore added in v0.2.0

func (r *Restic) Restore(snapshotID string, options RestoreOptions, tags ArrayOpts) error

Restore triggers a restore of a snapshot

func (*Restic) Snapshots added in v0.2.0

func (r *Restic) Snapshots(tags ArrayOpts) error

Snapshots lists all the snapshots from the repository and saves them in the restic instance for further use.

func (*Restic) StdinBackup added in v0.2.0

func (r *Restic) StdinBackup(data *kubernetes.ExecData, filename, fileExt string, tags ArrayOpts) error

StdinBackup create a snapshot with the data contained in the given reader.

func (*Restic) Unlock added in v0.2.0

func (r *Restic) Unlock(all bool) error

Unlock will remove stale locks from the repository

func (*Restic) Wait added in v0.2.0

func (r *Restic) Wait() error

Wait will block as long as there are any locks in the repository. As soon as they are all gone the function will return

type RestoreOptions added in v0.2.0

type RestoreOptions struct {
	RestoreType   RestoreType
	RestoreDir    string
	RestoreFilter string
	Verify        bool
	S3Destination S3Bucket
}

RestoreOptions holds options for a single restore, like type and destination.

type RestoreStats added in v0.2.3

type RestoreStats struct {
	RestoreLocation string   `json:"restore_location,omitempty"`
	SnapshotID      string   `json:"snapshot_ID,omitempty"`
	RestoredFiles   []string `json:"restored_files,omitempty"`
}

func (*RestoreStats) ToJson added in v0.2.3

func (r *RestoreStats) ToJson() []byte

type RestoreType added in v0.2.0

type RestoreType string

RestoreType defines the type for a restore.

const (
	FolderRestore RestoreType = "folder"
	S3Restore     RestoreType = "s3"
)

type S3Bucket added in v0.2.0

type S3Bucket struct {
	Endpoint  string
	AccessKey string
	SecretKey string
}

type Snapshot

type Snapshot struct {
	ID       string    `json:"id"`
	Time     time.Time `json:"time"`
	Tree     string    `json:"tree"`
	Paths    []string  `json:"paths"`
	Hostname string    `json:"hostname"`
	Username string    `json:"username"`
	UID      int       `json:"uid"`
	Gid      int       `json:"gid"`
	Tags     []string  `json:"tags"`
}

Snapshot models a restic a single snapshot from the snapshots --json subcommand.

type StatsHandler added in v0.2.0

type StatsHandler interface {
	SendPrometheus(PrometheusProvider) error
	SendWebhook(WebhookProvider) error
}

type WebhookProvider added in v0.2.0

type WebhookProvider interface {
	ToJson() []byte
}

Jump to

Keyboard shortcuts

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