backup

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2020 License: MIT Imports: 20 Imported by: 2

Documentation

Index

Constants

View Source
const (
	LocalBackupAdapter = "wings"
	S3BackupAdapter    = "s3"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Archive

type Archive struct {
	sync.Mutex

	TrimPrefix string
	Files      *IncludedFiles
}

func (*Archive) Create

func (a *Archive) Create(dst string, ctx context.Context) error

Creates an archive at dst with all of the files defined in the included files struct.

type ArchiveDetails

type ArchiveDetails struct {
	Checksum     string `json:"checksum"`
	ChecksumType string `json:"checksum_type"`
	Size         int64  `json:"size"`
}

func (*ArchiveDetails) ToRequest

func (ad *ArchiveDetails) ToRequest(successful bool) api.BackupRequest

Returns a request object.

type Backup

type Backup struct {
	// The UUID of this backup object. This must line up with a backup from
	// the panel instance.
	Uuid string `json:"uuid"`

	// An array of files to ignore when generating this backup. This should be
	// compatible with a standard .gitignore structure.
	IgnoredFiles []string `json:"ignored_files"`
}

func (*Backup) Checksum

func (b *Backup) Checksum() ([]byte, error)

Returns the SHA256 checksum of a backup.

func (*Backup) Details

func (b *Backup) Details() *ArchiveDetails

Returns details of the archive by utilizing two go-routines to get the checksum and the size of the archive.

func (*Backup) Identifier

func (b *Backup) Identifier() string

func (*Backup) Ignored

func (b *Backup) Ignored() []string

func (*Backup) Path

func (b *Backup) Path() string

Returns the path for this specific backup.

func (*Backup) Size

func (b *Backup) Size() (int64, error)

Return the size of the generated backup.

type BackupInterface

type BackupInterface interface {
	// Returns the UUID of this backup as tracked by the panel instance.
	Identifier() string

	// Generates a backup in whatever the configured source for the specific
	// implementation is.
	Generate(*IncludedFiles, string) (*ArchiveDetails, error)

	// Returns the ignored files for this backup instance.
	Ignored() []string

	// Returns a SHA256 checksum for the generated backup.
	Checksum() ([]byte, error)

	// Returns the size of the generated backup.
	Size() (int64, error)

	// Returns the path to the backup on the machine. This is not always the final
	// storage location of the backup, simply the location we're using to store
	// it until it is moved to the final spot.
	Path() string

	// Returns details about the archive.
	Details() *ArchiveDetails

	// Removes a backup file.
	Remove() error
}

noinspection GoNameStartsWithPackageName

type IncludedFiles

type IncludedFiles struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*IncludedFiles) All

func (i *IncludedFiles) All() []string

Returns all of the files that were marked as being included.

func (*IncludedFiles) Push

func (i *IncludedFiles) Push(p string)

Pushes an additional file or folder onto the struct.

type LocalBackup

type LocalBackup struct {
	Backup
}

func LocateLocal

func LocateLocal(uuid string) (*LocalBackup, os.FileInfo, error)

Locates the backup for a server and returns the local path. This will obviously only work if the backup was created as a local backup.

func (*LocalBackup) Generate

func (b *LocalBackup) Generate(included *IncludedFiles, prefix string) (*ArchiveDetails, error)

Generates a backup of the selected files and pushes it to the defined location for this instance.

func (*LocalBackup) Remove

func (b *LocalBackup) Remove() error

Removes a backup from the system.

type Request

type Request struct {
	Adapter      string   `json:"adapter"`
	Uuid         string   `json:"uuid"`
	IgnoredFiles []string `json:"ignored_files"`
	PresignedUrl string   `json:"presigned_url"`
}

func (*Request) NewLocalBackup

func (r *Request) NewLocalBackup() (*LocalBackup, error)

Generates a new local backup struct.

func (*Request) NewS3Backup

func (r *Request) NewS3Backup() (*S3Backup, error)

Generates a new S3 backup struct.

type S3Backup

type S3Backup struct {
	Backup

	// The pre-signed upload endpoint for the generated backup. This must be
	// provided otherwise this request will fail. This allows us to keep all
	// of the keys off the daemon instances and the panel can handle generating
	// the credentials for us.
	PresignedUrl string
}

func (*S3Backup) Generate

func (s *S3Backup) Generate(included *IncludedFiles, prefix string) (*ArchiveDetails, error)

Generates a new backup on the disk, moves it into the S3 bucket via the provided presigned URL, and then deletes the backup from the disk.

func (*S3Backup) Remove

func (s *S3Backup) Remove() error

Removes a backup from the system.

Jump to

Keyboard shortcuts

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