Documentation
¶
Index ¶
- Constants
- type AdapterType
- type ArchiveDetails
- type Backup
- func (b *Backup) Checksum() ([]byte, error)
- func (b *Backup) Details(ctx context.Context, parts []remote.BackupPart) (*ArchiveDetails, error)
- func (b *Backup) Identifier() string
- func (b *Backup) Ignored() string
- func (b *Backup) Path() string
- func (b *Backup) SetClient(c remote.Client)
- func (b *Backup) Size() (int64, error)
- type BackupInterface
- type Config
- type LocalBackup
- func (b *LocalBackup) Generate(ctx context.Context, fsys *filesystem.Filesystem, ignore string) (*ArchiveDetails, error)
- func (b *LocalBackup) Remove() error
- func (b *LocalBackup) Restore(ctx context.Context, _ io.Reader, callback RestoreCallback) error
- func (b *LocalBackup) WithLogContext(c map[string]interface{})
- type LocalRepository
- func (r *LocalRepository) Close() error
- func (r *LocalRepository) CreateSnapshot(ctx context.Context, path string, tags map[string]string, ignoreFile string) (*Snapshot, error)
- func (r *LocalRepository) DeleteSnapshot(ctx context.Context, id string) error
- func (r *LocalRepository) Destroy(ctx context.Context) error
- func (r *LocalRepository) Exists(ctx context.Context) (bool, error)
- func (r *LocalRepository) GetRepositorySize(ctx context.Context) (int64, error)
- func (r *LocalRepository) GetSnapshot(ctx context.Context, id string) (*Snapshot, error)
- func (r *LocalRepository) GetSnapshotSizes(ctx context.Context) (map[string]int64, error)
- func (r *LocalRepository) Info(ctx context.Context) (*RepositoryInfo, error)
- func (r *LocalRepository) Initialize(ctx context.Context) error
- func (r *LocalRepository) ListSnapshots(ctx context.Context, filter map[string]string) ([]*Snapshot, error)
- func (r *LocalRepository) RestoreSnapshot(ctx context.Context, snapshotID string, targetPath string, sourcePath string) error
- type Reader
- type Repository
- type RepositoryInfo
- type RestoreCallback
- type RusticBackup
- func LocateRusticBackup(client remote.Client, cfg Config, snapshotID string) (*RusticBackup, error)
- func LocateRusticBySnapshotID(client remote.Client, serverUuid string, snapshotID string, backupType string, ...) (*RusticBackup, error)
- func NewRustic(client remote.Client, uuid string, ignore string, backupType string, ...) *RusticBackup
- func NewRusticBackup(client remote.Client, cfg Config) (*RusticBackup, error)
- func NewRusticWithServerPath(client remote.Client, serverUuid string, backupUuid string, ignore string, ...) *RusticBackup
- func (r *RusticBackup) CanDownload() bool
- func (r *RusticBackup) Checksum() ([]byte, error)
- func (r *RusticBackup) Close() error
- func (r *RusticBackup) Details(ctx context.Context, parts []remote.BackupPart) (*ArchiveDetails, error)
- func (r *RusticBackup) DownloadTarGz(ctx context.Context, writer io.Writer) error
- func (r *RusticBackup) Generate(ctx context.Context, fsys *filesystem.Filesystem, ignore string) (*ArchiveDetails, error)
- func (b *RusticBackup) GetRepository() Repository
- func (r *RusticBackup) Path() string
- func (r *RusticBackup) Remove() error
- func (r *RusticBackup) Restore(ctx context.Context, reader io.Reader, callback RestoreCallback) error
- func (r *RusticBackup) Size() (int64, error)
- func (r *RusticBackup) WithLogContext(ctx map[string]interface{})
- type S3Backup
- func (s *S3Backup) Generate(ctx context.Context, fsys *filesystem.Filesystem, ignore string) (*ArchiveDetails, error)
- func (s *S3Backup) Remove() error
- func (s *S3Backup) Restore(ctx context.Context, r io.Reader, callback RestoreCallback) error
- func (s *S3Backup) WithLogContext(c map[string]interface{})
- type S3Config
- type S3Repository
- func (r *S3Repository) Close() error
- func (r *S3Repository) CreateSnapshot(ctx context.Context, path string, tags map[string]string, ignoreFile string) (*Snapshot, error)
- func (r *S3Repository) DeleteSnapshot(ctx context.Context, id string) error
- func (r *S3Repository) Destroy(ctx context.Context) error
- func (r *S3Repository) Exists(ctx context.Context) (bool, error)
- func (r *S3Repository) GetRepositorySize(ctx context.Context) (int64, error)
- func (r *S3Repository) GetSnapshot(ctx context.Context, id string) (*Snapshot, error)
- func (r *S3Repository) GetSnapshotSizes(ctx context.Context) (map[string]int64, error)
- func (r *S3Repository) Info(ctx context.Context) (*RepositoryInfo, error)
- func (r *S3Repository) Initialize(ctx context.Context) error
- func (r *S3Repository) ListSnapshots(ctx context.Context, filter map[string]string) ([]*Snapshot, error)
- func (r *S3Repository) RestoreSnapshot(ctx context.Context, snapshotID string, targetPath string, sourcePath string) error
- type Snapshot
- type SnapshotInfo
Constants ¶
const ( DefaultTimeout = 30 * time.Minute SnapshotIDPattern = `^[a-f0-9]{8}([a-f0-9]{56})?$` SnapshotSavedPattern = `snapshot\s+([a-f0-9]{8,64})\s+successfully\s+saved` TempPrefix = "elytra-rustic-" SecureFileMode = 0600 SecureDirMode = 0700 )
Constants for rustic operations
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) 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 ¶
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 Config ¶ added in v1.3.0
type Config struct {
BackupUUID string
ServerUUID string
Password string
BackupType string // "local" or "s3"
S3Config *S3Config `json:"s3_config,omitempty"`
LocalPath string `json:"local_path,omitempty"`
IgnorePatterns string `json:"ignore_patterns,omitempty"`
Tags map[string]string `json:"tags,omitempty"`
}
Config represents a complete rustic backup configuration
type LocalBackup ¶
type LocalBackup struct {
Backup
}
func LocateLocal ¶
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 (*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 LocalRepository ¶ added in v1.3.0
type LocalRepository struct {
// contains filtered or unexported fields
}
LocalRepository implements Repository for local filesystem storage
func NewLocalRepository ¶ added in v1.3.0
func NewLocalRepository(cfg Config) (*LocalRepository, error)
NewLocalRepository creates a new local repository instance
func (*LocalRepository) Close ¶ added in v1.3.0
func (r *LocalRepository) Close() error
Close cleans up resources (no-op for local repository)
func (*LocalRepository) CreateSnapshot ¶ added in v1.3.0
func (r *LocalRepository) CreateSnapshot(ctx context.Context, path string, tags map[string]string, ignoreFile string) (*Snapshot, error)
CreateSnapshot creates a new backup snapshot
func (*LocalRepository) DeleteSnapshot ¶ added in v1.3.0
func (r *LocalRepository) DeleteSnapshot(ctx context.Context, id string) error
DeleteSnapshot deletes a snapshot by ID
func (*LocalRepository) Destroy ¶ added in v1.3.0
func (r *LocalRepository) Destroy(ctx context.Context) error
Destroy completely removes the repository and all its data
func (*LocalRepository) Exists ¶ added in v1.3.0
func (r *LocalRepository) Exists(ctx context.Context) (bool, error)
Exists checks if the repository exists and is accessible
func (*LocalRepository) GetRepositorySize ¶ added in v1.3.0
func (r *LocalRepository) GetRepositorySize(ctx context.Context) (int64, error)
GetRepositorySize returns the total size of the repository in bytes
func (*LocalRepository) GetSnapshot ¶ added in v1.3.0
GetSnapshot retrieves a snapshot by ID
func (*LocalRepository) GetSnapshotSizes ¶ added in v1.3.0
GetSnapshotSizes returns the actual size of each snapshot in the repository
func (*LocalRepository) Info ¶ added in v1.3.0
func (r *LocalRepository) Info(ctx context.Context) (*RepositoryInfo, error)
Info returns repository information
func (*LocalRepository) Initialize ¶ added in v1.3.0
func (r *LocalRepository) Initialize(ctx context.Context) error
Initialize creates the local repository if it doesn't exist
func (*LocalRepository) ListSnapshots ¶ added in v1.3.0
func (r *LocalRepository) ListSnapshots(ctx context.Context, filter map[string]string) ([]*Snapshot, error)
ListSnapshots lists all snapshots matching the filter
func (*LocalRepository) RestoreSnapshot ¶ added in v1.3.0
func (r *LocalRepository) RestoreSnapshot(ctx context.Context, snapshotID string, targetPath string, sourcePath string) error
RestoreSnapshot restores a snapshot to the target path
type Reader ¶
Reader provides a wrapper around an existing io.Reader but implements io.Closer in order to satisfy an io.ReadCloser.
type Repository ¶ added in v1.3.0
type Repository interface {
// Repository lifecycle
Initialize(ctx context.Context) error
Exists(ctx context.Context) (bool, error)
Info(ctx context.Context) (*RepositoryInfo, error)
// Snapshot operations
CreateSnapshot(ctx context.Context, path string, tags map[string]string, ignoreFile string) (*Snapshot, error)
GetSnapshot(ctx context.Context, id string) (*Snapshot, error)
ListSnapshots(ctx context.Context, filter map[string]string) ([]*Snapshot, error)
DeleteSnapshot(ctx context.Context, id string) error
// Data operations
RestoreSnapshot(ctx context.Context, snapshotID string, targetPath string, sourcePath string) error
GetRepositorySize(ctx context.Context) (int64, error)
GetSnapshotSizes(ctx context.Context) (map[string]int64, error)
// Maintenance
Destroy(ctx context.Context) error
// Cleanup
Close() error
}
Repository defines the interface for rustic repository operations
type RepositoryInfo ¶ added in v1.3.0
type RepositoryInfo struct {
TotalSize int64 `json:"total_size"`
SnapshotCount int `json:"snapshot_count"`
LastUpdate time.Time `json:"last_update"`
}
RepositoryInfo contains repository metadata
type RestoreCallback ¶
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
}
RusticBackup implements BackupInterface using rustic
func LocateRusticBackup ¶ added in v1.3.0
LocateRusticBackup finds an existing backup by snapshot ID
func LocateRusticBySnapshotID ¶ added in v1.3.0
func LocateRusticBySnapshotID(client remote.Client, serverUuid string, snapshotID string, backupType string, s3Creds *remote.S3Credentials, password string, repoPath string) (*RusticBackup, error)
LocateRusticBySnapshotID finds a rustic backup by snapshot ID (preferred method)
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 (legacy interface) somebody please refactor this - ellie
func NewRusticBackup ¶ added in v1.3.0
func NewRusticBackup(client remote.Client, cfg Config) (*RusticBackup, error)
NewRusticBackup creates a new rustic backup with the given configuration
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 server path (legacy interface)
func (*RusticBackup) CanDownload ¶
func (r *RusticBackup) CanDownload() bool
CanDownload returns true if this 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) Close ¶ added in v1.3.0
func (r *RusticBackup) Close() error
Close cleans up resources
func (*RusticBackup) Details ¶
func (r *RusticBackup) Details(ctx context.Context, parts []remote.BackupPart) (*ArchiveDetails, error)
Details returns backup details
func (*RusticBackup) DownloadTarGz ¶
DownloadTarGz generates a tar.gz archive from the backup 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 new backup NOTE: The caller is responsible for calling Close() after using the backup and repository
func (*RusticBackup) GetRepository ¶ added in v1.3.0
func (b *RusticBackup) GetRepository() Repository
GetRepository returns the underlying repository for this backup
func (*RusticBackup) Path ¶
func (r *RusticBackup) Path() string
Path returns a placeholder path for rustic backups
func (*RusticBackup) Restore ¶
func (r *RusticBackup) Restore(ctx context.Context, reader io.Reader, callback RestoreCallback) error
Restore restores files from backup
func (*RusticBackup) Size ¶
func (r *RusticBackup) Size() (int64, error)
Size returns the backup size
func (*RusticBackup) WithLogContext ¶
func (r *RusticBackup) WithLogContext(ctx map[string]interface{})
WithLogContext attaches additional context to the log output for this backup
type S3Backup ¶
type S3Backup struct {
Backup
}
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 ¶
Remove removes a backup from the system by requesting the Panel to delete it from S3.
func (*S3Backup) Restore ¶
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 ¶
WithLogContext attaches additional context to the log output for this backup.
type S3Config ¶ added in v1.3.0
type S3Config struct {
Bucket string `json:"bucket"`
Region string `json:"region"`
Endpoint string `json:"endpoint,omitempty"`
AccessKeyID string `json:"access_key_id"`
SecretAccessKey string `json:"secret_access_key"`
SessionToken string `json:"session_token,omitempty"`
ForcePathStyle bool `json:"force_path_style"`
}
S3Config holds S3-specific configuration
type S3Repository ¶ added in v1.3.0
type S3Repository struct {
// contains filtered or unexported fields
}
S3Repository implements Repository for S3 storage
func NewS3Repository ¶ added in v1.3.0
func NewS3Repository(cfg Config) (*S3Repository, error)
NewS3Repository creates a new S3 repository instance
func (*S3Repository) Close ¶ added in v1.3.0
func (r *S3Repository) Close() error
Close cleans up temporary files and directories
func (*S3Repository) CreateSnapshot ¶ added in v1.3.0
func (r *S3Repository) CreateSnapshot(ctx context.Context, path string, tags map[string]string, ignoreFile string) (*Snapshot, error)
CreateSnapshot creates a new backup snapshot
func (*S3Repository) DeleteSnapshot ¶ added in v1.3.0
func (r *S3Repository) DeleteSnapshot(ctx context.Context, id string) error
DeleteSnapshot deletes a snapshot by ID with retry mechanism for pruning
func (*S3Repository) Destroy ¶ added in v1.3.0
func (r *S3Repository) Destroy(ctx context.Context) error
Destroy completely removes all repository data from S3
func (*S3Repository) Exists ¶ added in v1.3.0
func (r *S3Repository) Exists(ctx context.Context) (bool, error)
Exists checks if the S3 repository exists and is accessible
func (*S3Repository) GetRepositorySize ¶ added in v1.3.0
func (r *S3Repository) GetRepositorySize(ctx context.Context) (int64, error)
GetRepositorySize returns the total size of the repository in bytes
func (*S3Repository) GetSnapshot ¶ added in v1.3.0
GetSnapshot retrieves a snapshot by ID
func (*S3Repository) GetSnapshotSizes ¶ added in v1.3.0
GetSnapshotSizes returns the actual size of each snapshot in the repository
func (*S3Repository) Info ¶ added in v1.3.0
func (r *S3Repository) Info(ctx context.Context) (*RepositoryInfo, error)
Info returns S3 repository information
func (*S3Repository) Initialize ¶ added in v1.3.0
func (r *S3Repository) Initialize(ctx context.Context) error
Initialize creates the S3 repository if it doesn't exist
func (*S3Repository) ListSnapshots ¶ added in v1.3.0
func (r *S3Repository) ListSnapshots(ctx context.Context, filter map[string]string) ([]*Snapshot, error)
ListSnapshots lists all snapshots matching the filter
func (*S3Repository) RestoreSnapshot ¶ added in v1.3.0
func (r *S3Repository) RestoreSnapshot(ctx context.Context, snapshotID string, targetPath string, sourcePath string) error
RestoreSnapshot restores a snapshot to the target path
type Snapshot ¶ added in v1.3.0
type Snapshot struct {
ID string `json:"id"`
BackupUUID string `json:"backup_uuid"`
Size int64 `json:"size"`
CreatedAt time.Time `json:"created_at"`
Tags map[string]string `json:"tags"`
Paths []string `json:"paths"`
}
Snapshot represents a backup snapshot
type SnapshotInfo ¶ added in v1.3.0
type SnapshotInfo 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"`
Summary *struct {
DataAdded int64 `json:"data_added"`
DataAddedPacked int64 `json:"data_added_packed"`
} `json:"summary,omitempty"`
}
SnapshotInfo represents detailed snapshot metadata from rustic JSON output