Documentation ¶
Overview ¶
Package storage keep track of the uploaded backups.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var BoltDBBucket = []byte("toglacier")
BoltDBBucket defines the bucket in the BoltDB database where the data will be stored.
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 ¶
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 ¶
NewAuditFile initializes a new AuditFile object.
func (*AuditFile) List ¶
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 ¶
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 ¶
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 ¶
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 ¶
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) Less ¶
Less compares two positions of the slice and verifies the preference. They are ordered by the id, that should be unique.
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 (BoltDB) List ¶
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 ¶
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 ¶
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 ¶
Error stores error details from a problem occurred while managing the local storage.
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" )
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).