Documentation
¶
Index ¶
- Constants
- func FormatFileSize(size int64) string
- func ValidateCronExpr(cronExpr string) error
- type BackupConfig
- type BackupConfigReq
- type BackupConfigResp
- type BackupHistory
- type BackupHistoryResp
- type COSStorage
- func (s *COSStorage) Delete(ctx context.Context, remotePath string) error
- func (s *COSStorage) GetPresignedURL(ctx context.Context, remotePath string, expires time.Duration) (string, error)
- func (s *COSStorage) List(ctx context.Context, prefix string) ([]string, error)
- func (s *COSStorage) TestConnection(ctx context.Context) error
- func (s *COSStorage) Upload(ctx context.Context, localPath, remotePath string) error
- type DiskChecker
- type IStorage
- type Manager
- type ProgressReader
- type Scheduler
- type Service
- func (s *Service) DeleteHistory(id int64) error
- func (s *Service) ExecuteBackup(backupID string) error
- func (s *Service) GetConfig() (*BackupConfig, error)
- func (s *Service) GetDownloadURL(id int64) (string, error)
- func (s *Service) GetHistoryList(pageIndex, pageSize int) ([]*BackupHistoryResp, int64, error)
- func (s *Service) IsRunning() bool
- func (s *Service) SaveConfig(cfg *BackupConfig) error
- func (s *Service) TestConnection() error
- func (s *Service) TriggerBackup() (string, error)
- type StorageConfig
Constants ¶
const ( BackupStatusPending = "pending" BackupStatusRunning = "running" BackupStatusSuccess = "success" BackupStatusFailed = "failed" )
BackupStatus 备份状态常量
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BackupConfig ¶
type BackupConfig struct {
ID int64 `json:"id"`
Enabled bool `json:"enabled"`
Prefix string `json:"prefix"` // 备份路径前缀
CronExpr string `json:"cron_expr"` // cron表达式
RetentionCount int `json:"retention_count"` // 保留数量
DataDir string `json:"data_dir"` // WuKongIM 数据目录
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
BackupConfig 备份配置模型(存储配置复用 ctx.GetConfig().COS)
type BackupConfigReq ¶
type BackupConfigReq struct {
Enabled *bool `json:"enabled,omitempty"`
Prefix string `json:"prefix,omitempty"`
CronExpr string `json:"cron_expr,omitempty"`
RetentionCount *int `json:"retention_count,omitempty"`
DataDir string `json:"data_dir,omitempty"`
}
BackupConfigReq 备份配置请求
type BackupConfigResp ¶
type BackupConfigResp struct {
Enabled bool `json:"enabled"`
Prefix string `json:"prefix"`
CronExpr string `json:"cron_expr"`
RetentionCount int `json:"retention_count"`
DataDir string `json:"data_dir"`
// 以下字段从 ctx.GetConfig() 读取,只读展示
StorageType string `json:"storage_type"`
Bucket string `json:"bucket"`
Region string `json:"region"`
}
BackupConfigResp 备份配置响应
type BackupHistory ¶
type BackupHistory struct {
ID int64 `json:"id"`
BackupID string `json:"backup_id"`
Status string `json:"status"` // pending/running/success/failed
FileName string `json:"file_name"`
FileSize int64 `json:"file_size"`
StoragePath string `json:"storage_path"`
StartedAt *time.Time `json:"started_at"`
FinishedAt *time.Time `json:"finished_at"`
ErrorMessage string `json:"error_message"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
BackupHistory 备份历史模型
type BackupHistoryResp ¶
type BackupHistoryResp struct {
ID int64 `json:"id"`
BackupID string `json:"backup_id"`
Status string `json:"status"`
FileName string `json:"file_name"`
FileSize int64 `json:"file_size"`
FileSizeStr string `json:"file_size_str"`
StoragePath string `json:"storage_path"`
StartedAt string `json:"started_at,omitempty"`
FinishedAt string `json:"finished_at,omitempty"`
ErrorMessage string `json:"error_message,omitempty"`
CreatedAt string `json:"created_at"`
}
BackupHistoryResp 备份历史响应
type COSStorage ¶
COSStorage 腾讯云 COS 存储(通过 S3 兼容协议)
func NewCOSStorage ¶
func NewCOSStorage(cfg *StorageConfig) (*COSStorage, error)
NewCOSStorage 创建 COS 存储实例
func (*COSStorage) Delete ¶
func (s *COSStorage) Delete(ctx context.Context, remotePath string) error
Delete 删除 COS 上的文件
func (*COSStorage) GetPresignedURL ¶
func (s *COSStorage) GetPresignedURL(ctx context.Context, remotePath string, expires time.Duration) (string, error)
GetPresignedURL 获取预签名下载 URL
func (*COSStorage) TestConnection ¶
func (s *COSStorage) TestConnection(ctx context.Context) error
TestConnection 测试 COS 连接
type DiskChecker ¶
type DiskChecker struct{}
DiskChecker 磁盘空间检查器
func (*DiskChecker) CheckAvailableSpace ¶
func (d *DiskChecker) CheckAvailableSpace(path string, requiredBytes int64) (available int64, sufficient bool, err error)
CheckAvailableSpace 检查目录可用空间是否满足需求 path: 要检查的目录路径 requiredBytes: 需要的字节数 返回: 可用空间(bytes), 是否满足需求, error
func (*DiskChecker) CheckBeforeBackup ¶
func (d *DiskChecker) CheckBeforeBackup(sourcePath, tempPath string) error
CheckBeforeBackup 备份前检查磁盘空间 sourcePath: 源数据目录 tempPath: 临时文件目录 (通常是 os.TempDir()) 返回: error 如果空间不足
func (*DiskChecker) EstimateArchiveSize ¶
func (d *DiskChecker) EstimateArchiveSize(sourcePath string, compressionRatio float64) (int64, error)
EstimateArchiveSize 估算压缩包大小 sourcePath: 源目录路径 compressionRatio: 压缩比 (0.0-1.0, 例如 0.5 表示压缩后为原大小的 50%)
type IStorage ¶
type IStorage interface {
// Upload 上传文件
Upload(ctx context.Context, localPath, remotePath string) error
// Delete 删除文件
Delete(ctx context.Context, remotePath string) error
// GetPresignedURL 获取预签名下载URL
GetPresignedURL(ctx context.Context, remotePath string, expires time.Duration) (string, error)
// TestConnection 测试连接
TestConnection(ctx context.Context) error
// List 列出文件
List(ctx context.Context, prefix string) ([]string, error)
}
IStorage 存储接口
type ProgressReader ¶
type ProgressReader struct {
// contains filtered or unexported fields
}
ProgressReader 进度读取器
func NewProgressReader ¶
func NewProgressReader(reader io.Reader, total int64, onProgress func(read, total int64)) *ProgressReader
type Service ¶
Service 备份服务
func (*Service) DeleteHistory ¶
DeleteHistory 删除备份历史
func (*Service) ExecuteBackup ¶
ExecuteBackup 执行备份
func (*Service) GetDownloadURL ¶
GetDownloadURL 获取下载链接
func (*Service) GetHistoryList ¶
func (s *Service) GetHistoryList(pageIndex, pageSize int) ([]*BackupHistoryResp, int64, error)
GetHistoryList 获取备份历史列表
func (*Service) SaveConfig ¶
func (s *Service) SaveConfig(cfg *BackupConfig) error
SaveConfig 保存备份配置
func (*Service) TestConnection ¶
TestConnection 测试存储连接(使用系统 COS 配置)
func (*Service) TriggerBackup ¶
TriggerBackup 手动触发备份