cli

package
v2.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArrayOpts

type ArrayOpts []string

func (*ArrayOpts) BuildArgs

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

func (*ArrayOpts) Set

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

func (*ArrayOpts) String

func (a *ArrayOpts) String() string

type BackupStats

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

func (*BackupStats) ToJSON

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

func (*BackupStats) ToProm

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

type Command

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

Command can handle a given command.

func NewCommand

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

NewCommand returns a new command

func (*Command) Configure

func (c *Command) Configure()

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

func (*Command) Run

func (c *Command) Run()

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

func (*Command) Start

func (c *Command) Start()

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

func (*Command) Wait

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

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

type Flags map[string][]string

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

func Combine

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

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

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

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

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

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

type PrometheusProvider

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

type RawMetrics

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

func (r *Restic) Archive(options RestoreOptions, tags ArrayOpts) error

Archive uploads the last version of each snapshot to S3.

func (*Restic) Backup

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

func (r *Restic) Check() error

Check will check the repository for errors

func (*Restic) Init

func (r *Restic) Init() error

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

func (*Restic) LastSnapshots

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

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

func (*Restic) Prune

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

Prune will enforce the retention policy onto the repository

func (*Restic) Restore

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

Restore triggers a restore of a snapshot

func (*Restic) Snapshots

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

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

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

Unlock will remove stale locks from the repository If the all flag is set to true, even non-stale locks are removed.

func (*Restic) Wait

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

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

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

func (*RestoreStats) ToJSON

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

type RestoreType

type RestoreType string

RestoreType defines the type for a restore.

const (
	// FolderRestore indicates that a restore to a folder should be performed.
	FolderRestore RestoreType = cfg.RestoreTypeFolder
	// S3Restore indicates that a restore to a S3 endpoint should be performed.
	S3Restore RestoreType = cfg.RestoreTypeS3
)

type S3Bucket

type S3Bucket struct {
	Endpoint  string
	AccessKey string
	SecretKey string
	Cert      S3Cert
}

type S3Cert added in v2.9.0

type S3Cert struct {
	CACert     string
	ClientCert string
	ClientKey  string
}

type StatsHandler

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

type WebhookProvider

type WebhookProvider interface {
	ToJSON() []byte
}

Jump to

Keyboard shortcuts

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