storage

package
v0.0.0-...-1b4be3e Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const LastSuccessfulBackupFile = "last_successful_backup"

LastSuccessfulBackupFile name of meta file that contains the information of the last successful backup

Variables

This section is empty.

Functions

func FolderSize

func FolderSize(path string) (size int64, err error)

FolderSize calcs a folders size

func ZipFolderPath

func ZipFolderPath(pathToZip string) (pr *io.PipeReader, err error)

ZipFolderPath zips a folder

Types

type Backup

type Backup struct {
	Storage       string
	Time          time.Time
	Key           string
	IncList       []IncBackup
	VerifySuccess *Verify
	VerifyFail    *Verify
}

Backup storage struct

type BinlogEvent

type BinlogEvent struct {
	Value *replication.BinlogEvent
}

BinlogEvent holds a binlog event

func (*BinlogEvent) ToByte

func (b *BinlogEvent) ToByte() []byte

ToByte returns the byte content of a binlog event

type ByTime

type ByTime []Backup

ByTime implements the sort of a backup slice by time

func (ByTime) Len

func (b ByTime) Len() int

func (ByTime) Less

func (b ByTime) Less(i, j int) bool

func (ByTime) Swap

func (b ByTime) Swap(i, j int)

type ByteEvent

type ByteEvent struct {
	Value []byte
}

ByteEvent holds a slice of bytes

func (*ByteEvent) ToByte

func (b *ByteEvent) ToByte() []byte

ToByte returns the bytes of the event

type ChannelWriter

type ChannelWriter interface {
	// WriteChannel writes the contents of the channel to the storage
	WriteChannel(name, mimeType string, body <-chan StreamEvent, tags map[string]string, dlo bool) (err error)
}

ChannelWriter for storages that do not support consuming io.Reader

type Disk

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

Disk struct is ...

func NewDisk

func NewDisk(cfg config.Disk, serviceName string, binLog string) (d *Disk, err error)

NewDisk creates a new disk storage object

func (*Disk) DownloadBackup

func (d *Disk) DownloadBackup(fullBackup Backup) (path string, err error)

DownloadBackup implements interface

func (*Disk) DownloadBackupWithLogPosition

func (d *Disk) DownloadBackupWithLogPosition(fullBackupPath string, binlog string) (path string, err error)

DownloadBackupWithLogPosition implements interface

func (*Disk) DownloadLatestBackup

func (d *Disk) DownloadLatestBackup() (path string, err error)

DownloadLatestBackup implements interface

func (*Disk) GetFullBackups

func (d *Disk) GetFullBackups() (bl []Backup, err error)

GetFullBackups implements interface

Walks the backup basepath and list all full backups. Only backups which contain a dump.tar are listed

func (*Disk) GetIncBackupsFromDump

func (d *Disk) GetIncBackupsFromDump(key string) (bl []Backup, err error)

GetIncBackupsFromDump implements interface

func (*Disk) GetStatusError

func (d *Disk) GetStatusError() map[string]string

GetStatusError implements interface

func (*Disk) GetStatusErrorByKey

func (d *Disk) GetStatusErrorByKey(backupKey string) string

GetStatusErrorByKey implements interface

func (*Disk) GetStorageServiceName

func (d *Disk) GetStorageServiceName() (name string)

GetStorageServiceName implements interface

func (*Disk) GetTotalIncBackupsFromDump

func (d *Disk) GetTotalIncBackupsFromDump(key string) (t int, err error)

GetTotalIncBackupsFromDump implements interface

func (*Disk) Verify

func (d *Disk) Verify() bool

Verify implements interface

func (*Disk) WriteFolder

func (d *Disk) WriteFolder(p string) (err error)

WriteFolder implements interface

func (*Disk) WriteStream

func (d *Disk) WriteStream(fileName, mimeType string, body io.Reader, tags map[string]string, dlo bool) error

WriteStream implements interface.

Writes a file in the base directory defined in the config. If the fileName is `last_successful_backup` only the tags are written to the file but not its actual content In all other cases the tags are ignored and the body is written to the file

type Error

type Error struct {
	Storage string
	// contains filtered or unexported fields
}

Error with storage name and error message

func (*Error) Error

func (s *Error) Error() string

type IOClosers

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

IOClosers holds all io closers

func NewIOClosers

func NewIOClosers(closers []io.Closer) *IOClosers

NewIOClosers creates a list of io closers

func (*IOClosers) Close

func (m *IOClosers) Close() (err error)

Close closes all io closers

type IncBackup

type IncBackup struct {
	Key          string
	LastModified time.Time
}

IncBackup storage struct

type Manager

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

Manager which manages the different storage services

func NewManager

func NewManager(c config.StorageService, serviceName, restoreFolder, binLog string) (m *Manager, err error)

NewManager creates a new manager instance

func (*Manager) AddStorage

func (m *Manager) AddStorage(s Storage)

AddStorage can add a specific storage service

func (*Manager) DownloadBackup

func (m *Manager) DownloadBackup(storageService string, fullBackup Backup) (path string, err error)

DownloadBackup from a specific storage

func (*Manager) DownloadBackupWithLogPosition

func (m *Manager) DownloadBackupWithLogPosition(storageService, fullBackupPath string, binlog string) (path string, err error)

DownloadBackupWithLogPosition from a specific storage and timestamp

func (*Manager) DownloadLatestBackup

func (m *Manager) DownloadLatestBackup(storageService string) (path string, err error)

DownloadLatestBackup from a specific storage

func (*Manager) GetFullBackups

func (m *Manager) GetFullBackups(storageService string) (bl []Backup, err error)

GetFullBackups lists all available full backups from a specific storage

func (*Manager) GetIncBackupsFromDump

func (m *Manager) GetIncBackupsFromDump(storageService, key string) (bl []Backup, err error)

GetIncBackupsFromDump lists all available incremental backups belonging to the full backup from a specific storage

func (*Manager) GetStorage

func (m *Manager) GetStorage(s string) Storage

GetStorage returns a specific storage service

func (*Manager) GetStorageServices

func (m *Manager) GetStorageServices() map[string]Storage

GetStorageServices returns all storage services handled by this manager

func (*Manager) GetStorageServicesKeys

func (m *Manager) GetStorageServicesKeys() (svc []string)

GetStorageServicesKeys returns a list of all storage names

func (*Manager) WriteFolderAll

func (m *Manager) WriteFolderAll(path string) (errs error)

WriteFolderAll writes a folder to all storages

func (*Manager) WriteStream

func (m *Manager) WriteStream(storageService, name, mimeType string, body io.Reader, tags map[string]string, dlo bool) (errs error)

WriteStream writes a byte stream to a specific storage service

func (*Manager) WriteStreamAll

func (m *Manager) WriteStreamAll(name, mimeType string, body <-chan StreamEvent, dlo bool) (errs error)

WriteStreamAll writes Events either as a byte stream or in channel to all available storage services

type MariaDBStream

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

MariaDBStream struct is ...

func NewMariaDBStream

func NewMariaDBStream(c config.MariaDBStream, serviceName string) (m *MariaDBStream, err error)

NewMariaDBStream creates a new mariadbstream storage object

func (*MariaDBStream) DownloadBackup

func (m *MariaDBStream) DownloadBackup(fullBackup Backup) (path string, err error)

DownloadBackup implements interface

func (*MariaDBStream) DownloadBackupWithLogPosition

func (m *MariaDBStream) DownloadBackupWithLogPosition(fullBackupPath string, binlog string) (path string, err error)

DownloadBackupWithLogPosition implements interface

func (*MariaDBStream) DownloadLatestBackup

func (m *MariaDBStream) DownloadLatestBackup() (path string, err error)

DownloadLatestBackup implements interface

func (*MariaDBStream) GetFullBackups

func (m *MariaDBStream) GetFullBackups() (bl []Backup, err error)

GetFullBackups implements interface

func (*MariaDBStream) GetIncBackupsFromDump

func (m *MariaDBStream) GetIncBackupsFromDump(key string) (bl []Backup, err error)

GetIncBackupsFromDump implements interface

func (*MariaDBStream) GetStatusError

func (m *MariaDBStream) GetStatusError() map[string]string

GetStatusError implements interface

func (*MariaDBStream) GetStatusErrorByKey

func (m *MariaDBStream) GetStatusErrorByKey(backupKey string) string

GetStatusErrorByKey implements interface

func (*MariaDBStream) GetStorageServiceName

func (m *MariaDBStream) GetStorageServiceName() (name string)

GetStorageServiceName implements interface

func (*MariaDBStream) GetTotalIncBackupsFromDump

func (m *MariaDBStream) GetTotalIncBackupsFromDump(key string) (t int, err error)

GetTotalIncBackupsFromDump implements interface

func (*MariaDBStream) ProcessBinlogEvent

func (m *MariaDBStream) ProcessBinlogEvent(ctx context.Context, event *replication.BinlogEvent) (err error)

ProcessBinlogEvent processes the QueryEvents - Events other than QueryEvent or RowsEvents are ignored - Only replicates all schemas or those set in the config - If schemas are filtered and the schema is set the event will be ignored

func (*MariaDBStream) Verify

func (m *MariaDBStream) Verify() bool

Verify implements interface

func (*MariaDBStream) WriteChannel

func (m *MariaDBStream) WriteChannel(name, mimeType string, body <-chan StreamEvent, tags map[string]string, dlo bool) (err error)

WriteChannel implements interface

func (*MariaDBStream) WriteFolder

func (m *MariaDBStream) WriteFolder(p string) (err error)

WriteFolder implements interface

func (*MariaDBStream) WriteStream

func (m *MariaDBStream) WriteStream(fileName, mimeType string, body io.Reader, tags map[string]string, dlo bool) error

WriteStream implements interface

type MockStorage

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

MockStorage struct for testing

func NewMockStorage

func NewMockStorage(c config.Config, serviceName, restoreFolder, binLog string) (m *MockStorage)

NewMockStorage creates a mock storage instance

func (*MockStorage) DownloadBackup

func (s *MockStorage) DownloadBackup(fullBackup Backup) (path string, err error)

DownloadBackup implements interface

func (*MockStorage) DownloadBackupWithLogPosition

func (s *MockStorage) DownloadBackupWithLogPosition(fullBackupPath string, binlog string) (path string, err error)

DownloadBackupWithLogPosition implements interface

func (*MockStorage) DownloadLatestBackup

func (s *MockStorage) DownloadLatestBackup() (path string, err error)

DownloadLatestBackup implements interface

func (*MockStorage) GetFullBackups

func (s *MockStorage) GetFullBackups() (bl []Backup, err error)

GetFullBackups implements interface

func (*MockStorage) GetIncBackupsFromDump

func (s *MockStorage) GetIncBackupsFromDump(key string) (bl []Backup, err error)

GetIncBackupsFromDump implements interface

func (*MockStorage) GetStatusError

func (s *MockStorage) GetStatusError() (m map[string]string)

GetStatusError implements interface

func (*MockStorage) GetStatusErrorByKey

func (s *MockStorage) GetStatusErrorByKey(backupKey string) string

GetStatusErrorByKey implements interface

func (*MockStorage) GetStorageServiceName

func (s *MockStorage) GetStorageServiceName() (name string)

GetStorageServiceName implements interface

func (*MockStorage) GetTotalIncBackupsFromDump

func (s *MockStorage) GetTotalIncBackupsFromDump(key string) (t int, err error)

GetTotalIncBackupsFromDump implements interface

func (*MockStorage) Verify

func (s *MockStorage) Verify() bool

Verify implements interface

func (*MockStorage) WithError

func (s *MockStorage) WithError(e bool)

WithError implements interface

func (*MockStorage) WriteFolder

func (s *MockStorage) WriteFolder(p string) (err error)

WriteFolder implements interface

func (*MockStorage) WriteStream

func (s *MockStorage) WriteStream(name, mimeType string, body io.Reader, tags map[string]string, dlo bool) (err error)

WriteStream implements interface

type NoBackupError

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

NoBackupError error when no backups are stored

func (*NoBackupError) Error

func (d *NoBackupError) Error() string

type S3

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

S3 struct is ...

func NewS3

func NewS3(c config.S3, serviceName, restoreFolder, binLog string) (s3 *S3, err error)

NewS3 creates a s3 storage instance

func (*S3) DownloadBackup

func (s *S3) DownloadBackup(fullBackup Backup) (path string, err error)

DownloadBackup implements interface

func (*S3) DownloadBackupWithLogPosition

func (s *S3) DownloadBackupWithLogPosition(fullBackupPath, binlog string) (path string, err error)

DownloadBackupWithLogPosition implements interface

func (*S3) DownloadLatestBackup

func (s *S3) DownloadLatestBackup() (path string, err error)

DownloadLatestBackup implements interface

func (*S3) GetFullBackups

func (s *S3) GetFullBackups() (bl []Backup, err error)

GetFullBackups implements interface

func (*S3) GetIncBackupsFromDump

func (s *S3) GetIncBackupsFromDump(key string) (bl []Backup, err error)

GetIncBackupsFromDump implements interface

func (*S3) GetStatusError

func (s *S3) GetStatusError() map[string]string

GetStatusError implements interface

func (*S3) GetStatusErrorByKey

func (s *S3) GetStatusErrorByKey(backupKey string) string

GetStatusErrorByKey implements interface

func (*S3) GetStorageServiceName

func (s *S3) GetStorageServiceName() (name string)

GetStorageServiceName implements interface

func (*S3) GetTotalIncBackupsFromDump

func (s *S3) GetTotalIncBackupsFromDump(key string) (t int, err error)

GetTotalIncBackupsFromDump implements interface

func (*S3) Verify

func (s *S3) Verify() bool

Verify implements interface

func (*S3) WriteFolder

func (s *S3) WriteFolder(p string) (err error)

WriteFolder implements interface

func (*S3) WriteStream

func (s *S3) WriteStream(fileName, mimeType string, body io.Reader, tags map[string]string, dlo bool) error

WriteStream implements interface

type Storage

type Storage interface {
	// WriteFolder writes a folder to the storage
	WriteFolder(p string) (err error)
	// WriteStream writes a byte stream to the storage
	WriteStream(name, mimeType string, body io.Reader, tags map[string]string, dlo bool) (err error)
	// DownloadLatestBackup downloads the latest available backup from a storage
	DownloadLatestBackup() (path string, err error)
	// GetFullBackups lists all available full backups per storage
	GetFullBackups() (bl []Backup, err error)
	// GetIncBackupsFromDump lists all available incremental backups that belong to a full backup from a storage
	GetIncBackupsFromDump(key string) (bl []Backup, err error)
	// DownloadBackupWithLogPosition downloads a specific backup until given binlog position from a storage
	DownloadBackupWithLogPosition(fullBackupPath string, binlog string) (path string, err error)
	// DownloadBackup downloads a specific backup from a storage
	DownloadBackup(b Backup) (path string, err error)
	// GetStorageServiceName lists all available storages from a service
	GetStorageServiceName() (name string)
	// GetStatusError gets the backup->error map
	GetStatusError() map[string]string
	// GetStatusErrorByKey returns error per backup
	GetStatusErrorByKey(backupKey string) string
	// GetTotalIncBackupsFromDump returns current total incremental backups in this dump
	GetTotalIncBackupsFromDump(key string) (t int, err error)
	// check if verify should be run with this Storage
	Verify() bool
}

Storage interface

type StreamEvent

type StreamEvent interface {
	ToByte() []byte
}

StreamEvent used to send byte slices or binlog events to the storages

type Swift

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

Swift struct is ...

func NewSwift

func NewSwift(c config.Swift, serviceName, restoreFolder, logBin string) (s *Swift, err error)

NewSwift creates a swift storage instance

func (*Swift) DownloadBackup

func (s *Swift) DownloadBackup(fullBackup Backup) (path string, err error)

DownloadBackup implements interface

func (*Swift) DownloadBackupWithLogPosition

func (s *Swift) DownloadBackupWithLogPosition(fullBackupPath string, binlog string) (path string, err error)

DownloadBackupWithLogPosition implements interface

func (*Swift) DownloadLatestBackup

func (s *Swift) DownloadLatestBackup() (path string, err error)

DownloadLatestBackup implements interface

func (*Swift) GetFullBackups

func (s *Swift) GetFullBackups() (b []Backup, err error)

GetFullBackups implements interface

func (*Swift) GetIncBackupsFromDump

func (s *Swift) GetIncBackupsFromDump(key string) (bl []Backup, err error)

GetIncBackupsFromDump implements interface

func (*Swift) GetStatusError

func (s *Swift) GetStatusError() map[string]string

GetStatusError implements interface

func (*Swift) GetStatusErrorByKey

func (s *Swift) GetStatusErrorByKey(backupKey string) string

GetStatusErrorByKey implements interface

func (*Swift) GetStorageServiceName

func (s *Swift) GetStorageServiceName() (storages string)

GetStorageServiceName implements interface

func (*Swift) GetTotalIncBackupsFromDump

func (s *Swift) GetTotalIncBackupsFromDump(key string) (t int, err error)

GetTotalIncBackupsFromDump implements interface

func (*Swift) Verify

func (s *Swift) Verify() bool

Verify implements interface

func (*Swift) WriteFolder

func (s *Swift) WriteFolder(p string) (err error)

WriteFolder implements interface

func (*Swift) WriteStream

func (s *Swift) WriteStream(name, mimeType string, body io.Reader, tags map[string]string, dlo bool) (err error)

WriteStream implements interface

type Verify

type Verify struct {
	VerifyRestore  int    `yaml:"verify_backup"`
	VerifyChecksum int    `yaml:"verify_checksum"`
	VerifyDiff     int    `yaml:"verify_diff"`
	VerifyError    string `yaml:"verify_error"`
	Time           time.Time
}

Verify storage struct

Jump to

Keyboard shortcuts

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