backup

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2025 License: AGPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AdapterType

type AdapterType string
const (
	LocalBackupAdapter AdapterType = "elytra"
	S3BackupAdapter    AdapterType = "s3"
	RusticLocalAdapter AdapterType = "rustic_local"
	RusticS3Adapter    AdapterType = "rustic_s3"
)

type ArchiveDetails

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

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

	// 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) SetClient

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

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
	// 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) (*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, 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) Remove

func (b *LocalBackup) Remove() error

Remove removes a backup from the system.

func (*LocalBackup) Restore

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

Restore will walk over the archive and call the callback function for each file encountered.

func (*LocalBackup) WithLogContext

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

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

type Reader

type Reader struct {
	io.Reader
}

Reader provides a wrapper around an existing io.Reader but implements io.Closer in order to satisfy an io.ReadCloser.

func (Reader) Close

func (Reader) Close() error

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 RusticBackup

type RusticBackup struct {
	Backup
	// contains filtered or unexported fields
}

func LocateRustic

func LocateRustic(client remote.Client, uuid string, backupType string, s3Creds *remote.S3Credentials, password string) (*RusticBackup, error)

LocateRustic finds a rustic backup by snapshot ID and returns a backup instance This function checks if the snapshot exists in the repository before returning

func LocateRusticLocal

func LocateRusticLocal(client remote.Client, uuid string, password string) (*RusticBackup, error)

LocateRusticLocal finds a rustic local backup by snapshot ID

func LocateRusticS3

func LocateRusticS3(client remote.Client, uuid string, s3Creds *remote.S3Credentials, password string) (*RusticBackup, error)

LocateRusticS3 finds a rustic S3 backup by snapshot ID

func LocateRusticWithPath

func LocateRusticWithPath(client remote.Client, serverUuid string, backupUuid string, backupType string, s3Creds *remote.S3Credentials, password string, repoPath string) (*RusticBackup, error)

LocateRusticWithPath finds a rustic backup by backup UUID tag with Panel-provided path

func NewRustic

func NewRustic(client remote.Client, uuid string, ignore string, backupType string, s3Creds *remote.S3Credentials, password string) *RusticBackup

NewRustic creates a new rustic backup instance

func NewRusticWithServerPath

func NewRusticWithServerPath(client remote.Client, serverUuid string, backupUuid string, ignore string, backupType string, s3Creds *remote.S3Credentials, password string, repoPath string) *RusticBackup

NewRusticWithServerPath creates a new rustic backup instance with explicit server and backup UUIDs

func (*RusticBackup) CanDownload

func (r *RusticBackup) CanDownload() bool

CanDownload returns true if this rustic backup can be downloaded as a tar.gz

func (*RusticBackup) Checksum

func (r *RusticBackup) Checksum() ([]byte, error)

Checksum returns a checksum for the backup

func (*RusticBackup) Details

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

Details returns backup details

func (*RusticBackup) DownloadTarGz

func (r *RusticBackup) DownloadTarGz(ctx context.Context, writer io.Writer) error

DownloadTarGz generates a tar.gz archive from the rustic snapshot and writes it to the provided writer

func (*RusticBackup) Generate

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

Generate creates a backup using rustic

func (*RusticBackup) Path

func (r *RusticBackup) Path() string

Path returns a placeholder path for rustic backups

func (*RusticBackup) Remove

func (r *RusticBackup) Remove() error

Remove removes a backup from the system.

func (*RusticBackup) Restore

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

Restore restores files from a rustic backup

func (*RusticBackup) SetClient

func (r *RusticBackup) SetClient(c remote.Client)

SetClient sets the API request client on the backup interface.

func (*RusticBackup) Size

func (r *RusticBackup) Size() (int64, error)

Size returns the size of the backup accounting for deduplication

func (*RusticBackup) WithLogContext

func (r *RusticBackup) WithLogContext(c map[string]any)

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

type RusticGroupMetadata

type RusticGroupMetadata struct {
	Hostname string   `json:"hostname"`
	Label    string   `json:"label"`
	Paths    []string `json:"paths"`
}

RusticGroupMetadata represents group metadata in rustic JSON output

type RusticRepoInfo

type RusticRepoInfo struct {
	Index struct {
		Blobs []struct {
			BlobType string `json:"blob_type"`
			Count    int    `json:"count"`
			Size     int64  `json:"size"`
			DataSize int64  `json:"data_size"`
		} `json:"blobs"`
	} `json:"index"`
}

RusticRepoInfo represents repository information from rustic repoinfo JSON output

func (*RusticRepoInfo) GetTotalDataSize

func (r *RusticRepoInfo) GetTotalDataSize() int64

GetTotalDataSize returns the total data size from all blobs

type RusticSnapshotGroup

type RusticSnapshotGroup [2]any // [0] = GroupMetadata, [1] = []Snapshot

RusticSnapshotGroup represents the nested array structure from rustic Format: [ [GroupMetadata, [Snapshot, ...]], ... ]

type RusticSnapshotInfo

type RusticSnapshotInfo struct {
	ID             string    `json:"id"`
	Time           time.Time `json:"time"`
	ProgramVersion string    `json:"program_version"`
	Tree           string    `json:"tree"`
	Paths          []string  `json:"paths"`
	Hostname       string    `json:"hostname"`
	Username       string    `json:"username"`
	UID            int       `json:"uid"`
	GID            int       `json:"gid"`
	Tags           []string  `json:"tags,omitempty"`
	Original       string    `json:"original,omitempty"`
	Summary        *struct {
		DataAdded       int64 `json:"data_added"`
		DataAddedPacked int64 `json:"data_added_packed"`
	} `json:"summary,omitempty"`
}

RusticSnapshotInfo represents snapshot information from rustic JSON output

type S3Backup

type S3Backup struct {
	Backup
}

func NewS3

func NewS3(client remote.Client, uuid 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 by requesting the Panel to delete it from S3.

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