backup

package
v1.31.21 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2025 License: BSD-3-Clause Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// DefaultChunkSize if size is not specified
	DefaultChunkSize = 1 << 27 // 128MB

	// DefaultCPUPercentage default CPU percentage can be consumed by the file writer
	DefaultCPUPercentage = 50
)

TODO adjust or make configurable

View Source
const (
	// BackupFile used by a node to store its metadata
	BackupFile = "backup.json"
	// GlobalBackupFile used by coordinator to store its metadata
	GlobalBackupFile  = "backup_config.json"
	GlobalRestoreFile = "restore_config.json"
	TempDirectory     = ".backup.tmp"
)
View Source
const (
	// Version > version1 support compression
	// "2.1" support restore on 2 phases
	Version = "2.1"
)

Version of backup structure

Variables

This section is empty.

Functions

func NewNodeStore added in v1.27.2

func NewNodeStore(backend modulecapabilities.BackupBackend, backupId, bucket, path string) *nodeStore

func NewUnzip added in v1.21.0

func NewUnzip(dst string) (unzip, io.WriteCloser)

func NewZip added in v1.21.0

func NewZip(sourcePath string, level int) (zip, io.ReadCloser)

func RestoreClassDir added in v1.25.0

func RestoreClassDir(dataPath string) func(class string) error

RestoreClassDir returns a func that restores classes on the filesystem directly from the temporary class backup stored on disk. This function is invoked by the Raft store when a restoration request is sent by the backup coordinator.

Types

type AbortRequest

type AbortRequest StatusRequest

type BackupBackendProvider

type BackupBackendProvider interface {
	BackupBackend(backend string) (modulecapabilities.BackupBackend, error)
	EnabledBackupBackends() []modulecapabilities.BackupBackend
}

type BackupRequest

type BackupRequest struct {
	// Compression is the compression configuration.
	Compression

	// ID is the backup ID
	ID string
	// Backend specify on which backend to store backups (gcs, s3, ..)
	Backend string

	// Include is list of class which need to be backed up
	// The same class cannot appear in both Include and Exclude in the same request
	Include []string
	// Exclude means include all classes but those specified in Exclude
	// The same class cannot appear in both Include and Exclude in the same request
	Exclude []string

	// NodeMapping is a map of node name replacement where key is the old name and value is the new name
	// No effect if the map is empty
	NodeMapping map[string]string

	// Override bucket (optional) - replaces environement variable for one call
	Bucket string

	// Override path (optional) - replaces environement variable for one call
	Path string

	RbacRestoreOption string
	UserRestoreOption string
}

BackupRequest a transition request from API to Backend.

type CanCommitResponse

type CanCommitResponse struct {
	// Method is the backup operation (create, restore)
	Method Op
	// ID is the backup ID
	ID string
	// Timeout for how long the promise might be hold
	Timeout time.Duration
	// Err error
	Err string
}

type Compression added in v1.24.0

type Compression struct {
	// Level is one of DefaultCompression, BestSpeed, BestCompression
	Level CompressionLevel

	// ChunkSize represents the desired size for chunks between 1 - 512  MB
	// However, during compression, the chunk size might
	// slightly deviate from this value, being either slightly
	// below or above the specified size
	ChunkSize int

	// CPUPercentage desired CPU core utilization (1%-80%), default: 50%
	CPUPercentage int
}

Compression is the compression configuration.

type CompressionLevel added in v1.21.0

type CompressionLevel int

CompressionLevel represents supported compression level

const (
	DefaultCompression CompressionLevel = iota
	BestSpeed
	BestCompression
)

type Handler added in v1.21.0

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

func NewHandler added in v1.21.0

func NewHandler(
	logger logrus.FieldLogger,
	authorizer authorization.Authorizer,
	schema schemaManger,
	sourcer Sourcer,
	backends BackupBackendProvider,
	rbacSourcer fsm.Snapshotter,
	dynUserSourcer fsm.Snapshotter,
) *Handler

func (*Handler) OnAbort added in v1.21.0

func (m *Handler) OnAbort(ctx context.Context, req *AbortRequest) error

OnAbort will be triggered when the coordinator abort the execution of a previous operation

func (*Handler) OnCanCommit added in v1.21.0

func (m *Handler) OnCanCommit(ctx context.Context, req *Request) *CanCommitResponse

OnCanCommit will be triggered when coordinator asks the node to participate in a distributed backup operation

func (*Handler) OnCommit added in v1.21.0

func (m *Handler) OnCommit(ctx context.Context, req *StatusRequest) (err error)

OnCommit will be triggered when the coordinator confirms the execution of a previous operation

func (*Handler) OnStatus added in v1.21.0

func (m *Handler) OnStatus(ctx context.Context, req *StatusRequest) *StatusResponse

type MockBackupBackendProvider added in v1.28.13

type MockBackupBackendProvider struct {
	mock.Mock
}

MockBackupBackendProvider is an autogenerated mock type for the BackupBackendProvider type

func NewMockBackupBackendProvider added in v1.28.13

func NewMockBackupBackendProvider(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockBackupBackendProvider

NewMockBackupBackendProvider creates a new instance of MockBackupBackendProvider. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockBackupBackendProvider) BackupBackend added in v1.28.13

BackupBackend provides a mock function with given fields: backend

func (*MockBackupBackendProvider) EXPECT added in v1.28.13

func (*MockBackupBackendProvider) EnabledBackupBackends added in v1.28.13

func (_m *MockBackupBackendProvider) EnabledBackupBackends() []modulecapabilities.BackupBackend

EnabledBackupBackends provides a mock function with no fields

type MockBackupBackendProvider_BackupBackend_Call added in v1.28.13

type MockBackupBackendProvider_BackupBackend_Call struct {
	*mock.Call
}

MockBackupBackendProvider_BackupBackend_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'BackupBackend'

func (*MockBackupBackendProvider_BackupBackend_Call) Return added in v1.28.13

func (*MockBackupBackendProvider_BackupBackend_Call) Run added in v1.28.13

func (*MockBackupBackendProvider_BackupBackend_Call) RunAndReturn added in v1.28.13

type MockBackupBackendProvider_EnabledBackupBackends_Call added in v1.28.13

type MockBackupBackendProvider_EnabledBackupBackends_Call struct {
	*mock.Call
}

MockBackupBackendProvider_EnabledBackupBackends_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'EnabledBackupBackends'

func (*MockBackupBackendProvider_EnabledBackupBackends_Call) Return added in v1.28.13

func (*MockBackupBackendProvider_EnabledBackupBackends_Call) Run added in v1.28.13

func (*MockBackupBackendProvider_EnabledBackupBackends_Call) RunAndReturn added in v1.28.13

type MockBackupBackendProvider_Expecter added in v1.28.13

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

func (*MockBackupBackendProvider_Expecter) BackupBackend added in v1.28.13

BackupBackend is a helper method to define mock.On call

  • backend string

func (*MockBackupBackendProvider_Expecter) EnabledBackupBackends added in v1.28.13

EnabledBackupBackends is a helper method to define mock.On call

type MockNodeResolver added in v1.28.13

type MockNodeResolver struct {
	mock.Mock
}

MockNodeResolver is an autogenerated mock type for the NodeResolver type

func NewMockNodeResolver added in v1.28.13

func NewMockNodeResolver(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockNodeResolver

NewMockNodeResolver creates a new instance of MockNodeResolver. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockNodeResolver) AllNames added in v1.28.13

func (_m *MockNodeResolver) AllNames() []string

AllNames provides a mock function with no fields

func (*MockNodeResolver) EXPECT added in v1.28.13

func (*MockNodeResolver) LeaderID added in v1.28.13

func (_m *MockNodeResolver) LeaderID() string

LeaderID provides a mock function with no fields

func (*MockNodeResolver) NodeCount added in v1.28.13

func (_m *MockNodeResolver) NodeCount() int

NodeCount provides a mock function with no fields

func (*MockNodeResolver) NodeHostname added in v1.28.13

func (_m *MockNodeResolver) NodeHostname(nodeName string) (string, bool)

NodeHostname provides a mock function with given fields: nodeName

type MockNodeResolver_AllNames_Call added in v1.28.13

type MockNodeResolver_AllNames_Call struct {
	*mock.Call
}

MockNodeResolver_AllNames_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllNames'

func (*MockNodeResolver_AllNames_Call) Return added in v1.28.13

func (*MockNodeResolver_AllNames_Call) Run added in v1.28.13

func (*MockNodeResolver_AllNames_Call) RunAndReturn added in v1.28.13

type MockNodeResolver_Expecter added in v1.28.13

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

func (*MockNodeResolver_Expecter) AllNames added in v1.28.13

AllNames is a helper method to define mock.On call

func (*MockNodeResolver_Expecter) LeaderID added in v1.28.13

LeaderID is a helper method to define mock.On call

func (*MockNodeResolver_Expecter) NodeCount added in v1.28.13

NodeCount is a helper method to define mock.On call

func (*MockNodeResolver_Expecter) NodeHostname added in v1.28.13

func (_e *MockNodeResolver_Expecter) NodeHostname(nodeName interface{}) *MockNodeResolver_NodeHostname_Call

NodeHostname is a helper method to define mock.On call

  • nodeName string

type MockNodeResolver_LeaderID_Call added in v1.28.13

type MockNodeResolver_LeaderID_Call struct {
	*mock.Call
}

MockNodeResolver_LeaderID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LeaderID'

func (*MockNodeResolver_LeaderID_Call) Return added in v1.28.13

func (*MockNodeResolver_LeaderID_Call) Run added in v1.28.13

func (*MockNodeResolver_LeaderID_Call) RunAndReturn added in v1.28.13

type MockNodeResolver_NodeCount_Call added in v1.28.13

type MockNodeResolver_NodeCount_Call struct {
	*mock.Call
}

MockNodeResolver_NodeCount_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'NodeCount'

func (*MockNodeResolver_NodeCount_Call) Return added in v1.28.13

func (*MockNodeResolver_NodeCount_Call) Run added in v1.28.13

func (*MockNodeResolver_NodeCount_Call) RunAndReturn added in v1.28.13

type MockNodeResolver_NodeHostname_Call added in v1.28.13

type MockNodeResolver_NodeHostname_Call struct {
	*mock.Call
}

MockNodeResolver_NodeHostname_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'NodeHostname'

func (*MockNodeResolver_NodeHostname_Call) Return added in v1.28.13

func (*MockNodeResolver_NodeHostname_Call) Run added in v1.28.13

func (*MockNodeResolver_NodeHostname_Call) RunAndReturn added in v1.28.13

type MockSelector added in v1.28.13

type MockSelector struct {
	mock.Mock
}

MockSelector is an autogenerated mock type for the Selector type

func NewMockSelector added in v1.28.13

func NewMockSelector(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockSelector

NewMockSelector creates a new instance of MockSelector. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockSelector) Backupable added in v1.28.13

func (_m *MockSelector) Backupable(_a0 context.Context, classes []string) error

Backupable provides a mock function with given fields: _a0, classes

func (*MockSelector) EXPECT added in v1.28.13

func (_m *MockSelector) EXPECT() *MockSelector_Expecter

func (*MockSelector) ListClasses added in v1.28.13

func (_m *MockSelector) ListClasses(ctx context.Context) []string

ListClasses provides a mock function with given fields: ctx

func (*MockSelector) Shards added in v1.28.13

func (_m *MockSelector) Shards(ctx context.Context, class string) ([]string, error)

Shards provides a mock function with given fields: ctx, class

type MockSelector_Backupable_Call added in v1.28.13

type MockSelector_Backupable_Call struct {
	*mock.Call
}

MockSelector_Backupable_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Backupable'

func (*MockSelector_Backupable_Call) Return added in v1.28.13

func (*MockSelector_Backupable_Call) Run added in v1.28.13

func (*MockSelector_Backupable_Call) RunAndReturn added in v1.28.13

type MockSelector_Expecter added in v1.28.13

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

func (*MockSelector_Expecter) Backupable added in v1.28.13

func (_e *MockSelector_Expecter) Backupable(_a0 interface{}, classes interface{}) *MockSelector_Backupable_Call

Backupable is a helper method to define mock.On call

  • _a0 context.Context
  • classes []string

func (*MockSelector_Expecter) ListClasses added in v1.28.13

func (_e *MockSelector_Expecter) ListClasses(ctx interface{}) *MockSelector_ListClasses_Call

ListClasses is a helper method to define mock.On call

  • ctx context.Context

func (*MockSelector_Expecter) Shards added in v1.28.13

func (_e *MockSelector_Expecter) Shards(ctx interface{}, class interface{}) *MockSelector_Shards_Call

Shards is a helper method to define mock.On call

  • ctx context.Context
  • class string

type MockSelector_ListClasses_Call added in v1.28.13

type MockSelector_ListClasses_Call struct {
	*mock.Call
}

MockSelector_ListClasses_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListClasses'

func (*MockSelector_ListClasses_Call) Return added in v1.28.13

func (*MockSelector_ListClasses_Call) Run added in v1.28.13

func (*MockSelector_ListClasses_Call) RunAndReturn added in v1.28.13

type MockSelector_Shards_Call added in v1.28.13

type MockSelector_Shards_Call struct {
	*mock.Call
}

MockSelector_Shards_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Shards'

func (*MockSelector_Shards_Call) Return added in v1.28.13

func (*MockSelector_Shards_Call) Run added in v1.28.13

func (*MockSelector_Shards_Call) RunAndReturn added in v1.28.13

type NodeResolver added in v1.28.0

type NodeResolver interface {
	NodeHostname(nodeName string) (string, bool)
	AllNames() []string
	NodeCount() int

	// LeaderID is used to return the current leader ID
	// It may return empty strings if there is no current leader or the leader is unknown.
	LeaderID() string
}

type Op

type Op string

Op is the kind of a backup operation

const (
	OpCreate  Op = "create"
	OpRestore Op = "restore"
)

type Request

type Request struct {
	// Method is the backup operation (create, restore)
	Method Op
	// ID is the backup ID
	ID string
	// Backend specify on which backend to store backups (gcs, s3, ..)
	Backend string

	// NodeMapping specify node names replacement to be made on restore
	NodeMapping map[string]string

	// Classes is list of class which need to be backed up
	Classes []string

	// Duration
	Duration time.Duration

	// Compression is the compression configuration.
	Compression

	// Override bucket
	Bucket string

	// Additional path prefix override
	Path string

	RbacRestoreOption string
	UserRestoreOption string
}

type Scheduler

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

Scheduler assigns backup operations to coordinators.

func NewScheduler

func NewScheduler(
	authorizer authorization.Authorizer,
	client client,
	sourcer Selector,
	backends BackupBackendProvider,
	nodeResolver NodeResolver,
	schema schemaManger,
	logger logrus.FieldLogger,
) *Scheduler

NewScheduler creates a new scheduler with two coordinators

func (*Scheduler) Backup

func (s *Scheduler) Backup(ctx context.Context, pr *models.Principal, req *BackupRequest,
) (_ *models.BackupCreateResponse, err error)

func (*Scheduler) BackupStatus

func (s *Scheduler) BackupStatus(ctx context.Context, principal *models.Principal,
	backend, backupID, overrideBucket, overridePath string,
) (_ *Status, err error)

func (*Scheduler) Cancel added in v1.24.25

func (s *Scheduler) Cancel(ctx context.Context, principal *models.Principal, backend, backupID, overrideBucket, overridePath string,
) error

func (*Scheduler) CleanupUnfinishedBackups added in v1.27.4

func (s *Scheduler) CleanupUnfinishedBackups(ctx context.Context)

func (*Scheduler) List added in v1.24.25

func (s *Scheduler) List(ctx context.Context, principal *models.Principal, backend string) (*models.BackupListResponse, error)

func (*Scheduler) RestorationStatus

func (s *Scheduler) RestorationStatus(ctx context.Context, principal *models.Principal, backend, backupID, overrideBucket, overridePath string,
) (_ *Status, err error)

func (*Scheduler) Restore

func (s *Scheduler) Restore(ctx context.Context, pr *models.Principal,
	req *BackupRequest,
) (_ *models.BackupRestoreResponse, err error)

Restore loads the backup and restores classes in temporary directories on the filesystem. The final backup restoration is orchestrated by the raft store.

type Selector added in v1.28.0

type Selector interface {
	// Shards gets all nodes on which this class is sharded
	Shards(ctx context.Context, class string) ([]string, error)
	// ListClasses returns a list of all existing classes
	// This will be needed if user doesn't include any classes
	ListClasses(ctx context.Context) []string

	// Backupable returns whether all given class can be backed up.
	Backupable(_ context.Context, classes []string) error
}

Selector is used to select participant nodes

type Sourcer

type Sourcer interface {
	// ReleaseBackup signals to the underlying index that the files have been
	// copied (or the operation aborted), and that it is safe for the index to
	// change the files, such as start compactions.
	ReleaseBackup(_ context.Context, id, class string) error

	// Backupable returns whether all given class can be backed up.
	Backupable(_ context.Context, classes []string) error

	// BackupDescriptors returns a channel of class descriptors.
	// Class descriptor records everything needed to restore a class
	// If an error happens a descriptor with an error will be written to the channel just before closing it.
	//
	// BackupDescriptors acquires resources so that a call to ReleaseBackup() is mandatory to free acquired resources.
	BackupDescriptors(_ context.Context, bakid string, classes []string,
	) <-chan backup.ClassDescriptor

	// ClassExists checks whether a class exits or not
	ClassExists(name string) bool
}

Sourcer represents the source of artifacts used in the backup

type Status

type Status struct {
	Path        string
	StartedAt   time.Time
	CompletedAt time.Time
	Status      backup.Status
	Err         string
}

type StatusRequest

type StatusRequest struct {
	// Method is the backup operation (create, restore)
	Method Op
	// ID is the backup ID
	ID string
	// Backend specify on which backend to store backups (gcs, s3, ..)
	Backend string
	// Bucket specify the bucket name
	Bucket string
	// Path specify the path
	Path string
}

type StatusResponse

type StatusResponse struct {
	// Method is the backup operation (create, restore)
	Method Op
	ID     string
	Status backup.Status
	Err    string
}

Jump to

Keyboard shortcuts

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