Documentation
¶
Index ¶
- 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 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 Reader
- type RestoreCallback
- 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{})
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
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 {
// 此備份物件的 UUID。此值必須與面板實例中的某個備份對應。
Uuid string `json:"uuid"`
// 產生此備份時應忽略的檔案陣列。此格式應與標準的 .gitignore
// 結構相容。
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 將目前儲存於磁碟中壓縮檔的校驗碼與大小回傳給呼叫端。
func (*Backup) Identifier ¶
type BackupInterface ¶
type BackupInterface interface {
// SetClient 在備份介面上設定 API 請求客戶端。
SetClient(remote.Client)
// Identifier 回傳此備份在面板實例中所追蹤的 UUID。
Identifier() string
// WithLogContext 為此備份的日誌輸出附加額外的內容資訊。
WithLogContext(map[string]interface{})
// Generate 在特定實作所設定的來源中建立一份備份。
Generate(context.Context, *filesystem.Filesystem, string) (*ArchiveDetails, error)
// Ignored 回傳此備份實例被忽略的檔案。
Ignored() string
// Checksum 回傳已產生備份的 SHA1 校驗碼。
Checksum() ([]byte, error)
// Size 回傳已產生備份的大小。
Size() (int64, error)
// Path 回傳此機器上備份的路徑。這通常不是備份最終的儲存位置,
// 只是我們在移動至最終位置之前用來存放它的位置。
Path() string
// Details 回傳此壓縮檔的詳細資訊。
Details(context.Context, []remote.BackupPart) (*ArchiveDetails, error)
// Remove 移除一個備份檔案。
Remove() error
// Restore 會在備份準備從給定來源還原至磁碟時被呼叫。
// 並非每種備份實作都支援此功能,也並非每種實作
// 都需要提供 reader。
Restore(context.Context, io.Reader, RestoreCallback) error
}
noinspection GoNameStartsWithPackageName
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 Reader ¶
Reader provides a wrapper around an existing io.Reader but implements io.Closer in order to satisfy an io.ReadCloser.
type RestoreCallback ¶
RestoreCallback 是一個通用的還原回呼函式,本機與遠端備份皆會使用, 用於讓檔案得以被還原。
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) 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.