backups

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2021 License: Apache-2.0 Imports: 7 Imported by: 1

Documentation

Overview

Package backups enables management and retrieval of Backups VBS service.

Example to List Backups

listOpts := backups.ListOpts{}
allBackups, err := backups.List(vbsClient, listOpts)
if err != nil {
	panic(err)
}

for _, backup := range allBackups {
	fmt.Printf("%+v\n", backup)
}

Example to Get a Backup

   getbackup,err:=backups.Get(vbsClient, "6149e448-dcac-4691-96d9-041e09ef617f").Extract()
   if err != nil {
         panic(err)
		}

   fmt.Println(getbackup)

Example to Create a Backup

	createOpts := backups.CreateOpts{
		Name:"backup-test",
		VolumeId:"5024a06e-6990-4f12-9dcc-8fe26b01a710",
	}

	jobInfo, err := backups.Create(vbsClient, createOpts).ExtractJobResponse()
	if err != nil {
		panic(err)
	}

    err1 := backups.WaitForJobSuccess(client, int(120), jobInfo.JobID)
	if err1 != nil {
		panic(err1)
	}

	Label := "backup_id"
    entity, err2 := backups.GetJobEntity(client, jobInfo.JobID, Label)
	fmt.Println(entity)
	if err2 != nil {
		panic(err2)
	}

Example to Delete a Backup

backupID := "4e8e5957-649f-477b-9e5b-f1f75b21c03c"
err := backups.Delete(vbsClient, backupID).ExtractErr()
if err != nil {
	panic(err)
}

Example to Restore a Backup

restoreOpts := backups.BackupRestoreOpts{VolumeId:"5024a06e-6990-4f12-9dcc-8fe26b01a710"}

restore,err := backups.CreateBackupRestore(vbsClient,"87566ed6-72cb-4053-aa6e-6f6216b3d507",backup).ExtractBackupRestore()
if err != nil {
	panic(err)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetJobEntity

func GetJobEntity(client *golangsdk.ServiceClient, jobId string, label string) (interface{}, error)

func WaitForJobSuccess

func WaitForJobSuccess(client *golangsdk.ServiceClient, secs int, jobID string) error

Types

type Backup

type Backup struct {
	// Backup ID
	Id string `json:"id"`
	// Backup name
	Name string `json:"name"`
	// Backup URL
	Links []golangsdk.Link `json:"links"`
	// Backup status
	Status string `json:"status"`
	// Backup description
	Description string `json:"description"`
	// AvailabilityZone where the backup resides
	AvailabilityZone string `json:"availability_zone"`
	// Source volume ID of the backup
	VolumeId string `json:"volume_id"`
	// Cause of the backup failure
	FailReason string `json:"fail_reason"`
	// Backup size
	Size int `json:"size"`
	// Number of objects on OBS for the disk data
	ObjectCount int `json:"object_count"`
	// Container of the backup
	Container string `json:"container"`
	// Backup creation time
	CreatedAt time.Time `json:"-"`
	// ID of the tenant to which the backup belongs
	TenantId string `json:"os-bak-tenant-attr:tenant_id"`
	// Backup metadata
	ServiceMetadata string `json:"service_metadata"`
	// Time when the backup was updated
	UpdatedAt time.Time `json:"-"`
	// Current time
	DataTimeStamp time.Time `json:"-"`
	// Whether a dependent backup exists
	DependentBackups bool `json:"has_dependent_backups"`
	// ID of the snapshot associated with the backup
	SnapshotId string `json:"snapshot_id"`
	// Whether the backup is an incremental backup
	Incremental bool `json:"is_incremental"`
}

func ExtractBackups

func ExtractBackups(r pagination.Page) ([]Backup, error)

ExtractBackups accepts a Page struct, specifically a BackupPage struct, and extracts the elements into a slice of Backups struct. In other words, a generic collection is mapped into a relevant slice.

func FilterBackups

func FilterBackups(backup []Backup, opts ListOpts) ([]Backup, error)

func List

func List(c *golangsdk.ServiceClient, opts ListOpts) ([]Backup, error)

List returns collection of Backup. It accepts a ListOpts struct, which allows you to filter and sort the returned collection for greater efficiency.

Default policy settings return only those Backup that are owned by the tenant who submits the request, unless an admin user submits the request.

func (*Backup) UnmarshalJSON

func (r *Backup) UnmarshalJSON(b []byte) error

UnmarshalJSON overrides the default, to convert the JSON API response into our Backup struct

type BackupPage

type BackupPage struct {
	pagination.LinkedPageBase
}

BackupPage is the page returned by a pager when traversing over a collection of Backups.

func (BackupPage) IsEmpty

func (r BackupPage) IsEmpty() (bool, error)

IsEmpty checks whether a BackupPage struct is empty.

func (BackupPage) NextPageURL

func (r BackupPage) NextPageURL() (string, error)

NextPageURL is invoked when a paginated collection of Backups has reached the end of a page and the pager seeks to traverse over a new one. In order to do this, it needs to construct the next page's URL.

type BackupRestoreInfo

type BackupRestoreInfo struct {
	// Backup ID
	BackupId string `json:"backup_id"`
	// Volume ID
	VolumeId string `json:"volume_id"`
	// Volume name
	VolumeName string `json:"volume_name"`
}

type BackupRestoreOpts

type BackupRestoreOpts struct {
	// ID of the disk to be backed up
	VolumeId string `json:"volume_id" required:"true"`
}

BackupRestoreOpts contains all the values needed to create a new backup.

func (BackupRestoreOpts) ToRestoreCreateMap

func (opts BackupRestoreOpts) ToRestoreCreateMap() (map[string]interface{}, error)

ToRestoreCreateMap builds a create request body from BackupRestoreOpts.

type CreateOpts

type CreateOpts struct {
	// ID of the disk to be backed up
	VolumeId string `json:"volume_id" required:"true"`
	// Snapshot ID of the disk to be backed up
	SnapshotId string `json:"snapshot_id,omitempty" `
	// Backup name, which cannot start with autobk
	Name string `json:"name" required:"true"`
	// Backup description
	Description string `json:"description,omitempty"`
	// List of tags to be configured for the backup resources
	Tags []Tag `json:"tags,omitempty"`
}

CreateOpts contains all the values needed to create a new backup.

func (CreateOpts) ToBackupCreateMap

func (opts CreateOpts) ToBackupCreateMap() (map[string]interface{}, error)

ToBackupCreateMap builds a create request body from CreateOpts.

type CreateOptsBuilder

type CreateOptsBuilder interface {
	ToBackupCreateMap() (map[string]interface{}, error)
}

CreateOptsBuilder allows extensions to add additional parameters to the Create request.

type CreateResult

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

CreateResult represents the result of a create operation. Call its Extract method to interpret it as a Backup.

func CreateBackupRestore

func CreateBackupRestore(c *golangsdk.ServiceClient, id string, opts RestoreOptsBuilder) (r CreateResult)

CreateBackupRestore will create a new Restore based on the values in BackupRestoreOpts. To extract the BackupRestoreInfo object from the response, call the ExtractBackupRestore method on the CreateResult.

func (CreateResult) Extract

func (r CreateResult) Extract() (*Backup, error)

Extract is a function that accepts a result and extracts a backup.

func (CreateResult) ExtractBackupRestore

func (r CreateResult) ExtractBackupRestore() (*BackupRestoreInfo, error)

ExtractBackupRestore is a function that accepts a result and extracts a backup

type DeleteResult

type DeleteResult struct {
	golangsdk.ErrResult
}

DeleteResult represents the result of a delete operation. Call its ExtractErr method to determine if the request succeeded or failed.

func Delete

func Delete(c *golangsdk.ServiceClient, id string) (r DeleteResult)

Delete will permanently delete a particular backup based on its unique ID.

type GetResult

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

GetResult represents the result of a get operation. Call its Extract method to interpret it as a Backup.

func Get

func Get(c *golangsdk.ServiceClient, id string) (r GetResult)

Get retrieves a particular backup based on its unique ID. To extract // the Backup object from the response, call the Extract method on the // GetResult.

func (GetResult) Extract

func (r GetResult) Extract() (*Backup, error)

Extract is a function that accepts a result and extracts a backup.

func (GetResult) ExtractBackupRestore

func (r GetResult) ExtractBackupRestore() (*BackupRestoreInfo, error)

ExtractBackupRestore is a function that accepts a result and extracts a backup

type JobResponse

type JobResponse struct {
	JobID string `json:"job_id"`
}

type JobResult

type JobResult struct {
	golangsdk.Result
}

func Create

func Create(c *golangsdk.ServiceClient, opts CreateOptsBuilder) (r JobResult)

Create will create a new Backup based on the values in CreateOpts. To extract the Backup object from the response, call the ExtractJobResponse method on the JobResult.

func (JobResult) ExtractJobResponse

func (r JobResult) ExtractJobResponse() (*JobResponse, error)

func (JobResult) ExtractJobStatus

func (r JobResult) ExtractJobStatus() (*JobStatus, error)

type JobStatus

type JobStatus struct {
	Status     string            `json:"status"`
	Entities   map[string]string `json:"entities"`
	JobID      string            `json:"job_id"`
	JobType    string            `json:"job_type"`
	BeginTime  string            `json:"begin_time"`
	EndTime    string            `json:"end_time"`
	ErrorCode  string            `json:"error_code"`
	FailReason string            `json:"fail_reason"`
	SubJobs    []JobStatus       `json:"sub_jobs"`
}

type ListOpts

type ListOpts struct {
	Id         string
	SnapshotId string
	Name       string `q:"name"`
	Status     string `q:"status"`
	Limit      int    `q:"limit"`
	Offset     int    `q:"offset"`
	VolumeId   string `q:"volume_id"`
}

ListOpts allows the filtering and sorting of paginated collections through the API. Filtering is achieved by passing in struct field values that map to the backup attributes you want to see returned.

type RestoreOptsBuilder

type RestoreOptsBuilder interface {
	ToRestoreCreateMap() (map[string]interface{}, error)
}

RestoreOptsBuilder allows extensions to add additional parameters to the Create request.

type Tag

type Tag struct {
	// Tag key
	Key string `json:"key" required:"true"`
	// Tag value
	Value string `json:"value" required:"true"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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