Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Backend ¶
type Backend interface { Store(name string, reader io.Reader) error Read(name string) (io.Reader, error) }
Backend provides read and write capabilities to a filesystem-like storage.
type InMemoryBackend ¶
InMemoryBackend stores backups in a slice. This should only be used for testing.
func NewInMemoryBackend ¶
func NewInMemoryBackend() *InMemoryBackend
type Lock ¶
type Lock struct { Name string `json:"name"` Current string `json:"current"` Previous string `json:"previous"` CreatedAt time.Time `json:"created_at"` }
Lock is a data structure representing a backup's lock file.
A single back up may have many versions. The lock file is used to point to the current version to restore from as well as the previous version as an easy way to roll back. It also provides flexibility to point to an even older version by locking Lock.Current to any version.
func NewLockFromBytes ¶
NewLockFromBytes unmarshals a lock file's JSON bytes into a Lock struct.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager performs versioned backup and restoration of files.
func NewManager ¶
NewManager returns a new Manager with the given backend and versioner.
func (Manager) Backup ¶
Backup creates and stores a backup for `name` with the contents of `reader` in the Manager's backend. Backups are versioned and stored under a name in the format "$name_$version.bak", where $name is the name passed to this function and $version is calculated from `m.versioner`.
A lockfile is created for each name and points to the latest stored backup under that name. The lockfile is used to restore from the latest backup.
func (Manager) Restore ¶
Restore attempts to restore the latest backup under `name` by looking for an associated lock and returning an `io.Reader` for the contents of backup that the lock points to. If no lock exists for the given name, this function is unable to find a back up and will return an error.
type NoSuchName ¶
type NoSuchName struct {
Name string
}
NoSuchName is an error returned by `Backend` when a name does not exist.
func (NoSuchName) Error ¶
func (e NoSuchName) Error() string
type S3Backend ¶
type S3Backend struct {
// contains filtered or unexported fields
}
S3Backend provides a Backend to AWS S3. This will also work with Digital Ocean Spaces, since this product is also S3-compatible.
func NewS3Backend ¶
NewS3Backend returns an S3Backend with the given session and bucket.
type TimestampVersioner ¶
type TimestampVersioner struct { }
TimestampVersioner is a Versioner that returns a timestamp that can be used to version a file. It takes a `time.Time` which it uses to create the version.
func NewTimestampVersioner ¶
func NewTimestampVersioner() TimestampVersioner
NewTimestampVersioner returns a new TimestampVersioner for the given time.
func (TimestampVersioner) GetVersion ¶
func (v TimestampVersioner) GetVersion() string
GetVersion returns a filename-safe version string in the format `YmdTHMS`.
For example, if the versioner was created on August 15, 2019 at 15:00:00, the version string would look like `20190815T150000`.