restic

package
v1.3.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2020 License: Apache-2.0 Imports: 38 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

	// 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"
)
View Source
const (
	CredentialsSecretName = "velero-restic-credentials"
	CredentialsKey        = "repository-password"
)

Variables

This section is empty.

Functions

func AzureCmdEnv added in v0.10.0

func AzureCmdEnv(backupLocationLister velerov1listers.BackupStorageLocationLister, namespace, backupLocation string) ([]string, error)

AzureCmdEnv returns a list of environment variables (in the format var=val) that should be used when running a restic command for an Azure backend. This list is the current environment, plus the Azure-specific variables restic needs, namely a storage account name and key.

func EnsureCommonRepositoryKey

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

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 GetRepositoryKey

func GetRepositoryKey(secretGetter SecretGetter, namespace string) ([]byte, error)

func GetSnapshotID

func GetSnapshotID(repoIdentifier, passwordFile string, tags map[string]string, env []string) (string, error)

GetSnapshotID runs a 'restic snapshots' command to get the ID of the snapshot in the specified repo matching the set of provided tags, or an error if a unique snapshot cannot be identified.

func GetVolumeBackupsForPod added in v1.0.1

func GetVolumeBackupsForPod(podVolumeBackups []*velerov1api.PodVolumeBackup, pod metav1.Object) 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.

func NewPodVolumeBackupListOptions

func NewPodVolumeBackupListOptions(name string) metav1.ListOptions

NewPodVolumeBackupListOptions creates a ListOptions with a label selector configured to find PodVolumeBackups for the backup identified by name.

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 RunBackup added in v1.2.0

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 added in v1.2.0

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 S3CmdEnv added in v1.3.0

func S3CmdEnv(backupLocationLister velerov1listers.BackupStorageLocationLister, namespace, backupLocation string) ([]string, error)

S3CmdEnv returns a list of environment variables (in the format var=val) that should be used when running a restic command for an S3 backend. This list is the current environment, plus the AWS-specific variables restic needs, namely a credential profile.

func TempCredentialsFile

func TempCredentialsFile(secretLister corev1listers.SecretLister, veleroNamespace, repoName string, fs filesystem.Interface) (string, error)

TempCredentialsFile creates a temp file containing a restic encryption key for the given repo 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
	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 added in v1.0.0

func SnapshotsCommand(repoIdentifier string) *Command

func StatsCommand added in v0.10.2

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

func UnlockCommand added in v1.0.1

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 added in v1.0.1

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 SecretGetter

type SecretGetter interface {
	GetSecret(namespace, name string) (*corev1api.Secret, error)
}

func NewClientSecretGetter

func NewClientSecretGetter(client corev1client.SecretsGetter) SecretGetter

func NewListerSecretGetter

func NewListerSecretGetter(lister corev1listers.SecretLister) SecretGetter

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