storage

package
v3.2.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2017 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package storage keep track of the uploaded backups.

Index

Constants

This section is empty.

Variables

View Source
var BoltDBBucket = []byte("toglacier")

BoltDBBucket defines the bucket in the BoltDB database where the data will be stored.

View Source
var BoltDBFileMode = os.FileMode(0600)

BoltDBFileMode defines the file mode used for the BoltDB database file. By default only the owner has permission to access the file.

Functions

func ErrorEqual

func ErrorEqual(first, second error) bool

ErrorEqual compares two Error objects. This is useful to compare down to the low level errors.

Types

type AuditFile

type AuditFile struct {
	Filename string
	// contains filtered or unexported fields
}

AuditFile stores all backup information in a simple text file.

func NewAuditFile

func NewAuditFile(logger log.Logger, filename string) *AuditFile

NewAuditFile initializes a new AuditFile object.

func (*AuditFile) List

func (a *AuditFile) List() (Backups, error)

List all backup information in the storage. As the audit file doesn't store backup extra information, it will be always nil. On error it will return 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 *storage.Error:
    // handle specifically
  default:
    // unknown error
  }
}

func (*AuditFile) Remove

func (a *AuditFile) Remove(id string) error

Remove a specific backup information from the storage. On error it will return 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 *storage.Error:
    // handle specifically
  default:
    // unknown error
  }
}

func (*AuditFile) Save

func (a *AuditFile) Save(backup Backup) error

Save a backup information. It stores the backup information one per line with the following columns:

[datetime] [vaultName] [archiveID] [checksum] [size]

The audit file doesn't store backup extra information. On error it will return 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 *storage.Error:
    // handle specifically
  default:
    // unknown error
  }
}

type Backup

type Backup struct {
	Backup cloud.Backup // TODO: rename this attribute?
	Info   archive.Info
}

Backup stores the cloud location of the backup and some extra information about the files of the backup.

type Backups

type Backups []Backup

Backups represents a sorted list of backups that are ordered by id. It has the necessary methods so you could use the sort package of the standard library.

func (*Backups) Add

func (b *Backups) Add(backup Backup)

Add inserts in the sorted slice a new backup. If the backup id already exist it will be replaced by the new one.

func (Backups) Len

func (b Backups) Len() int

Len returns the number of backups.

func (Backups) Less

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

Less compares two positions of the slice and verifies the preference. They are ordered by the id, that should be unique.

func (Backups) Search

func (b Backups) Search(id string) (Backup, bool)

Search looks for a backup containing the id.

func (Backups) Swap

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

Swap change the backups position inside the slice.

func (Backups) ValidInfo

func (b Backups) ValidInfo(archiveInfo archive.Info) bool

ValidInfo verifies if an archive information contains references for backups that exist.

type BoltDB

type BoltDB struct {
	Filename string
	// contains filtered or unexported fields
}

BoltDB stores all necessary data to use the BoltDB database. BoltDB was chosen as it is a fast key/value storage that uses only one local file. More information can be found at https://github.com/boltdb/bolt

func NewBoltDB

func NewBoltDB(logger log.Logger, filename string) *BoltDB

NewBoltDB initializes a BoltDB storage.

func (BoltDB) List

func (b BoltDB) List() (Backups, error)

List all backup information in the storage. On error it will return 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 *storage.Error:
    // handle specifically
  default:
    // unknown error
  }
}

func (BoltDB) Remove

func (b BoltDB) Remove(id string) error

Remove a specific backup information from the storage. On error it will return 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 *storage.Error:
    // handle specifically
  default:
    // unknown error
  }
}

func (*BoltDB) Save

func (b *BoltDB) Save(backup Backup) error

Save a backup information. On error it will return 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 *storage.Error:
    // handle specifically
  default:
    // unknown error
  }
}

type Error

type Error struct {
	Code ErrorCode
	Err  error
}

Error stores error details from a problem occurred while managing the local storage.

func (Error) Error

func (e Error) Error() string

Error returns the error in a human readable format.

func (Error) String

func (e Error) String() string

String translate the error to a human readable text.

type ErrorCode

type ErrorCode string

ErrorCode stores the error type that occurred while managing the local storage.

const (
	// ErrorCodeOpeningFile error when opening the file that stores the data
	// locally.
	ErrorCodeOpeningFile ErrorCode = "opening-file"

	// ErrorCodeWritingFile error while writing the data to the local storage
	// file.
	ErrorCodeWritingFile ErrorCode = "writing-file"

	// ErrorCodeReadingFile error while reading the file that stores the data
	// locally.
	ErrorCodeReadingFile ErrorCode = "reading-file"

	// ErrorCodeMovingFile error moving files. We keep backups of the storage
	// file, so we need to move the old one before writing a new storage file.
	ErrorCodeMovingFile ErrorCode = "moving-file"

	// ErrorCodeFormat local storage file contains an unexpected format
	// (corrupted).
	ErrorCodeFormat ErrorCode = "format"

	// ErrorCodeSizeFormat backup size isn't a valid number.
	ErrorCodeSizeFormat ErrorCode = "size-format"

	// ErrorCodeDateFormat strange date format found in the local storage file.
	ErrorCodeDateFormat ErrorCode = "date-format"

	// ErrorCodeEncodingBackup failed to encode the backup to a storage
	// representation.
	ErrorCodeEncodingBackup ErrorCode = "encoding-backup"

	// ErrorCodeDecodingBackup failed to decode the backup to the original format.
	ErrorCodeDecodingBackup ErrorCode = "decoding-backup"

	// ErrorCodeDatabaseNotFound database wasn't found.
	ErrorCodeDatabaseNotFound ErrorCode = "database-not-found"

	// ErrorCodeUpdatingDatabase problem while updating the database.
	ErrorCodeUpdatingDatabase ErrorCode = "updating-database"

	// ErrorCodeListingDatabase failed to list the backups from the database.
	ErrorCodeListingDatabase ErrorCode = "listing-database"

	// ErrorCodeSave failed to save the item in the database.
	ErrorCodeSave ErrorCode = "save"

	// ErrorCodeDelete failed to remove the item from the database.
	ErrorCodeDelete ErrorCode = "delete"

	// ErrorCodeIterating error while iterating over the database results.
	ErrorCodeIterating ErrorCode = "iterating"

	// ErrorAccessingBucket failed to open or create a database bucket.
	ErrorAccessingBucket ErrorCode = "accessing-bucket"
)

func (ErrorCode) String

func (e ErrorCode) String() string

String translate the error code to a human readable text.

type Storage

type Storage interface {
	// Save a backup information.
	Save(Backup) error

	// List all backup informations in the storage.
	List() (Backups, error)

	// Remove a specific backup information from the storage.
	Remove(id string) error
}

Storage represents all commands to manage backups information locally. After the backup is uploaded we must keep track of them locally to speed up recovery and cloud cleanup (remove old ones).

Jump to

Keyboard shortcuts

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