Documentation ¶
Index ¶
- Constants
- type DB
- func (d *DB) AddOrUpdate(set *Set) error
- func (d *DB) Backup() error
- func (d *DB) Close() error
- func (d *DB) Discover(setID string, cb DiscoverCallback) (*Set, error)
- func (d *DB) EnableRemoteBackups(remotePath string, handler put.Handler)
- func (d *DB) GetAll() ([]*Set, error)
- func (d *DB) GetByID(id string) *Set
- func (d *DB) GetByNameAndRequester(name, requester string) (*Set, error)
- func (d *DB) GetByRequester(requester string) ([]*Set, error)
- func (d *DB) GetDefinedFileEntry(setID string) (*Entry, error)
- func (d *DB) GetDirEntries(setID string) ([]*Entry, error)
- func (d *DB) GetFailedEntries(setID string) ([]*Entry, int, error)
- func (d *DB) GetFileEntries(setID string) ([]*Entry, error)
- func (d *DB) GetMountPointFromPath(path string) string
- func (d *DB) GetPureFileEntries(setID string) ([]*Entry, error)
- func (d *DB) HardlinkPaths(e *Entry) ([]string, error)
- func (d *DB) HardlinkRemote(e *Entry) (string, error)
- func (d *DB) SetBackupPath(path string)
- func (d *DB) SetDirEntries(setID string, entries []*walk.Dirent) error
- func (d *DB) SetEntryStatus(r *put.Request) (*Entry, error)
- func (d *DB) SetError(setID, errMsg string) error
- func (d *DB) SetFileEntries(setID string, paths []string) error
- func (d *DB) SetMinimumTimeBetweenBackups(dur time.Duration)
- func (d *DB) SetWarning(setID, warnMsg string) error
- type DiscoverCallback
- type Entry
- type EntryStatus
- type EntryType
- type Error
- type Set
- type Status
Constants ¶
const ( ErrInvalidSetID = "invalid set ID" ErrInvalidRequest = "request lacks Requester or Set" ErrInvalidEntry = "invalid set entry" ErrInvalidTransformerPath = "invalid transformer path concatenation" ErrNoAddDuringDiscovery = "can't add set while set is being discovered" AttemptsToBeConsideredFailing = 3 )
const (
ErrInvalidTransformer = "invalid transformer"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB is used to create and query a database for storing backup sets (lists of files a user wants to have backed up) and their backup status.
func New ¶
New returns a *DB that can be used to create or query a set database. Provide the path to the database file.
Optionally, also provide a path to backup the database to.
Returns an error if path exists but can't be opened, or if it doesn't exist and can't be created.
func (*DB) AddOrUpdate ¶
AddOrUpdate adds or updates the given Set to the database.
func (*DB) Backup ¶ added in v0.7.0
Backup does an on-line backup of the database to the given file path. There's at least 1 second in between backups, and incoming backup requests are noted during an on-going backup, with 1 further backup occurring after the on-going one completes.
func (*DB) Close ¶
Close closes the database. Be sure to call this to finalise any writes to disk correctly.
func (*DB) Discover ¶ added in v0.8.0
func (d *DB) Discover(setID string, cb DiscoverCallback) (*Set, error)
Discover discovers and stores file entry details for the given set. Immediately tries to record in the db that discovery has started and returns any error from doing that. Actual discovery using your callback on directories will then proceed, as will the stat'ing of pure files, and return the updated set.
func (*DB) EnableRemoteBackups ¶ added in v0.7.0
EnableRemoteBackups causes the backup file to also be backed up to the remote path.
func (*DB) GetByID ¶
GetByID returns the Sets with the given ID previously added to the database. Returns nil if such a set does not exist.
func (*DB) GetByNameAndRequester ¶ added in v0.7.0
GetByNameAndRequester returns the set with the given name and requester.
Returns nil error when no set found.
func (*DB) GetByRequester ¶
GetByRequester returns all the Sets previously added to the database by the given requester.
func (*DB) GetDefinedFileEntry ¶ added in v0.7.0
GetDefinedFileEntry returns the first defined file entry for the given set.
Will return nil Entry if SetFileEntries hasn't been called.
func (*DB) GetDirEntries ¶
GetDirEntries returns all the dir entries for the given set.
func (*DB) GetFailedEntries ¶ added in v0.6.0
GetFailedEntries returns up to 10 of the file entries for the given set (both SetFileEntries and SetDiscoveredEntries) that have a failed status. Also returns the number of failed entries that were not returned.
func (*DB) GetFileEntries ¶
GetFileEntries returns all the file entries for the given set (both SetFileEntries and SetDiscoveredEntries).
func (*DB) GetMountPointFromPath ¶ added in v0.9.0
GetMountPointFromPath determines the mount point for the given path based on the mount points available on the system when the server started. If nothing matches, returns /.
func (*DB) GetPureFileEntries ¶
GetPureFileEntries returns all the file entries for the given set (only SetFileEntries, not SetDiscoveredEntries).
func (*DB) HardlinkPaths ¶ added in v0.8.0
HardlinkPaths returns all known hardlink paths that share the same mountpoint and inode as the entry provided.
func (*DB) SetBackupPath ¶ added in v0.7.0
SetBackupPath sets the backup path, for if you created the DB without providing one.
func (*DB) SetDirEntries ¶
SetDirEntries sets the directory paths for the given backup set. Only supply absolute paths to directories.
func (*DB) SetEntryStatus ¶
SetEntryStatus finds the set Entry corresponding to the given Request's Local path, Requester and Set name, and updates its status in the database, and also updates summary status for the Set.
Returns the Entry, which is a reflection of the Request, but contains additional information such as the number of Attempts if the Request is failing and you keep retrying.
Returns an error if a set or entry corresponding to the Request can't be found.
func (*DB) SetError ¶
SetError updates a set with the given error message. Returns an error if the setID isn't in the database.
func (*DB) SetFileEntries ¶
SetFileEntries sets the file paths for the given backup set. Only supply absolute paths to files.
func (*DB) SetMinimumTimeBetweenBackups ¶ added in v0.7.0
SetMinimumTimeBetweenBackups sets the minimum time between successive backups. Defaults to 1 second if this method not called.
func (*DB) SetWarning ¶ added in v0.8.0
SetWarning updates a set with the given warning message. Returns an error if the setID isn't in the database.
type DiscoverCallback ¶ added in v0.8.0
DiscoverCallback will receive the sets directory entries and return a list of the files discovered in those directories.
type Entry ¶
type Entry struct { Path string PathForJSON []byte // set by MakeSafeForJSON(); do not set this yourself. Size uint64 // size of local file in bytes. Status EntryStatus Type EntryType LastError string LastAttempt time.Time Attempts int Inode uint64 Dest string // contains filtered or unexported fields }
Entry holds the status of an entry in a backup set.
func (*Entry) CorrectFromJSON ¶ added in v0.6.3
func (e *Entry) CorrectFromJSON()
CorrectFromJSON copies PathForJSON to Path, so that this value is correct following a decode from JSON.
func (*Entry) MakeSafeForJSON ¶ added in v0.6.3
func (e *Entry) MakeSafeForJSON()
MakeSafeForJSON copies Path to PathForJSON, so that if this Entry struct is encoded as JSON, non-UTF8 characters will be preserved. On decode be sure to use CorrectFromJSON().
type EntryStatus ¶
type EntryStatus int
const ( // Pending is an Entry status meaning the file has not yet had an upload // attempt. Pending EntryStatus = iota // UploadingEntry is an Entry status meaning the file has started to upload. UploadingEntry // Uploaded is an Entry status meaning the file has been uploaded // successfully. Uploaded // Failed is an Entry status meaning the file failed to upload due to some // remote issue. Failed // Missing is an Entry status meaning the local file is missing so can't be // uploaded. Missing // AbnormalEntry is an Entry status meaning the local files is neither // regular nor a symlink (ie. it's a fifo or socket etc.), so shouldn't be // uploaded. AbnormalEntry )
func (EntryStatus) String ¶
func (e EntryStatus) String() string
String lets you convert a EntryStatus to a meaningful string.
type Set ¶
type Set struct { // An arbitrary (short) name for this backup set. Name string // The username of the person requesting this backup. Requester string // The method of transforming local Entries paths in to remote paths, to // determine the upload location. "humgen" to use the put.HumgenTransformer, // or "prefix=local:remote" to use the put.PrefixTransformer. Transformer string // Monitor the files and directories and re-upload them whenever they // change, checking for changes after the given amount of time. Optional, // defaults to unmonitored (a one time upload of Entries). MonitorTime time.Duration // An optional longer free-text description of this backup set. Description string // Delete local paths after successful upload. Optional, defaults to no // deletions (ie. do a backup, not a move). DeleteLocal bool // StartedDiscovery provides the last time that discovery started. This is a // read-only value. StartedDiscovery time.Time // LastDiscovery provides the last time that discovery completed. This is a // read-only value. LastDiscovery time.Time // NumFiles provides the total number of set and discovered files in this // set, as of the last discovery. This is a read-only value. NumFiles uint64 // SizeFiles provides the total size (bytes) of set and discovered files in // this set, as of the last discovery. This is a read-only value. SizeFiles uint64 // Uploaded provides the total number of set and discovered files in this // set that have been uploaded or confirmed uploaded since the last // discovery. This is a read-only value. Uploaded uint64 // Failed provides the total number of set and discovered files in this set // that have failed their upload since the last discovery. This is a // read-only value. Failed uint64 // Missing provides the total number of set and discovered files in this set // that no longer exist locally since the last discovery. This is a // read-only value. Missing uint64 // Abnormal provides the total number of set files in this set that were // neither regular files, nor Symlinks (ie. they were fifo or socket files // etc). Abnormal uint64 // Symlinks provides the total number of set and discovered files in this // set that are symlinks. This is a read-only value. Symlinks uint64 // Hardlinks provides the total number of set and discovered files in this // set that are hardlinks and skipped. This is a read-only value. Hardlinks uint64 // Status provides the current status for the set since the last discovery. // This is a read-only value. Status Status // LastCompleted provides the last time that all uploads completed // (regardless of success or failure). This is a read-only value. LastCompleted time.Time // LastCompletedCount provides the count of files on the last upload attempt // (those successfully uploaded, those which failed, but not those which // were missing locally). This is a read-only value. LastCompletedCount uint64 // LastCompletedSize provides the size of files (bytes) counted in // LastCompletedCount. This is a read-only value. LastCompletedSize uint64 // Error holds any error that applies to the whole set, such as an issue // with the Transformer. This is a read-only value. Error string // Warning contains errors that do not stop progression. This is a read-only // value. Warning string }
Set describes a backup set; a list of files and directories to backup, plus some metadata. All properties are required unless otherwise noted.
func (*Set) Count ¶
Count provides a string representation of NumFiles, or if 0, returns the LastCompletedCount with a textual note to that effect.
func (*Set) Discovered ¶
Discovered provides a string representation of when discovery last completed, or if it hasn't, when it started, or if it hasn't, says "not started".
func (*Set) ID ¶
ID returns an ID for this set, generated deterministiclly from its Name and Requester. Ie. it is unique between all requesters, and amongst a requester's differently named sets. Sets with the same Name and Requester will have the same ID().
func (*Set) MakeTransformer ¶
func (s *Set) MakeTransformer() (put.PathTransformer, error)
MakeTransformer turns our Transformer string in to a put.HumgenTransformer or a put.PrefixTransformer as appropriate.
type Status ¶
type Status int
const ( // PendingDiscovery is a Set status meaning the set's entries are pending // existence, size and directory content discovery. PendingDiscovery Status = iota // PendingUpload is a Set status meaning discovery has completed, but no // entries have been uploaded since then. PendingUpload // Uploading is a Set status meaning discovery has completed and upload of // entries has started. Uploading // Failing is a Set status meaning at least 1 of the entries has failed to // upload after 3 attempts. Other uploads are ongoing. Failing // Complete is a Set status meaning all entries have had an upload attempt // since the last discovery. (Some uploads may have failed, but they had // 3 retries.) Complete )