restic

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2021 License: Apache-2.0 Imports: 39 Imported by: 0

Documentation

Overview

Copyright 2018 the Velero contributors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	// DaemonSet is the name of the Velero restic daemonset.
	DaemonSet = "restic"

	// InitContainer is the name of the init container added
	// to workload pods to help with restores.
	InitContainer = "restic-wait"

	// DefaultMaintenanceFrequency is the default time interval
	// at which restic prune is run.
	DefaultMaintenanceFrequency = 7 * 24 * time.Hour

	// DefaultVolumesToRestic specifies whether restic should be used, by default, to
	// take backup of all pod volumes.
	DefaultVolumesToRestic = false

	// PVCNameAnnotation is the key for the annotation added to
	// pod volume backups when they're for a PVC.
	PVCNameAnnotation = "velero.io/pvc-name"

	// VolumesToBackupAnnotation is the annotation on a pod whose mounted volumes
	// need to be backed up using restic.
	VolumesToBackupAnnotation = "backup.velero.io/backup-volumes"

	// VolumesToExcludeAnnotation is the annotation on a pod whose mounted volumes
	// should be excluded from restic backup.
	VolumesToExcludeAnnotation = "backup.velero.io/backup-volumes-excludes"
)

Variables

This section is empty.

Functions

func CmdEnv

func CmdEnv(backupLocation *velerov1api.BackupStorageLocation, credentialFileStore credentials.FileStore) ([]string, error)

CmdEnv returns a list of environment variables (in the format var=val) that should be used when running a restic command for a particular backend provider. This list is the current environment, plus any provider-specific variables restic needs.

func EnsureCommonRepositoryKey

func EnsureCommonRepositoryKey(secretClient corev1client.SecretsGetter, namespace string) error

func GetPodVolumesUsingRestic

func GetPodVolumesUsingRestic(pod *corev1api.Pod, defaultVolumesToRestic bool) []string

GetPodVolumesUsingRestic returns a list of volume names to backup for the provided pod.

func GetRepoIdentifier

func GetRepoIdentifier(location *velerov1api.BackupStorageLocation, name string) (string, error)

GetRepoIdentifier returns the string to be used as the value of the --repo flag in restic commands for the given repository.

func GetSnapshotID

func GetSnapshotID(snapshotIdCmd *Command) (string, error)

GetSnapshotID runs provided 'restic snapshots' command to get the ID of a snapshot and an error if a unique snapshot cannot be identified.

func GetVolumeBackupsForPod

func GetVolumeBackupsForPod(podVolumeBackups []*velerov1api.PodVolumeBackup, pod metav1.Object, sourcePodNs string) map[string]string

GetVolumeBackupsForPod returns a map, of volume name -> snapshot id, of the PodVolumeBackups that exist for the provided pod.

func GetVolumesToBackup

func GetVolumesToBackup(obj metav1.Object) []string

GetVolumesToBackup returns a list of volume names to backup for the provided pod. Deprecated: Use GetPodVolumesUsingRestic instead.

func NewPodVolumeRestoreListOptions

func NewPodVolumeRestoreListOptions(name string) metav1.ListOptions

NewPodVolumeRestoreListOptions creates a ListOptions with a label selector configured to find PodVolumeRestores for the restore identified by name.

func RepoKeySelector

func RepoKeySelector() *corev1api.SecretKeySelector

RepoKeySelector returns the SecretKeySelector which can be used to fetch the restic repository key.

func RunBackup

func RunBackup(backupCmd *Command, log logrus.FieldLogger, updateFunc func(velerov1api.PodVolumeOperationProgress)) (string, string, error)

RunBackup runs a `restic backup` command and watches the output to provide progress updates to the caller.

func RunRestore

func RunRestore(restoreCmd *Command, log logrus.FieldLogger, updateFunc func(velerov1api.PodVolumeOperationProgress)) (string, string, error)

RunRestore runs a `restic restore` command and monitors the volume size to provide progress updates to the caller.

func TempCACertFile

func TempCACertFile(caCert []byte, bsl string, fs filesystem.Interface) (string, error)

TempCACertFile creates a temp file containing a CA bundle and returns its path. The caller should generally call os.Remove() to remove the file when done with it.

Types

type BackendType

type BackendType string
const (
	AWSBackend   BackendType = "velero.io/aws"
	AzureBackend BackendType = "velero.io/azure"
	GCPBackend   BackendType = "velero.io/gcp"
)

type Backupper

type Backupper interface {
	// BackupPodVolumes backs up all specified volumes in a pod.
	BackupPodVolumes(backup *velerov1api.Backup, pod *corev1api.Pod, volumesToBackup []string, log logrus.FieldLogger) ([]*velerov1api.PodVolumeBackup, []error)
}

Backupper can execute restic backups of volumes in a pod.

type BackupperFactory

type BackupperFactory interface {
	// NewBackupper returns a restic backupper for use during a single
	// Velero backup.
	NewBackupper(context.Context, *velerov1api.Backup) (Backupper, error)
}

BackupperFactory can construct restic backuppers.

type Command

type Command struct {
	Command        string
	RepoIdentifier string
	PasswordFile   string
	CACertFile     string
	Dir            string
	Args           []string
	ExtraFlags     []string
	Env            []string
}

Command represents a restic command.

func BackupCommand

func BackupCommand(repoIdentifier, passwordFile, path string, tags map[string]string) *Command

BackupCommand returns a Command for running a restic backup.

func ForgetCommand

func ForgetCommand(repoIdentifier, snapshotID string) *Command

func GetSnapshotCommand

func GetSnapshotCommand(repoIdentifier, passwordFile string, tags map[string]string) *Command

GetSnapshotCommand returns a Command for running a restic (get) snapshots.

func InitCommand

func InitCommand(repoIdentifier string) *Command

func PruneCommand

func PruneCommand(repoIdentifier string) *Command

func RestoreCommand

func RestoreCommand(repoIdentifier, passwordFile, snapshotID, target string) *Command

RestoreCommand returns a Command for running a restic restore.

func SnapshotsCommand

func SnapshotsCommand(repoIdentifier string) *Command

func StatsCommand

func StatsCommand(repoIdentifier, passwordFile, snapshotID string) *Command

func UnlockCommand

func UnlockCommand(repoIdentifier string) *Command

func (*Command) Cmd

func (c *Command) Cmd() *exec.Cmd

Cmd returns an exec.Cmd for the command.

func (*Command) RepoName

func (c *Command) RepoName() string

func (*Command) String

func (c *Command) String() string

String returns the command as a string.

func (*Command) StringSlice

func (c *Command) StringSlice() []string

StringSlice returns the command as a slice of strings.

type RepositoryManager

type RepositoryManager interface {
	// InitRepo initializes a repo with the specified name and identifier.
	InitRepo(repo *velerov1api.ResticRepository) error

	// ConnectToRepo runs the 'restic snapshots' command against the
	// specified repo, and returns an error if it fails. This is
	// intended to be used to ensure that the repo exists/can be
	// authenticated to.
	ConnectToRepo(repo *velerov1api.ResticRepository) error

	// PruneRepo deletes unused data from a repo.
	PruneRepo(repo *velerov1api.ResticRepository) error

	// UnlockRepo removes stale locks from a repo.
	UnlockRepo(repo *velerov1api.ResticRepository) error

	// Forget removes a snapshot from the list of
	// available snapshots in a repo.
	Forget(context.Context, SnapshotIdentifier) error

	BackupperFactory

	RestorerFactory
}

RepositoryManager executes commands against restic repositories.

func NewRepositoryManager

NewRepositoryManager constructs a RepositoryManager.

type RestoreData

type RestoreData struct {
	Restore                         *velerov1api.Restore
	Pod                             *corev1api.Pod
	PodVolumeBackups                []*velerov1api.PodVolumeBackup
	SourceNamespace, BackupLocation string
}

type Restorer

type Restorer interface {
	// RestorePodVolumes restores all annotated volumes in a pod.
	RestorePodVolumes(RestoreData) []error
}

Restorer can execute restic restores of volumes in a pod.

type RestorerFactory

type RestorerFactory interface {
	// NewRestorer returns a restic restorer for use during a single
	// Velero restore.
	NewRestorer(context.Context, *velerov1api.Restore) (Restorer, error)
}

RestorerFactory can construct restic restorers.

type SnapshotIdentifier

type SnapshotIdentifier struct {
	// VolumeNamespace is the namespace of the pod/volume that
	// the restic snapshot is for.
	VolumeNamespace string

	// BackupStorageLocation is the backup's storage location
	// name.
	BackupStorageLocation string

	// SnapshotID is the short ID of the restic snapshot.
	SnapshotID string
}

SnapshotIdentifier uniquely identifies a restic snapshot taken by Velero.

func GetSnapshotsInBackup

func GetSnapshotsInBackup(backup *velerov1api.Backup, podVolumeBackupLister velerov1listers.PodVolumeBackupLister) ([]SnapshotIdentifier, error)

GetSnapshotsInBackup returns a list of all restic snapshot ids associated with a given Velero backup.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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