restic

package
v0.10.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2020 License: Apache-2.0 Imports: 37 Imported by: 19

Documentation

Index

Constants

View Source
const (
	DefaultOutputFileName = "output.json"
	DefaultScratchDir     = "/tmp"
	DefaultHost           = "host-0"
)
View Source
const (
	MetricsLabelDriver     = "driver"
	MetricsLabelKind       = "kind"
	MetricsLabelAppGroup   = "group"
	MetricsLabelName       = "name"
	MetricsLabelNamespace  = "namespace"
	MetricsLabelRepository = "repository"
	MetricsLabelBackend    = "backend"
	MetricsLabelBucket     = "bucket"
	MetricsLabelPrefix     = "prefix"
)
View Source
const (
	RESTIC_REPOSITORY = "RESTIC_REPOSITORY"
	RESTIC_PASSWORD   = "RESTIC_PASSWORD"
	TMPDIR            = "TMPDIR"

	AWS_ACCESS_KEY_ID     = "AWS_ACCESS_KEY_ID"
	AWS_SECRET_ACCESS_KEY = "AWS_SECRET_ACCESS_KEY"
	AWS_DEFAULT_REGION    = "AWS_DEFAULT_REGION"

	GOOGLE_PROJECT_ID               = "GOOGLE_PROJECT_ID"
	GOOGLE_SERVICE_ACCOUNT_JSON_KEY = "GOOGLE_SERVICE_ACCOUNT_JSON_KEY"
	GOOGLE_APPLICATION_CREDENTIALS  = "GOOGLE_APPLICATION_CREDENTIALS"

	AZURE_ACCOUNT_NAME = "AZURE_ACCOUNT_NAME"
	AZURE_ACCOUNT_KEY  = "AZURE_ACCOUNT_KEY"

	REST_SERVER_USERNAME = "REST_SERVER_USERNAME"
	REST_SERVER_PASSWORD = "REST_SERVER_PASSWORD"

	B2_ACCOUNT_ID  = "B2_ACCOUNT_ID"
	B2_ACCOUNT_KEY = "B2_ACCOUNT_KEY"

	// For keystone v1 authentication
	ST_AUTH = "ST_AUTH"
	ST_USER = "ST_USER"
	ST_KEY  = "ST_KEY"
	// For keystone v2 authentication (some variables are optional)
	OS_AUTH_URL    = "OS_AUTH_URL"
	OS_REGION_NAME = "OS_REGION_NAME"
	OS_USERNAME    = "OS_USERNAME"
	OS_PASSWORD    = "OS_PASSWORD"
	OS_TENANT_ID   = "OS_TENANT_ID"
	OS_TENANT_NAME = "OS_TENANT_NAME"
	// For keystone v3 authentication (some variables are optional)
	OS_USER_DOMAIN_NAME    = "OS_USER_DOMAIN_NAME"
	OS_PROJECT_NAME        = "OS_PROJECT_NAME"
	OS_PROJECT_DOMAIN_NAME = "OS_PROJECT_DOMAIN_NAME"
	// For keystone v3 application credential authentication (application credential id)
	OS_APPLICATION_CREDENTIAL_ID     = "OS_APPLICATION_CREDENTIAL_ID"
	OS_APPLICATION_CREDENTIAL_SECRET = "OS_APPLICATION_CREDENTIAL_SECRET"
	// For keystone v3 application credential authentication (application credential name)
	OS_APPLICATION_CREDENTIAL_NAME = "OS_APPLICATION_CREDENTIAL_NAME"
	// For authentication based on tokens
	OS_STORAGE_URL = "OS_STORAGE_URL"
	OS_AUTH_TOKEN  = "OS_AUTH_TOKEN"

	// For using certs in Minio server or REST server
	CA_CERT_DATA = "CA_CERT_DATA"
)
View Source
const FileModeRWXAll = 0777
View Source
const (
	ResticCMD = "/bin/restic_0.9.6"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BackupHostMetrics

type BackupHostMetrics struct {
	// BackupSuccess indicates whether the backup for a host succeeded or not
	BackupSuccess prometheus.Gauge
	// BackupDuration indicates total time taken to complete the backup process for a host
	BackupDuration prometheus.Gauge
	// DataSize indicates total size of the target data to backup for a host (in bytes)
	DataSize prometheus.Gauge
	// DataUploaded indicates the amount of data uploaded to the repository for a host (in bytes)
	DataUploaded prometheus.Gauge
	// DataProcessingTime indicates total time taken to backup the target data for a host
	DataProcessingTime prometheus.Gauge
	// FileMetrics shows information of backup files
	FileMetrics *FileMetrics
}

BackupHostMetrics defines Prometheus metrics for individual hosts backup

type BackupMetrics

type BackupMetrics struct {
	// BackupSessionMetrics shows metrics related to entire backup session
	BackupSessionMetrics *BackupSessionMetrics
	// BackupHostMetrics shows backup metrics for individual hosts
	BackupHostMetrics *BackupHostMetrics
}

BackupMetrics defines prometheus metrics for backup process

type BackupOptions

type BackupOptions struct {
	Host             string
	BackupPaths      []string
	StdinPipeCommand Command
	StdinFileName    string // default "stdin"
	RetentionPolicy  v1alpha1.RetentionPolicy
}

BackupOptions specifies backup information if StdinPipeCommand is specified, BackupPaths will not be used

type BackupOutput

type BackupOutput struct {
	// HostBackupStats shows backup statistics of a host
	HostBackupStats []api_v1beta1.HostBackupStats `json:"hostBackupStats,omitempty"`
	// RepositoryStats shows statistics of repository after last backup
	RepositoryStats RepositoryStats `json:"repository,omitempty"`
}

func ReadBackupOutput

func ReadBackupOutput(filename string) (*BackupOutput, error)

func (*BackupOutput) WriteOutput

func (out *BackupOutput) WriteOutput(fileName string) error

WriteOutput write output of backup process into output.json file in the directory specified by outputDir parameter

type BackupSessionMetrics

type BackupSessionMetrics struct {
	// SessionSuccess indicates whether the entire backup session was succeeded or not
	SessionSuccess prometheus.Gauge
	// SessionDuration indicates total time taken to complete the entire backup session
	SessionDuration prometheus.Gauge
	// HostCount indicates the total number of hosts of a target that was backed up in this backup session
	HostCount prometheus.Gauge
}

BackupSessionMetrics defines metrics for entire backup session

type BackupSummary

type BackupSummary struct {
	MessageType         string  `json:"message_type"` // "summary"
	FilesNew            *int64  `json:"files_new"`
	FilesChanged        *int64  `json:"files_changed"`
	FilesUnmodified     *int64  `json:"files_unmodified"`
	DataAdded           uint64  `json:"data_added"`
	TotalFilesProcessed *int64  `json:"total_files_processed"`
	TotalBytesProcessed uint64  `json:"total_bytes_processed"`
	TotalDuration       float64 `json:"total_duration"` // in seconds
	SnapshotID          string  `json:"snapshot_id"`
}

type Command

type Command struct {
	Name string
	Args []interface{}
}

type DumpOptions

type DumpOptions struct {
	Host              string
	SourceHost        string
	Snapshot          string // default "latest"
	Path              string
	FileName          string // default "stdin"
	StdoutPipeCommand Command
}

type FileMetrics

type FileMetrics struct {
	// TotalFiles shows total number of files that has been backed up for a host
	TotalFiles prometheus.Gauge
	// NewFiles shows total number of new files that has been created since last backup for a host
	NewFiles prometheus.Gauge
	// ModifiedFiles shows total number of files that has been modified since last backup for a host
	ModifiedFiles prometheus.Gauge
	// UnmodifiedFiles shows total number of files that has not been changed since last backup for a host
	UnmodifiedFiles prometheus.Gauge
}

FileMetrics defines Prometheus metrics for target files of a backup process for a host

type ForgetGroup

type ForgetGroup struct {
	Keep   []json.RawMessage `json:"keep"`
	Remove []json.RawMessage `json:"remove"`
}

type MetricsOptions

type MetricsOptions struct {
	Enabled        bool
	PushgatewayURL string
	MetricFileDir  string
	Labels         []string
	JobName        string
}

func (*MetricsOptions) SendBackupHostMetrics

func (metricOpt *MetricsOptions) SendBackupHostMetrics(config *rest.Config, invoker apis.Invoker, targetInfo apis.TargetInfo, backupOutput *BackupOutput) error

SendBackupSessionMetrics send backup metrics for individual hosts to the Pushgateway

func (*MetricsOptions) SendBackupSessionMetrics

func (metricOpt *MetricsOptions) SendBackupSessionMetrics(config *rest.Config, invoker apis.Invoker, status api_v1beta1.BackupSessionStatus) error

SendBackupSessionMetrics send backup session metrics to the Pushgateway

func (*MetricsOptions) SendRestoreHostMetrics

func (metricOpt *MetricsOptions) SendRestoreHostMetrics(config *rest.Config, restoreSession *api_v1beta1.RestoreSession, restoreOutput *RestoreOutput) error

SendRestoreHostMetrics send restore metrics for individual hosts to the Pushgateway

func (*MetricsOptions) SendRestoreSessionMetrics

func (metricOpt *MetricsOptions) SendRestoreSessionMetrics(config *rest.Config, restoreSession *api_v1beta1.RestoreSession) error

SendRestoreSessionMetrics send restore session metrics to the Pushgateway

type RepositoryMetrics

type RepositoryMetrics struct {
	// RepoIntegrity shows result of repository integrity check after last backup
	RepoIntegrity prometheus.Gauge
	// RepoSize show size of repository after last backup
	RepoSize prometheus.Gauge
	// SnapshotCount shows number of snapshots stored in the repository
	SnapshotCount prometheus.Gauge
	// SnapshotsRemovedOnLastCleanup shows number of old snapshots cleaned up according to retention policy on last backup session
	SnapshotsRemovedOnLastCleanup prometheus.Gauge
}

RepositoryMetrics defines Prometheus metrics for Repository state after each backup

type RepositoryStats

type RepositoryStats struct {
	// Integrity shows result of repository integrity check after last backup
	Integrity *bool `json:"integrity,omitempty"`
	// Size show size of repository after last backup
	Size string `json:"size,omitempty"`
	// SnapshotCount shows number of snapshots stored in the repository
	SnapshotCount int64 `json:"snapshotCount,omitempty"`
	// SnapshotsRemovedOnLastCleanup shows number of old snapshots cleaned up according to retention policy on last backup session
	SnapshotsRemovedOnLastCleanup int64 `json:"snapshotsRemovedOnLastCleanup,omitempty"`
}

type ResticWrapper

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

func NewResticWrapper

func NewResticWrapper(options SetupOptions) (*ResticWrapper, error)

func (*ResticWrapper) Copy

func (w *ResticWrapper) Copy() *ResticWrapper

Copy function copy input ResticWrapper and returns a new wrapper with copy of its content.

func (*ResticWrapper) DeleteSnapshots

func (w *ResticWrapper) DeleteSnapshots(snapshotIDs []string) ([]byte, error)

func (*ResticWrapper) Dump

func (w *ResticWrapper) Dump(dumpOptions DumpOptions) (*RestoreOutput, error)

Dump run restore process for a single host and output the restored files in stdout.

func (*ResticWrapper) DumpEnv

func (w *ResticWrapper) DumpEnv(path string, dumpedFile string) error

func (*ResticWrapper) GetRepo

func (w *ResticWrapper) GetRepo() string

func (*ResticWrapper) GetSnapshotSize

func (w *ResticWrapper) GetSnapshotSize(snapshotID string) (uint64, error)

GetSnapshotSize returns size of a snapshot in bytes

func (*ResticWrapper) HideCMD

func (w *ResticWrapper) HideCMD()

func (*ResticWrapper) ListSnapshots

func (w *ResticWrapper) ListSnapshots(snapshotIDs []string) ([]Snapshot, error)

func (*ResticWrapper) ParallelDump

func (w *ResticWrapper) ParallelDump(dumpOptions []DumpOptions, maxConcurrency int) (*RestoreOutput, error)

ParallelDump run dump for multiple hosts concurrently using go routine. You can control maximum number of parallel restore process using maxConcurrency parameter.

func (*ResticWrapper) RunBackup

func (w *ResticWrapper) RunBackup(backupOption BackupOptions) (*BackupOutput, error)

RunBackup takes backup, cleanup old snapshots, check repository integrity etc. It extract valuable information from respective restic command it runs and return them for further use.

func (*ResticWrapper) RunParallelBackup

func (w *ResticWrapper) RunParallelBackup(backupOptions []BackupOptions, maxConcurrency int) (*BackupOutput, error)

RunParallelBackup runs multiple backup in parallel. Host must be different for each backup.

func (*ResticWrapper) RunParallelRestore

func (w *ResticWrapper) RunParallelRestore(restoreOptions []RestoreOptions, maxConcurrency int) (*RestoreOutput, error)

RunParallelRestore run restore process for multiple hosts in parallel using go routine. You can control maximum number of parallel restore using maxConcurrency parameter.

func (*ResticWrapper) RunRestore

func (w *ResticWrapper) RunRestore(restoreOptions RestoreOptions) (*RestoreOutput, error)

RunRestore run restore process for a single host.

func (*ResticWrapper) SetEnv

func (w *ResticWrapper) SetEnv(key, value string)

func (*ResticWrapper) UnlockRepository

func (w *ResticWrapper) UnlockRepository() error

type RestoreHostMetrics

type RestoreHostMetrics struct {
	// RestoreSuccess indicates whether restore was succeeded or not for a host
	RestoreSuccess prometheus.Gauge
	// RestoreDuration indicates the time taken to complete the restore process for a host
	RestoreDuration prometheus.Gauge
}

RestoreHostMetrics defines restore metrics for individual hosts

type RestoreMetrics

type RestoreMetrics struct {
	// RestoreSessionMetrics shows metrics related to entire restore session
	RestoreSessionMetrics *RestoreSessionMetrics
	// RestoreHostMetrics shows restore metrics for individual hosts
	RestoreHostMetrics *RestoreHostMetrics
}

RestoreMetrics defines metrics for restore process

type RestoreOptions

type RestoreOptions struct {
	Host         string
	SourceHost   string
	RestorePaths []string
	Snapshots    []string // when Snapshots are specified SourceHost and RestorePaths will not be used
	Destination  string   // destination path where snapshot will be restored, used in cli
}

RestoreOptions specifies restore information

type RestoreOutput

type RestoreOutput struct {
	// HostRestoreStats shows restore statistics of a host
	HostRestoreStats []api_v1beta1.HostRestoreStats `json:"hostRestoreStats,omitempty"`
}

func ReadRestoreOutput

func ReadRestoreOutput(filename string) (*RestoreOutput, error)

func (*RestoreOutput) WriteOutput

func (out *RestoreOutput) WriteOutput(fileName string) error

type RestoreSessionMetrics

type RestoreSessionMetrics struct {
	// SessionSuccess indicates whether the restore session succeeded or not
	SessionSuccess prometheus.Gauge
	// SessionDuration indicates the total time taken to complete the entire restore session
	SessionDuration prometheus.Gauge
	// HostCount indicates the number of hosts that was restored in this restore session
	HostCount prometheus.Gauge
}

RestoreSessionMetrics defines metrics related to entire restore session

type SetupOptions

type SetupOptions struct {
	Provider       string
	Bucket         string
	Endpoint       string
	Region         string
	Path           string
	SecretDir      string
	CacertFile     string
	ScratchDir     string
	EnableCache    bool
	MaxConnections int64
	Nice           *ofst.NiceSettings
	IONice         *ofst.IONiceSettings
}

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"`
}

type StatsContainer

type StatsContainer struct {
	TotalSize uint64 `json:"total_size"`
}

Jump to

Keyboard shortcuts

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