backupapi

package
v1.0.24 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2023 License: GPL-3.0 Imports: 42 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ChunkUploadLowerBound  = chunker.MaxSize
	IntervalTimeRetryChunk = 30 * time.Second
	MaxTimesRetryChunk     = 3
)
View Source
const (
	RecoveryPointTypePoint          = "RECOVERY_POINT"
	RecoveryPointTypeInitialReplica = "INITIAL_REPLICA"

	RecoveryPointStatusCreated   = "CREATED"
	RecoveryPointStatusCompleted = "COMPLETED"
	RecoveryPointStatusFAILED    = "FAILED"
)

Variables

View Source
var ErrUpdateRecoveryPoint = errors.New("failed to update recovery point")

ErrUpdateRecoveryPoint indicates that there is error from server when updating recovery point.

View Source
var (
	ErrorGotCancelRequest = errors.New("got cancel request")
)

Functions

func CustomLevelEncoder added in v1.0.0

func CustomLevelEncoder(level zapcore.Level, enc zapcore.PrimitiveArrayEncoder)

func SyslogTimeEncoder added in v1.0.0

func SyslogTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)

func WithHTTPClient

func WithHTTPClient(client *http.Client) func(*Client) error

WithHTTPClient sets the underlying HTTP client for Client.

func WriteLog added in v1.0.0

func WriteLog() (*zap.Logger, error)

Write log to file

Types

type Activity added in v1.0.18

type Activity struct {
	ID                string        `json:"id"`
	Action            string        `json:"action"`
	Status            string        `json:"status"`
	Message           string        `json:"message"`
	BackupDirectoryID string        `json:"backup_directory_id"`
	PolicyID          string        `json:"policy_id"`
	Progress          string        `json:"progress_restore"`
	RecoveryPoint     RecoveryPoint `json:"recovery_point"`
	MachineID         string        `json:"machine_id"`
	CreatedAt         string        `json:"created_at"`
	UpdatedAt         string        `json:"updated_at"`
}

Activity ...

type AuthRestore added in v1.0.0

type AuthRestore struct {
	RecoveryPointID   string
	ActionID          string
	CreatedAt         string
	RestoreSessionKey string
}

type BackupDirectory

type BackupDirectory struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
	Path        string `json:"path"`
	Quota       int    `json:"quota"`
	Size        int    `json:"size"`
	MachineID   string `json:"machine_id"`
	TenantID    string `json:"tenant_id"`
}

BackupDirectory ...

type BackupDirectoryConfig

type BackupDirectoryConfig struct {
	ID        string                        `json:"id" yaml:"id"`
	Name      string                        `json:"name" yaml:"name"`
	Path      string                        `json:"path" yaml:"path"`
	Policies  []BackupDirectoryConfigPolicy `json:"policies" yaml:"policies"`
	Activated bool                          `json:"activated" yaml:"activated"`
}

BackupDirectoryConfig is the cron policies for given directory.

type BackupDirectoryConfigPolicy

type BackupDirectoryConfigPolicy struct {
	ID              string `json:"id" yaml:"id"`
	Name            string `json:"name" yaml:"name"`
	SchedulePattern string `json:"schedule_pattern" yaml:"schedule_pattern"`
	Retentions      string `json:"retentions" yaml:"retentions"`
	LimitUpload     int    `json:"limit_upload" yaml:"limit_upload"`
}

BackupDirectoryConfigPolicy is the cron policy.

type Client

type Client struct {
	ServerURL *url.URL
	Id        string
	// contains filtered or unexported fields
}

Client is the client for interacting with BackupService API server.

func NewClient

func NewClient(opts ...ClientOption) (*Client, error)

NewClient creates a Client with given options.

func (*Client) ChunkFileToBackup added in v1.0.0

func (c *Client) ChunkFileToBackup(ctx context.Context, pool *ants.Pool, itemInfo *cache.Node, cacheWriter *cache.Repository,
	storageVault storage_vault.StorageVault, p *progress.Progress, pipe chan<- *cache.Chunk, rpID, bdID string) (uint64, error)

func (*Client) CreateRecoveryPoint

func (c *Client) CreateRecoveryPoint(ctx context.Context, backupDirectoryID string, crpr *CreateRecoveryPointRequest) (*CreateRecoveryPointResponse, error)

func (*Client) DeleteRecoveryPoints added in v1.0.20

func (c *Client) DeleteRecoveryPoints(ctx context.Context, recoveryPointID string) error

DeleteRecoveryPoints delete a recovery points.

func (*Client) Do

func (c *Client) Do(req *http.Request) (*http.Response, error)

Do makes an http request.

func (*Client) GetBackupDirectory

func (c *Client) GetBackupDirectory(id string) (*BackupDirectory, error)

GetBackupDirectory retrieves a backup directory by given id.

func (*Client) GetConfig

func (c *Client) GetConfig(ctx context.Context) (*Config, error)

func (*Client) GetCredentialStorageVault added in v1.0.0

func (c *Client) GetCredentialStorageVault(storageVaultID string, actionID string, restoreKey *AuthRestore) (*StorageVault, error)

GetCredentialStorageVault get a new credential with backend credential not constant.

func (*Client) GetLatestRecoveryPointID added in v1.0.0

func (c *Client) GetLatestRecoveryPointID(backupDirectoryID string) (*RecoveryPointResponse, error)

func (*Client) GetObject added in v1.0.0

func (c *Client) GetObject(storageVault storage_vault.StorageVault, key string, restoreKey *AuthRestore) ([]byte, error)

GetObject downloads the object by name in storage vault.

func (*Client) GetRecoveryPointInfo added in v1.0.0

func (c *Client) GetRecoveryPointInfo(recoveryPointID string) (*RecoveryPointResponse, error)

func (*Client) GetRestoreSessionKey added in v1.0.0

func (c *Client) GetRestoreSessionKey(recoveryPointID string, actionID string, createdAt string) (*RestoreResponse, error)

func (*Client) LatestVersion added in v0.0.11

func (c *Client) LatestVersion() (*Version, error)

func (*Client) ListActivity added in v1.0.18

func (c *Client) ListActivity(ctx context.Context, machineID string, statuses []string) (*ListActivity, error)

ListActivity retrieves list activity.

func (*Client) ListBackupDirectory added in v1.0.4

func (c *Client) ListBackupDirectory() (*ListBackupDirectory, error)

ListBackupDirectory retrieves list backup directory.

func (*Client) ListRecoveryPoints

func (c *Client) ListRecoveryPoints(ctx context.Context, backupDirectoryID string) (*ListRecoveryPointsResponse, error)

ListRecoveryPoints list all recovery points of given backup directory.

func (*Client) NewRequest

func (c *Client) NewRequest(method, relPath string, body interface{}) (*http.Request, error)

NewRequest create new http request

func (*Client) OpenFile added in v1.0.21

func (c *Client) OpenFile(ctx context.Context, path string) (io.ReadCloser, error)

func (*Client) PutObject added in v1.0.0

func (c *Client) PutObject(storageVault storage_vault.StorageVault, key string, data []byte) error

PutObject stores the data to the storage vault.

func (*Client) RequestBackupDirectory

func (c *Client) RequestBackupDirectory(id string, cmbr *CreateManualBackupRequest) error

RequestBackupDirectory requests a manual backup.

func (*Client) RequestRestore

func (c *Client) RequestRestore(recoveryPointID string, crr *CreateRestoreRequest) error

RequestRestore requests restore

func (*Client) RestoreDirectory added in v1.0.0

func (c *Client) RestoreDirectory(ctx context.Context, index cache.Index, destDir string, storageVault storage_vault.StorageVault, restoreKey *AuthRestore, p *progress.Progress) error

func (*Client) RestoreItem added in v1.0.0

func (c *Client) RestoreItem(ctx context.Context, destDir string, item cache.Node, storageVault storage_vault.StorageVault, restoreKey *AuthRestore, p *progress.Progress) error

func (*Client) UpdateMachine

func (c *Client) UpdateMachine() (*UpdateMachineResponse, error)

UpdateMachine updates machine information.

func (*Client) UploadFile

func (c *Client) UploadFile(ctx context.Context, pool *ants.Pool, lastInfo *cache.Node, itemInfo *cache.Node, cacheWriter *cache.Repository,
	storageVault storage_vault.StorageVault, p *progress.Progress, pipe chan<- *cache.Chunk, rpID, bdID string) (uint64, error)

type ClientOption

type ClientOption func(c *Client) error

ClientOption provides mechanism to configure Client.

func WithAccessKey

func WithAccessKey(accessKey string) ClientOption

WithAccessKey sets the access key for Client.

func WithID

func WithID(id string) ClientOption

WithMachineID sets the machine id for Client.

func WithNumGoroutine added in v1.0.19

func WithNumGoroutine(num int) ClientOption

WithNumGoroutine sets the secret key for Client.

func WithSecretKey

func WithSecretKey(secretKey string) ClientOption

WithSecretKey sets the secret key for Client.

func WithServerURL

func WithServerURL(serverURL string) ClientOption

WithServerURL sets the server url for Client.

type Config

type Config struct {
	BackupDirectories []BackupDirectoryConfig `json:"backup_directories" yaml:"backup_directories"`
}

type CreateManualBackupRequest

type CreateManualBackupRequest struct {
	Action      string `json:"action"`
	StorageType string `json:"storage_type"`
	Name        string `json:"name"`
}

CreateManualBackupRequest represents a request manual backup.

type CreateRecoveryPointRequest

type CreateRecoveryPointRequest struct {
	PolicyID          string `json:"policy_id"`
	Name              string `json:"name"`
	RecoveryPointType string `json:"recovery_point_type"`
}

CreateRecoveryPointRequest represents a request to create a recovery point.

type CreateRecoveryPointResponse

type CreateRecoveryPointResponse struct {
	ID            string         `json:"id"`
	RecoveryPoint *RecoveryPoint `json:"recovery_point"`
	Action        string         `json:"action"`
	Status        string         `json:"status"`
	StorageVault  *StorageVault  `json:"storage_vault"`
}

CreateRecoveryPointResponse is the server response when creating recovery point

type CreateRestoreRequest

type CreateRestoreRequest struct {
	MachineID string `json:"machine_id"`
	Path      string `json:"path"`
}

CreateRestoreRequest represents a request manual backup.

type Directories added in v1.0.4

type Directories struct {
	ID   string `json:"id"`
	Size int    `json:"size"`
}

Directories ...

type ListActivity added in v1.0.18

type ListActivity struct {
	Activities []Activity `json:"activities"`
}

ListBackupDirectory ...

type ListBackupDirectory added in v1.0.4

type ListBackupDirectory struct {
	Directories []BackupDirectory `json:"directories"`
}

ListBackupDirectory ...

type ListRecoveryPointsResponse added in v1.0.4

type ListRecoveryPointsResponse struct {
	RecoveryPoints []RecoveryPointResponse `json:"recovery_points"`
}

ListRecoveryPointsResponse get a list recovery point of backup directory id

type Machine

type Machine struct {
	ID           string `json:"id"`
	CreatedAt    string `json:"created_at"`
	UpdatedAt    string `json:"updated_at"`
	Name         string `json:"name"`
	HostName     string `json:"host_name"`
	IPAddress    string `json:"ip_address"`
	OSVersion    string `json:"os_version"`
	AgentVersion string `json:"agent_version"`
	TenantID     string `json:"tenant_id"`
	OSMachineID  string `json:"os_machine_id"`
	NumGoroutine int    `json:"num_goroutine"`
}

Machine ...

type Policy

type Policy struct {
	ID              string `json:"id"`
	Name            string `json:"name"`
	SchedulePattern string `json:"schedule_pattern"`
	RetentionHours  int    `json:"retention_hours"`
	RetentionDays   int    `json:"retention_days"`
	RetentionWeeks  int    `json:"retention_weeks"`
	RetentionMonths int    `json:"retention_months"`
	CreatedAt       string `json:"created_at"`
	UpdatedAt       string `json:"updated_at"`
	TenantID        string `json:"tenant_id"`
}

Policy ...

type PolicyDirectories

type PolicyDirectories struct {
	ID                string   `json:"id"`
	Name              string   `json:"name"`
	SchedulePattern   string   `json:"schedule_pattern"`
	RetentionHours    int      `json:"retention_hours"`
	RetentionDays     int      `json:"retention_days"`
	RetentionWeeks    int      `json:"retention_weeks"`
	RetentionMonths   int      `json:"retention_months"`
	CreatedAt         string   `json:"created_at"`
	UpdatedAt         string   `json:"updated_at"`
	TenantID          string   `json:"tenant_id"`
	BackupDirectories []string `json:"backup-directories"`
}

PolicyDirectories ...

type ProgressWriter

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

ProgressWriter wraps a writer, counts number of bytes written to it and write the report back to writer.

func NewProgressWriter

func NewProgressWriter(out io.Writer) *ProgressWriter

NewProgressWriter returns new progress writer.

func (*ProgressWriter) Write

func (pc *ProgressWriter) Write(buf []byte) (int, error)

Write implements io.Writer interface.

Report the progress to underlying writer before return.

type RecoveryPoint

type RecoveryPoint struct {
	ID                string `json:"id"`
	Name              string `json:"name"`
	RecoveryPointType string `json:"recovery_point_type"`
	Status            string `json:"status"`
	PolicyID          string `json:"policy_id"`
	Progress          string `json:"progress"`
	BackupDirectoryID string `json:"backup_directory_id"`
	CreatedAt         string `json:"created_at"`
	UpdatedAt         string `json:"updated_at"`
}

RecoveryPoint ...

type RecoveryPointResponse added in v1.0.0

type RecoveryPointResponse struct {
	Name              string `json:"name"`
	RecoveryPointType string `json:"recovery_point_type"`
	ID                string `json:"id"`
	Status            string `json:"status"`
	CreatedAt         string `json:"created_at"`
	UpdatedAt         string `json:"updated_at"`
	IndexHash         string `json:"index_hash"`
}

LatestRecoveryPointID get a id latest recovery point of backup directory id.

type RestoreResponse added in v1.0.0

type RestoreResponse struct {
	ActionID          string `json:"action_id"`
	CreatedAt         string `json:"created_at"`
	RestoreSessionKey string `json:"restore_session_key"`
}

type StorageVault added in v1.0.0

type StorageVault struct {
	ID               string                   `json:"id"`
	Name             string                   `json:"name"`
	CredentialType   string                   `json:"credential_type"`
	StorageBucket    string                   `json:"storage_bucket"`
	StorageVaultType string                   `json:"storage_vault_type"`
	SecretRef        string                   `json:"secret_ref"`
	CreatedAt        string                   `json:"created_at"`
	UpdatedAt        string                   `json:"updated_at"`
	Deleted          bool                     `json:"deleted"`
	EncryptionKey    string                   `json:"encryption_key"`
	Credential       storage_vault.Credential `json:"credential"`
}

StorageVault ...

type UpdateMachineResponse added in v0.0.2

type UpdateMachineResponse struct {
	BrokerUrl    string `json:"broker_url"`
	NumGoroutine int    `json:"num_goroutine"`
}

UpdateMachineResponse is the server response when update machine info

type UpdateRecoveryPointRequest

type UpdateRecoveryPointRequest struct {
	Status string `json:"status"`
}

UpdateRecoveryPointRequest represents a request to update a recovery point.

type UpdateState added in v1.0.4

type UpdateState struct {
	EventType   string        `json:"event_type"`
	Directories []Directories `json:"directories"`
}

UpdateState ...

type Version added in v0.0.11

type Version struct {
	Ver     string            `json:"lastest_version"`
	Linux   map[string]string `json:"linux"`
	Macos   map[string]string `json:"macos"`
	Windows map[string]string `json:"windows"`
}

Jump to

Keyboard shortcuts

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