backup

package
v1.0.0-rc.4 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: MIT Imports: 23 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	// PelicanConfigFile is the name of the server configuration stored as the
	// first entry of a backup archive.
	PelicanConfigFile = ".pelicanconfig"
	// MaxPelicanConfigSize is the largest server configuration that is stored, the
	// Panel does not read a larger one.
	MaxPelicanConfigSize = 64 * 1024
)

Variables

This section is empty.

Functions

func IsPelicanConfigEntry

func IsPelicanConfigEntry(info fs.FileInfo) bool

IsPelicanConfigEntry reports whether an archive entry is the server configuration written by Wings, rather than a file from the server's directory.

func LegacyLocalArchives

func LegacyLocalArchives() (count int, size int64, err error)

LegacyLocalArchives returns the number and total size of local backups still stored in the legacy location, directly in the root of the backup directory.

Types

type AdapterType

type AdapterType string
const (
	LocalBackupAdapter AdapterType = "wings"
	S3BackupAdapter    AdapterType = "s3"
)

type ArchiveDetails

type ArchiveDetails struct {
	Checksum     string              `json:"checksum"`
	ChecksumType string              `json:"checksum_type"`
	Size         int64               `json:"size"`
	Parts        []remote.BackupPart `json:"parts"`
}

func (*ArchiveDetails) ToRequest

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

ToRequest 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"`

	// The UUID of the server the backup is associated with.
	ServerUuid string `json:"server_uuid"`

	// An array of files to ignore when generating this backup. This should be
	// compatible with a standard .gitignore structure.
	Ignore string `json:"ignore"`
	// contains filtered or unexported fields
}

func (*Backup) Checksum

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

Checksum returns the SHA256 checksum of a backup.

func (*Backup) Details

func (b *Backup) Details(ctx context.Context, parts []remote.BackupPart) (*ArchiveDetails, error)

Details returns both the checksum and size of the archive currently stored on the disk to the caller.

func (*Backup) Identifier

func (b *Backup) Identifier() string

func (*Backup) Ignored

func (b *Backup) Ignored() string

func (*Backup) Path

func (b *Backup) Path() string

Path returns the path for this specific backup.

func (*Backup) ServerId

func (b *Backup) ServerId() string

func (*Backup) SetClient

func (b *Backup) SetClient(c remote.Client)

func (*Backup) SetPelicanConfig

func (b *Backup) SetPelicanConfig(config []byte)

SetPelicanConfig sets the server configuration stored as the first entry of the archive. Nothing is stored when it is empty.

func (*Backup) Size

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

Size returns the size of the generated backup.

type BackupInterface

type BackupInterface interface {
	// SetClient sets the API request client on the backup interface.
	SetClient(remote.Client)
	// Identifier returns the UUID of this backup as tracked by the panel
	// instance.
	Identifier() string
	// ServerId returns the UUID of the server the backup is associated with
	ServerId() string
	// WithLogContext attaches additional context to the log output for this
	// backup.
	WithLogContext(map[string]interface{})
	// Generate creates a backup in whatever the configured source for the
	// specific implementation is.
	Generate(context.Context, *filesystem.Filesystem, string) (*ArchiveDetails, error)
	// Ignored returns the ignored files for this backup instance.
	Ignored() string
	// Checksum returns a SHA1 checksum for the generated backup.
	Checksum() ([]byte, error)
	// Size returns the size of the generated backup.
	Size() (int64, error)
	// Path 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
	// Details returns details about the archive.
	Details(context.Context, []remote.BackupPart) (*ArchiveDetails, error)
	// Remove removes a backup file.
	Remove() error
	// Restore is called when a backup is ready to be restored to the disk from
	// the given source. Not every backup implementation will support this nor
	// will every implementation require a reader be provided.
	Restore(context.Context, io.Reader, RestoreCallback) error
}

noinspection GoNameStartsWithPackageName

type LocalBackup

type LocalBackup struct {
	Backup
}

func LocateLocal

func LocateLocal(client remote.Client, uuid string, suuid string) (*LocalBackup, os.FileInfo, error)

LocateLocal finds 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 NewLocal

func NewLocal(client remote.Client, uuid string, suuid string, ignore string) *LocalBackup

func (*LocalBackup) Generate

func (b *LocalBackup) Generate(ctx context.Context, fsys *filesystem.Filesystem, ignore string) (*ArchiveDetails, error)

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

func (*LocalBackup) MigrateLegacy

func (b *LocalBackup) MigrateLegacy() error

MigrateLegacy moves this backup from its legacy location in the root of the backup directory into the server's backup directory, if it only exists at the legacy location. It is a no-op when the backup already exists at its current location or does not exist at the legacy one.

func (*LocalBackup) Open

func (b *LocalBackup) Open() (*os.File, error)

Open opens the backup's archive for reading. A restore that reads the archive more than once can hold it open, so that deleting the backup part way through cannot take it away.

func (*LocalBackup) Remove

func (b *LocalBackup) Remove() error

Remove removes a backup from the system.

func (*LocalBackup) Restore

func (b *LocalBackup) Restore(ctx context.Context, r io.Reader, callback RestoreCallback) error

Restore will walk over the archive and call the callback function for each file encountered. The archive is read from r if it is given, such as one returned by Open, and otherwise opened from the backup's path.

func (*LocalBackup) WithLogContext

func (b *LocalBackup) WithLogContext(c map[string]interface{})

WithLogContext attaches additional context to the log output for this backup.

type RestoreCallback

type RestoreCallback func(file string, info fs.FileInfo, r io.ReadCloser) error

RestoreCallback is a generic restoration callback that exists for both local and remote backups allowing the files to be restored.

type S3Backup

type S3Backup struct {
	Backup
}

func NewS3

func NewS3(client remote.Client, uuid string, suuid string, ignore string) *S3Backup

func (*S3Backup) Generate

func (s *S3Backup) Generate(ctx context.Context, fsys *filesystem.Filesystem, ignore string) (*ArchiveDetails, error)

Generate creates 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

Remove removes a backup from the system.

func (*S3Backup) Restore

func (s *S3Backup) Restore(ctx context.Context, r io.Reader, callback RestoreCallback) error

Restore will read from the provided reader assuming that it is a gzipped tar reader. When a file is encountered in the archive the callback function will be triggered. If the callback returns an error the entire process is stopped, otherwise this function will run until all files have been written.

This restoration uses a workerpool to use up to the number of CPUs available on the machine when writing files to the disk.

func (*S3Backup) WithLogContext

func (s *S3Backup) WithLogContext(c map[string]interface{})

WithLogContext attaches additional context to the log output for this backup.

Jump to

Keyboard shortcuts

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