Documentation ¶
Overview ¶
Package cloud manages the backup in a specific cloud.
Index ¶
- func ErrorEqual(first, second error) bool
- func JobsErrorEqual(first, second error) bool
- func MultipartErrorEqual(first, second error) bool
- func MultipartUploadLimit(value int64)
- func PartSize(value int64)
- func WaitJobTime(value time.Duration)
- type AWSCloud
- type AWSConfig
- type AWSInventoryArchiveList
- type Backup
- type Clock
- type Cloud
- type Error
- type ErrorCode
- type JobsError
- type JobsErrorCode
- type MultipartError
- type MultipartErrorCode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ErrorEqual ¶
ErrorEqual compares two Error objects. This is useful to compare down to the low level errors.
func JobsErrorEqual ¶
JobsErrorEqual compares two JobsError objects. This is useful to compare down to the low level errors.
func MultipartErrorEqual ¶
MultipartErrorEqual compares two MultipartError objects. This is useful to compare down to the low level errors.
func MultipartUploadLimit ¶
func MultipartUploadLimit(value int64)
MultipartUploadLimit defines the limit where we decide if we will send the file in one shot or if we will use multipart upload strategy. By default we use 100 MB.
func PartSize ¶
func PartSize(value int64)
PartSize the size of each part of the multipart upload except the last, in bytes. The last part can be smaller than this part size. By default we use 4MB.
func WaitJobTime ¶
WaitJobTime is the amount of time that we wait for the job to complete, as it takes some time, we will sleep for a long time before we check again. By default we use 1 minute.
Types ¶
type AWSCloud ¶
type AWSCloud struct { Logger log.Logger AccountID string VaultName string Glacier glacieriface.GlacierAPI Clock Clock }
AWSCloud is the Amazon solution for storing the backups in the cloud. It uses the Amazon Glacier service, as it allows large files for a small price.
func NewAWSCloud ¶
NewAWSCloud initializes the Amazon cloud object, defining the account ID and vault name that are going to be used in the AWS Glacier service. For more details set the debug flag to receive low level information in the standard output. On error it will return an Error type. To retrieve the desired error you can do:
type causer interface { Cause() error } if causeErr, ok := err.(causer); ok { switch specificErr := causeErr.Cause().(type) { case *cloud.Error: // handle specifically default: // unknown error } }
func (*AWSCloud) Get ¶
Get retrieves a specific backup file and stores it locally in a file. The filename storing the location of the file is returned. If an error occurs it will be an Error or JobsError type encapsulated in a traceable error. To retrieve the desired error you can do:
type causer interface { Cause() error } if causeErr, ok := err.(causer); ok { switch specificErr := causeErr.Cause().(type) { case *cloud.Error: // handle specifically case *cloud.JobsError: // handle specifically default: // unknown error } }
func (*AWSCloud) List ¶
List retrieves all the uploaded backups information in the cloud. If an error occurs it will be an Error or JobsError type encapsulated in a traceable error. To retrieve the desired error you can do:
type causer interface { Cause() error } if causeErr, ok := err.(causer); ok { switch specificErr := causeErr.Cause().(type) { case *cloud.Error: // handle specifically case *cloud.JobsError: // handle specifically default: // unknown error } }
func (*AWSCloud) Remove ¶
Remove erase a specific backup from the cloud. If an error occurs it will be an Error type encapsulated in a traceable error. To retrieve the desired error you can do:
type causer interface { Cause() error } if causeErr, ok := err.(causer); ok { switch specificErr := causeErr.Cause().(type) { case *cloud.Error: // handle specifically default: // unknown error } }
func (*AWSCloud) Send ¶
Send uploads the file to the cloud and return the backup archive information. It already has the logic to send directly if it's a small file or use multipart strategy if it's a large file. If an error occurs it will be an Error or MultipartError type encapsulated in a traceable error. To retrieve the desired error you can do:
type causer interface { Cause() error } if causeErr, ok := err.(causer); ok { switch specificErr := causeErr.Cause().(type) { case *cloud.Error: // handle specifically case *cloud.MultipartError: // handle specifically default: // unknown error } }
type AWSConfig ¶
type AWSConfig struct { AccountID string AccessKeyID string SecretAccessKey string Region string VaultName string }
AWSConfig stores all necessary parameters to initialize a AWS session.
type AWSInventoryArchiveList ¶
type AWSInventoryArchiveList []struct { ArchiveID string `json:"ArchiveId"` ArchiveDescription string `json:"ArchiveDescription"` CreationDate time.Time `json:"CreationDate"` Size int `json:"Size"` SHA256TreeHash string `json:"SHA256TreeHash"` }
AWSInventoryArchiveList stores the archive information retrieved from AWS Glacier service.
func (AWSInventoryArchiveList) Len ¶
func (a AWSInventoryArchiveList) Len() int
func (AWSInventoryArchiveList) Less ¶
func (a AWSInventoryArchiveList) Less(i, j int) bool
func (AWSInventoryArchiveList) Swap ¶
func (a AWSInventoryArchiveList) Swap(i, j int)
type Backup ¶
type Backup struct { // ID primary key to identify the archive in the cloud. ID string // Time that the archive was created in the cloud. CreatedAt time.Time // Checksum is a SHA256 of the archive content. Checksum string // VaultName is the identifier of the place in the cloud where the archive was // stored. VaultName string // Size backup archive size. Size int64 }
Backup store all the necessary information of an already uploaded archive.
type Clock ¶
Clock used to retrieve the current time. Useful for mocking in test environments, or if you want you own implementation of clock to be used.
type Cloud ¶
type Cloud interface { // Send uploads the file to the cloud and return the backup archive // information. The upload operation can be cancelled anytime using the // context. Send(ctx context.Context, filename string) (Backup, error) // List retrieves all the uploaded backups information in the cloud. The // operation can be cancelled anytime using the context. List(ctx context.Context) ([]Backup, error) // Get retrieves the backups with the given ids and stores them locally in // files. The ids and corresponding filenames where the backups were saved are // returned. The operation can be cancelled anytime using the context. Get(ctx context.Context, ids ...string) (filenames map[string]string, err error) // Remove erase a specific backup from the cloud. The operation can be // cancelled anytime using the context. Remove(ctx context.Context, id string) error }
Cloud offers all necessary operations to manage backups in the cloud.
type Error ¶
Error stores error details from cloud operations.
type ErrorCode ¶
type ErrorCode string
ErrorCode stores the error type that occurred while performing any operation with the cloud.
const ( // ErrorCodeInitializingSession error connecting to the cloud server to // initialize the session. ErrorCodeInitializingSession ErrorCode = "initializing-session" // ErrorCodeOpeningArchive problem detected while trying to open the archive // that contains the backup data. ErrorCodeOpeningArchive ErrorCode = "opening-archive" // ErrorCodeArchiveInfo error while trying to get information about the // archive. ErrorCodeArchiveInfo ErrorCode = "archive-info" // ErrorCodeSendingArchive problem while uploading the archive to the cloud. ErrorCodeSendingArchive ErrorCode = "sending-archive" // ErrorCodeComparingChecksums digest mismatch while comparing local archive // hash with the cloud archive hash. ErrorCodeComparingChecksums ErrorCode = "comparing-checksums" // ErrorCodeInitMultipart error while communicating to the cloud that we are // going to start sending pieces of the archive. ErrorCodeInitMultipart ErrorCode = "initi-multipart" // ErrorCodeCompleteMultipart error while signalizing to the cloud that the // multipart upload was done. ErrorCodeCompleteMultipart ErrorCode = "complete-multipart" // ErrorCodeInitJob error while asking to the cloud to initiate an offline // task. ErrorCodeInitJob ErrorCode = "init-job" // ErrorCodeJobComplete error while trying to retrieve an offline task result // from the cloud. ErrorCodeJobComplete ErrorCode = "job-complete" // ErrorCodeJobFailed offline task in the cloud failed to complete. ErrorCodeJobFailed ErrorCode = "job-failed" // ErrorCodeDecodingData problem decoding the data returned from the cloud. ErrorCodeDecodingData ErrorCode = "decoding-data" // ErrorCodeCreatingArchive error while creating the file that will store the // data retrieved from the cloud. ErrorCodeCreatingArchive ErrorCode = "creating-archive" // ErrorCodeCopyingData problem while filling the created file with the bytes // retrieved from the cloud. ErrorCodeCopyingData ErrorCode = "copying-data" // ErrorCodeRemovingArchive error while removing the archive from the cloud. ErrorCodeRemovingArchive ErrorCode = "removing-archive" // ErrorCodeCancelled action cancelled by the user. ErrorCodeCancelled ErrorCode = "cancelled" )
type JobsError ¶
type JobsError struct { Jobs []string Code JobsErrorCode Err error }
JobsError stores error details that occurs when monitoring asynchronous jobs in the cloud.
type JobsErrorCode ¶
type JobsErrorCode string
JobsErrorCode stores the error type that occurred while performing any operation with the cloud.
const ( // JobsErrorCodeRetrievingJob error while trying to get a task status in the // cloud. JobsErrorCodeRetrievingJob JobsErrorCode = "retrieving-job" // JobsErrorCodeJobNotFound offline task missing from the cloud. JobsErrorCodeJobNotFound JobsErrorCode = "job-not-found" // JobsErrorCodeCancelled action cancelled by the user. JobsErrorCodeCancelled JobsErrorCode = "cancelled" )
func (JobsErrorCode) String ¶
func (e JobsErrorCode) String() string
String translate the error code to a human readable text.
type MultipartError ¶
type MultipartError struct { Offset int64 Size int64 Code MultipartErrorCode Err error }
MultipartError stores error details that occurs when sending pieces of the archive to the cloud.
func (MultipartError) Error ¶
func (c MultipartError) Error() string
Error returns the error in a human readable format.
func (MultipartError) String ¶
func (c MultipartError) String() string
String translate the error to a human readable text.
type MultipartErrorCode ¶
type MultipartErrorCode string
MultipartErrorCode stores the error type that occurred while sending a piece of the archive to the cloud.
const ( // MultipartErrorCodeReadingArchive error reading a piece of the archive. MultipartErrorCodeReadingArchive MultipartErrorCode = "reading-archive" // MultipartErrorCodeSendingArchive error sending a piece of the archive to // the cloud. MultipartErrorCodeSendingArchive MultipartErrorCode = "sending-archive" // MultipartErrorCodeComparingChecksums error comparing checksums with the // cloud of the uploaded archive part. MultipartErrorCodeComparingChecksums MultipartErrorCode = "comparing-checksums" // MultipartErrorCodeCancelled action cancelled by the user. MultipartErrorCodeCancelled MultipartErrorCode = "cancelled" )
func (MultipartErrorCode) String ¶
func (c MultipartErrorCode) String() string
String translate the error code to a human readable text.