Documentation
¶
Overview ¶
Package backup 提供备份还原功能
Package backup 提供备份还原功能 ¶
Package backup 提供备份还原功能 ¶
Package backup 提供备份还原功能 ¶
Package backup 提供备份还原功能 ¶
Package backup 提供系统备份和还原功能 ¶
Package backup 提供备份还原功能
Index ¶
- Constants
- func AutoMigrate(db *gorm.DB) error
- func IsEncrypted(filePath string) (bool, error)
- type BackupOverview
- type BackupRecord
- type BackupRecordModel
- type BackupStatus
- type BackupTask
- type BackupTaskModel
- type BackupType
- type ChunkAckPayload
- type ChunkPayload
- type ConfigExportRequest
- type ConfigImportRequest
- type ConnectToSourceRequest
- type CreateTaskRequest
- type Encryptor
- type ExportableConfig
- type FileEntry
- type FileManifest
- type GeneratePairCodeRequest
- type GeneratePairCodeResponse
- type Handler
- func (h *Handler) CreateTask(c *gin.Context)
- func (h *Handler) DeleteRecord(c *gin.Context)
- func (h *Handler) DeleteTask(c *gin.Context)
- func (h *Handler) ExportConfig(c *gin.Context)
- func (h *Handler) GetExportableConfigs(c *gin.Context)
- func (h *Handler) GetOverview(c *gin.Context)
- func (h *Handler) GetRecord(c *gin.Context)
- func (h *Handler) GetRestoreStatus(c *gin.Context)
- func (h *Handler) GetTask(c *gin.Context)
- func (h *Handler) ImportConfig(c *gin.Context)
- func (h *Handler) ListRecords(c *gin.Context)
- func (h *Handler) ListTasks(c *gin.Context)
- func (h *Handler) RegisterRoutes(r *gin.RouterGroup)
- func (h *Handler) Restore(c *gin.Context)
- func (h *Handler) RunTask(c *gin.Context)
- func (h *Handler) TestTarget(c *gin.Context)
- func (h *Handler) UpdateTask(c *gin.Context)
- type HandshakePayload
- type IncrementalBackupInfo
- type ListRecordsRequest
- type ListTasksRequest
- type LocalTarget
- func (t *LocalTarget) Configure(config string) error
- func (t *LocalTarget) Delete(remotePath string) error
- func (t *LocalTarget) Download(remotePath, localPath string, progress func(int)) error
- func (t *LocalTarget) List() ([]RemoteFile, error)
- func (t *LocalTarget) Test() *TargetTestResponse
- func (t *LocalTarget) Upload(localPath, remoteName string, progress func(int)) (string, error)
- type LocalTargetConfig
- type MigrateContentSelection
- type MigrateHandler
- func (h *MigrateHandler) CancelSession(c *gin.Context)
- func (h *MigrateHandler) ConnectToSource(c *gin.Context)
- func (h *MigrateHandler) GeneratePairCode(c *gin.Context)
- func (h *MigrateHandler) GetProgress(c *gin.Context)
- func (h *MigrateHandler) GetSession(c *gin.Context)
- func (h *MigrateHandler) RegisterMigrateRoutes(r *gin.RouterGroup)
- func (h *MigrateHandler) StartTransfer(c *gin.Context)
- func (h *MigrateHandler) ValidatePairCode(c *gin.Context)
- func (h *MigrateHandler) WebSocketHandler(c *gin.Context)
- type MigrateProgress
- type MigrateSession
- type MigrateSessionRole
- type MigrateSessionStatus
- type MigrationContent
- type MigrationExportRequest
- type MigrationImportRequest
- type MigrationItemResult
- type MigrationPackage
- type MigrationResult
- type MigrationService
- type Module
- func (m *Module) Dependencies() []string
- func (m *Module) ID() string
- func (m *Module) Init(ctx *module.Context) error
- func (m *Module) Name() string
- func (m *Module) RegisterRoutes(router *gin.RouterGroup)
- func (m *Module) Start() error
- func (m *Module) Stop() error
- func (m *Module) Version() string
- type MsgType
- type P2PMessage
- type P2PMigrateService
- func (p *P2PMigrateService) CancelSession(sessionID string) error
- func (p *P2PMigrateService) ConnectWithPairCode(pairCode, targetURL string) (*MigrateSession, error)
- func (p *P2PMigrateService) GeneratePairCode() (*MigrateSession, error)
- func (p *P2PMigrateService) GetProgress(sessionID string) (*MigrateProgress, error)
- func (p *P2PMigrateService) GetSession(sessionID string) (*MigrateSession, error)
- func (p *P2PMigrateService) GetSessionByPairCode(pairCode string) (*MigrateSession, error)
- func (p *P2PMigrateService) HandleWebSocket(w http.ResponseWriter, r *http.Request, pairCode string) error
- func (p *P2PMigrateService) StartTransfer(sessionID string, content *MigrateContentSelection) error
- func (p *P2PMigrateService) ValidatePairCode(pairCode string) (*MigrateSession, error)
- type ProgressReader
- type RemoteFile
- type RestoreRecordModel
- type RestoreRequest
- type RestoreStatus
- type S3Target
- func (t *S3Target) Configure(configStr string) error
- func (t *S3Target) Delete(remotePath string) error
- func (t *S3Target) Download(remotePath, localPath string, progress func(int)) error
- func (t *S3Target) List() ([]RemoteFile, error)
- func (t *S3Target) Test() *TargetTestResponse
- func (t *S3Target) Upload(localPath, remoteName string, progress func(int)) (string, error)
- type S3TargetConfig
- type SFTPTarget
- func (t *SFTPTarget) Configure(config string) error
- func (t *SFTPTarget) Delete(remotePath string) error
- func (t *SFTPTarget) Download(remotePath, localPath string, progress func(int)) error
- func (t *SFTPTarget) List() ([]RemoteFile, error)
- func (t *SFTPTarget) Test() *TargetTestResponse
- func (t *SFTPTarget) Upload(localPath, remoteName string, progress func(int)) (string, error)
- type SFTPTargetConfig
- type Scheduler
- type Service
- func (s *Service) CreateTask(req *CreateTaskRequest) (*BackupTask, error)
- func (s *Service) DeleteRecord(id string) error
- func (s *Service) DeleteTask(id string) error
- func (s *Service) ExportConfig(req *ConfigExportRequest) ([]byte, error)
- func (s *Service) GetExportableConfigs() []ExportableConfig
- func (s *Service) GetOverview() (*BackupOverview, error)
- func (s *Service) GetRecord(id string) (*BackupRecord, error)
- func (s *Service) GetRestoreStatus(id string) (*RestoreStatus, error)
- func (s *Service) GetTask(id string) (*BackupTask, error)
- func (s *Service) ImportConfig(data []byte, req *ConfigImportRequest) error
- func (s *Service) ListRecords(req *ListRecordsRequest) ([]*BackupRecord, int64, error)
- func (s *Service) ListTasks(req *ListTasksRequest) ([]*BackupTask, int64, error)
- func (s *Service) RegisterTarget(t TargetType, target Target)
- func (s *Service) Restore(req *RestoreRequest) (*RestoreStatus, error)
- func (s *Service) RunTask(taskID string) (*BackupRecord, error)
- func (s *Service) SetEncryptionPassword(password string)
- func (s *Service) SetNotifyCallback(callback func(title, content string, isError bool))
- func (s *Service) TestTarget(req *TargetTestRequest) *TargetTestResponse
- func (s *Service) UpdateTask(id string, req *UpdateTaskRequest) (*BackupTask, error)
- type StartTransferRequest
- type Target
- type TargetTestRequest
- type TargetTestResponse
- type TargetType
- type UpdateTaskRequest
- type ValidatePairCodeRequest
- type WebDAVTarget
- func (t *WebDAVTarget) Configure(config string) error
- func (t *WebDAVTarget) Delete(remotePath string) error
- func (t *WebDAVTarget) Download(remotePath, localPath string, progress func(int)) error
- func (t *WebDAVTarget) List() ([]RemoteFile, error)
- func (t *WebDAVTarget) Test() *TargetTestResponse
- func (t *WebDAVTarget) Upload(localPath, remoteName string, progress func(int)) (string, error)
- type WebDAVTargetConfig
Constants ¶
const ( PairCodeLength = 9 // ABC-123-XYZ 格式 PairCodeExpiry = 10 * time.Minute ChunkSize = 4 * 1024 * 1024 // 4MB 分块 MaxConcurrentTx = 3 // 最大并发传输数 HeartbeatInterval = 30 * time.Second )
配对码相关常量
const ( ModuleID = "backup" ModuleName = "备份还原" ModuleVersion = "1.0.0" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BackupOverview ¶
type BackupOverview struct {
TotalTasks int `json:"total_tasks"`
EnabledTasks int `json:"enabled_tasks"`
TotalRecords int `json:"total_records"`
TotalSize int64 `json:"total_size"`
LastBackupAt *time.Time `json:"last_backup_at,omitempty"`
NextBackupAt *time.Time `json:"next_backup_at,omitempty"`
SuccessCount int `json:"success_count"`
FailedCount int `json:"failed_count"`
}
BackupOverview 备份概览
type BackupRecord ¶
type BackupRecord struct {
ID string `json:"id"`
TaskID string `json:"task_id"`
TaskName string `json:"task_name,omitempty"` // 关联显示
Type BackupType `json:"type"`
Size int64 `json:"size"` // 备份大小(字节)
FileCount int `json:"file_count"` // 文件数量
FilePath string `json:"file_path"` // 备份文件路径
Checksum string `json:"checksum"` // SHA256
Status BackupStatus `json:"status"`
Progress int `json:"progress"` // 进度 0-100
Message string `json:"message"` // 状态消息
Error string `json:"error,omitempty"`
StartedAt time.Time `json:"started_at"`
CompletedAt *time.Time `json:"completed_at,omitempty"`
}
BackupRecord 备份记录
type BackupRecordModel ¶
type BackupRecordModel struct {
ID string `gorm:"primaryKey;size:36"`
TaskID string `gorm:"not null;size:36;index"`
Type string `gorm:"not null;size:20"`
Size int64 `gorm:"default:0"`
FileCount int `gorm:"default:0"`
FilePath string `gorm:"size:500"`
Checksum string `gorm:"size:64"` // SHA256
Status string `gorm:"not null;size:20;index"`
Progress int `gorm:"default:0"`
Message string `gorm:"size:500"`
Error string `gorm:"type:text"`
StartedAt time.Time `gorm:"not null"`
CompletedAt *time.Time
CreatedAt time.Time `gorm:"autoCreateTime"`
}
BackupRecordModel 备份记录数据库模型
func (BackupRecordModel) TableName ¶
func (BackupRecordModel) TableName() string
func (*BackupRecordModel) ToBackupRecord ¶
func (m *BackupRecordModel) ToBackupRecord() *BackupRecord
ToBackupRecord 转换为 BackupRecord
type BackupStatus ¶
type BackupStatus string
BackupStatus 备份状态
const ( BackupStatusPending BackupStatus = "pending" BackupStatusRunning BackupStatus = "running" BackupStatusSuccess BackupStatus = "success" BackupStatusFailed BackupStatus = "failed" BackupStatusCancelled BackupStatus = "cancelled" )
type BackupTask ¶
type BackupTask struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
Type BackupType `json:"type"`
Sources []string `json:"sources"` // 备份源路径
TargetType TargetType `json:"target_type"` // 目标类型
TargetConfig string `json:"target_config"` // 目标配置 JSON
Schedule string `json:"schedule"` // cron 表达式,为空则手动触发
Retention int `json:"retention"` // 保留份数
Compression bool `json:"compression"` // 是否压缩
Encryption bool `json:"encryption"` // 是否加密
Enabled bool `json:"enabled"`
LastRunAt *time.Time `json:"last_run_at,omitempty"`
NextRunAt *time.Time `json:"next_run_at,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
BackupTask 备份任务
type BackupTaskModel ¶
type BackupTaskModel struct {
ID string `gorm:"primaryKey;size:36"`
Name string `gorm:"not null;size:255"`
Description string `gorm:"size:500"`
Type string `gorm:"not null;size:20"` // full, incremental, config
Sources string `gorm:"type:text"` // JSON 数组
TargetType string `gorm:"not null;size:20"` // local, s3, webdav, sftp
TargetConfig string `gorm:"type:text"` // JSON 配置
Schedule string `gorm:"size:100"` // cron 表达式
Retention int `gorm:"default:7"`
Compression bool `gorm:"default:true"`
Encryption bool `gorm:"default:false"`
Enabled bool `gorm:"default:true"`
LastRunAt *time.Time `gorm:"index"`
NextRunAt *time.Time `gorm:"index"`
CreatedAt time.Time `gorm:"autoCreateTime"`
UpdatedAt time.Time `gorm:"autoUpdateTime"`
}
BackupTaskModel 备份任务数据库模型
func (BackupTaskModel) TableName ¶
func (BackupTaskModel) TableName() string
func (*BackupTaskModel) ToBackupTask ¶
func (m *BackupTaskModel) ToBackupTask() *BackupTask
ToBackupTask 转换为 BackupTask
type BackupType ¶
type BackupType string
BackupType 备份类型
const ( BackupTypeFull BackupType = "full" // 完整备份 BackupTypeIncremental BackupType = "incremental" // 增量备份 BackupTypeConfig BackupType = "config" // 配置备份 )
type ChunkAckPayload ¶
type ChunkAckPayload struct {
FileID string `json:"file_id"`
ChunkIdx int `json:"chunk_idx"`
Success bool `json:"success"`
Error string `json:"error,omitempty"`
}
ChunkAckPayload 数据块确认消息
type ChunkPayload ¶
type ChunkPayload struct {
FileID string `json:"file_id"`
FilePath string `json:"file_path"`
ChunkIdx int `json:"chunk_idx"`
TotalChunks int `json:"total_chunks"`
Data string `json:"data"` // base64 编码的加密数据
Checksum string `json:"checksum"`
IsLast bool `json:"is_last"`
}
ChunkPayload 数据块消息
type ConfigExportRequest ¶
type ConfigExportRequest struct {
IncludeItems []string `json:"include_items"` // 要导出的配置项
Encryption bool `json:"encryption"`
Password string `json:"password,omitempty"`
}
ConfigExportRequest 配置导出请求
type ConfigImportRequest ¶
type ConfigImportRequest struct {
Password string `json:"password,omitempty"`
Overwrite bool `json:"overwrite"`
}
ConfigImportRequest 配置导入请求
type ConnectToSourceRequest ¶
type ConnectToSourceRequest struct {
PairCode string `json:"pair_code" binding:"required"`
TargetURL string `json:"target_url" binding:"required"`
}
ConnectToSourceRequest 连接到源请求
type CreateTaskRequest ¶
type CreateTaskRequest struct {
Name string `json:"name" binding:"required"`
Description string `json:"description"`
Type BackupType `json:"type" binding:"required"`
Sources []string `json:"sources" binding:"required"`
TargetType TargetType `json:"target_type" binding:"required"`
TargetConfig string `json:"target_config" binding:"required"`
Schedule string `json:"schedule"`
Retention int `json:"retention"`
Compression bool `json:"compression"`
Encryption bool `json:"encryption"`
}
CreateTaskRequest 创建任务请求
type Encryptor ¶
type Encryptor struct {
// contains filtered or unexported fields
}
Encryptor AES-256 加密器
func (*Encryptor) DecryptFile ¶
DecryptFile 解密文件
func (*Encryptor) DecryptFileStreaming ¶
DecryptFileStreaming 流式解密(用于大文件)
func (*Encryptor) EncryptFile ¶
EncryptFile 加密文件 格式: [header:10][salt:32][nonce:12][ciphertext...]
func (*Encryptor) EncryptFileStreaming ¶
EncryptFileStreaming 流式加密(用于大文件)
type ExportableConfig ¶
type ExportableConfig struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Category string `json:"category"` // system, app, user
}
ExportableConfig 可导出的配置项
type FileEntry ¶
type FileEntry struct {
Path string `json:"path"`
Size int64 `json:"size"`
ModTime time.Time `json:"mod_time"`
Checksum string `json:"checksum,omitempty"` // 可选的内容校验
IsDir bool `json:"is_dir"`
}
FileEntry 文件条目
type FileManifest ¶
type FileManifest struct {
Version int `json:"version"`
CreatedAt time.Time `json:"created_at"`
TaskID string `json:"task_id"`
Files map[string]FileEntry `json:"files"`
}
FileManifest 文件清单(用于增量备份)
func (*FileManifest) GetChangedFiles ¶
func (m *FileManifest) GetChangedFiles(old *FileManifest) []string
GetChangedFiles 获取相对于旧清单的变化文件
func (*FileManifest) GetDeletedFiles ¶
func (m *FileManifest) GetDeletedFiles(old *FileManifest) []string
GetDeletedFiles 获取已删除的文件
func (*FileManifest) ScanDirectory ¶
func (m *FileManifest) ScanDirectory(rootPath string) error
ScanDirectory 扫描目录建立文件清单
type GeneratePairCodeRequest ¶
type GeneratePairCodeRequest struct{}
GeneratePairCodeRequest 生成配对码请求
type GeneratePairCodeResponse ¶
type GeneratePairCodeResponse struct {
SessionID string `json:"session_id"`
PairCode string `json:"pair_code"`
ExpiresAt string `json:"expires_at"`
}
GeneratePairCodeResponse 生成配对码响应
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler HTTP 处理器
func (*Handler) GetExportableConfigs ¶
GetExportableConfigs 获取可导出配置
func (*Handler) GetRestoreStatus ¶
GetRestoreStatus 获取还原状态
func (*Handler) RegisterRoutes ¶
func (h *Handler) RegisterRoutes(r *gin.RouterGroup)
RegisterRoutes 注册路由
type HandshakePayload ¶
type HandshakePayload struct {
PublicKey string `json:"public_key"`
Hostname string `json:"hostname"`
Version string `json:"version"`
}
HandshakePayload 握手消息
type IncrementalBackupInfo ¶
type IncrementalBackupInfo struct {
BaseRecordID string `json:"base_record_id"` // 基于哪个完整备份
ChangedFiles []string `json:"changed_files"` // 变更的文件列表
DeletedFiles []string `json:"deleted_files"` // 删除的文件列表
ManifestPath string `json:"manifest_path"` // 清单文件路径
CreatedAt time.Time `json:"created_at"`
}
IncrementalBackupInfo 增量备份信息
type ListRecordsRequest ¶
type ListRecordsRequest struct {
Page int `form:"page"`
PageSize int `form:"page_size"`
TaskID string `form:"task_id"`
Status string `form:"status"`
}
ListRecordsRequest 记录列表请求
type ListTasksRequest ¶
type ListTasksRequest struct {
Page int `form:"page"`
PageSize int `form:"page_size"`
Type string `form:"type"`
Enabled *bool `form:"enabled"`
}
ListTasksRequest 任务列表请求
type LocalTarget ¶
type LocalTarget struct {
// contains filtered or unexported fields
}
LocalTarget 本地存储目标
func (*LocalTarget) Configure ¶
func (t *LocalTarget) Configure(config string) error
Configure 配置本地目标
type LocalTargetConfig ¶
type LocalTargetConfig struct {
Path string `json:"path"`
}
LocalTargetConfig 本地目标配置
type MigrateContentSelection ¶
type MigrateContentSelection struct {
SystemConfig bool `json:"system_config"`
Users bool `json:"users"`
Docker bool `json:"docker"`
Network bool `json:"network"`
Samba bool `json:"samba"`
Files []string `json:"files"`
Apps []string `json:"apps"`
}
MigrateContentSelection 迁移内容选择
type MigrateHandler ¶
type MigrateHandler struct {
// contains filtered or unexported fields
}
MigrateHandler 迁移 HTTP 处理器
func NewMigrateHandler ¶
func NewMigrateHandler(p2p *P2PMigrateService) *MigrateHandler
NewMigrateHandler 创建迁移处理器
func (*MigrateHandler) CancelSession ¶
func (h *MigrateHandler) CancelSession(c *gin.Context)
CancelSession 取消会话 @Summary 取消迁移会话 @Description 取消正在进行的迁移 @Tags migrate @Produce json @Param id path string true "会话ID" @Success 200 {object} map[string]interface{} @Router /backup/migrate/session/{id}/cancel [post]
func (*MigrateHandler) ConnectToSource ¶
func (h *MigrateHandler) ConnectToSource(c *gin.Context)
ConnectToSource 连接到源 @Summary 连接到数据源 @Description 源端调用,使用配对码连接到目标端 @Tags migrate @Accept json @Produce json @Param request body ConnectToSourceRequest true "连接请求" @Success 200 {object} map[string]interface{} @Router /backup/migrate/connect [post]
func (*MigrateHandler) GeneratePairCode ¶
func (h *MigrateHandler) GeneratePairCode(c *gin.Context)
GeneratePairCode 生成配对码 @Summary 生成配对码 @Description 目标端调用,生成用于配对的临时码 @Tags migrate @Accept json @Produce json @Success 200 {object} GeneratePairCodeResponse @Router /backup/migrate/pair [post]
func (*MigrateHandler) GetProgress ¶
func (h *MigrateHandler) GetProgress(c *gin.Context)
GetProgress 获取迁移进度 @Summary 获取迁移进度 @Description 获取当前迁移任务的详细进度 @Tags migrate @Produce json @Param id path string true "会话ID" @Success 200 {object} MigrateProgress @Router /backup/migrate/session/{id}/progress [get]
func (*MigrateHandler) GetSession ¶
func (h *MigrateHandler) GetSession(c *gin.Context)
GetSession 获取会话状态 @Summary 获取会话状态 @Description 获取迁移会话的当前状态 @Tags migrate @Produce json @Param id path string true "会话ID" @Success 200 {object} map[string]interface{} @Router /backup/migrate/session/{id} [get]
func (*MigrateHandler) RegisterMigrateRoutes ¶
func (h *MigrateHandler) RegisterMigrateRoutes(r *gin.RouterGroup)
RegisterMigrateRoutes 注册迁移路由
func (*MigrateHandler) StartTransfer ¶
func (h *MigrateHandler) StartTransfer(c *gin.Context)
StartTransfer 开始传输 @Summary 开始数据传输 @Description 源端调用,选择要迁移的内容并开始传输 @Tags migrate @Accept json @Produce json @Param id path string true "会话ID" @Param request body StartTransferRequest true "要迁移的内容" @Success 200 {object} map[string]interface{} @Router /backup/migrate/session/{id}/start [post]
func (*MigrateHandler) ValidatePairCode ¶
func (h *MigrateHandler) ValidatePairCode(c *gin.Context)
ValidatePairCode 验证配对码 @Summary 验证配对码 @Description 检查配对码是否有效 @Tags migrate @Accept json @Produce json @Param request body ValidatePairCodeRequest true "配对码" @Success 200 {object} map[string]interface{} @Router /backup/migrate/validate [post]
func (*MigrateHandler) WebSocketHandler ¶
func (h *MigrateHandler) WebSocketHandler(c *gin.Context)
WebSocketHandler WebSocket 处理 @Summary WebSocket 传输通道 @Description 建立 P2P 数据传输的 WebSocket 连接 @Tags migrate @Param pairCode path string true "配对码" @Router /backup/migrate/ws/{pairCode} [get]
type MigrateProgress ¶
type MigrateProgress struct {
Phase string `json:"phase"` // preparing, config, files, finalizing
TotalSize int64 `json:"total_size"`
TransferredSize int64 `json:"transferred_size"`
TotalFiles int `json:"total_files"`
TransferredFiles int `json:"transferred_files"`
CurrentFile string `json:"current_file"`
Speed int64 `json:"speed"` // bytes/sec
ETA int `json:"eta"` // 预计剩余秒数
Error string `json:"error,omitempty"`
}
MigrateProgress 迁移进度
type MigrateSession ¶
type MigrateSession struct {
ID string `json:"id"`
PairCode string `json:"pair_code"`
Role MigrateSessionRole `json:"role"`
Status MigrateSessionStatus `json:"status"`
RemoteAddr string `json:"remote_addr,omitempty"`
RemoteHost string `json:"remote_host,omitempty"`
ExpiresAt time.Time `json:"expires_at"`
CreatedAt time.Time `json:"created_at"`
// contains filtered or unexported fields
}
MigrateSession 迁移会话
type MigrateSessionRole ¶
type MigrateSessionRole string
MigrateSessionRole 会话角色
const ( RoleSource MigrateSessionRole = "source" // 发送方 RoleTarget MigrateSessionRole = "target" // 接收方 )
type MigrateSessionStatus ¶
type MigrateSessionStatus string
MigrateSessionStatus 会话状态
const ( StatusPairing MigrateSessionStatus = "pairing" StatusConnected MigrateSessionStatus = "connected" StatusTransferring MigrateSessionStatus = "transferring" StatusCompleted MigrateSessionStatus = "completed" StatusFailed MigrateSessionStatus = "failed" StatusCancelled MigrateSessionStatus = "cancelled" )
type MigrationContent ¶
type MigrationContent struct {
Type string `json:"type"` // config, data, file
Category string `json:"category"` // users, docker, samba, etc.
SourcePath string `json:"source_path"`
TargetPath string `json:"target_path"`
Size int64 `json:"size"`
}
MigrationContent 迁移内容条目
type MigrationExportRequest ¶
type MigrationExportRequest struct {
Description string `json:"description"`
IncludeItems []string `json:"include_items"` // users, docker, samba, settings, etc.
}
MigrationExportRequest 迁移导出请求
type MigrationImportRequest ¶
type MigrationImportRequest struct {
PackagePath string `json:"package_path"`
IncludeItems []string `json:"include_items"` // 空则导入全部
PathMapping map[string]string `json:"path_mapping"` // 路径映射
Overwrite bool `json:"overwrite"`
}
MigrationImportRequest 迁移导入请求
type MigrationItemResult ¶
type MigrationItemResult struct {
Category string `json:"category"`
Type string `json:"type"`
Status string `json:"status"` // success, failed, skipped
Error string `json:"error,omitempty"`
}
MigrationItemResult 迁移项结果
type MigrationPackage ¶
type MigrationPackage struct {
Version string `json:"version"`
CreatedAt time.Time `json:"created_at"`
SourceHost string `json:"source_host"`
Description string `json:"description"`
Contents []MigrationContent `json:"contents"`
PathMapping map[string]string `json:"path_mapping"` // 路径映射
Metadata map[string]interface{} `json:"metadata"`
}
MigrationPackage 迁移包结构
type MigrationResult ¶
type MigrationResult struct {
Package *MigrationPackage `json:"package"`
Items []MigrationItemResult `json:"items"`
StartedAt time.Time `json:"started_at"`
CompletedAt time.Time `json:"completed_at"`
}
MigrationResult 迁移结果
type MigrationService ¶
type MigrationService struct {
// contains filtered or unexported fields
}
MigrationService 迁移服务
func NewMigrationService ¶
func NewMigrationService(service *Service) *MigrationService
NewMigrationService 创建迁移服务
func (*MigrationService) ExportMigrationPackage ¶
func (m *MigrationService) ExportMigrationPackage(req *MigrationExportRequest) (string, error)
ExportMigrationPackage 导出迁移包
func (*MigrationService) ImportMigrationPackage ¶
func (m *MigrationService) ImportMigrationPackage(packagePath string, req *MigrationImportRequest) (*MigrationResult, error)
ImportMigrationPackage 导入迁移包
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
Module 备份还原模块
func (*Module) RegisterRoutes ¶
func (m *Module) RegisterRoutes(router *gin.RouterGroup)
RegisterRoutes 注册路由
type MsgType ¶
type MsgType string
P2P 消息类型
const ( MsgTypeHandshake MsgType = "handshake" MsgTypeHandshakeAck MsgType = "handshake_ack" MsgTypeContentList MsgType = "content_list" MsgTypeContentSelect MsgType = "content_select" MsgTypeTransferStart MsgType = "transfer_start" MsgTypeChunk MsgType = "chunk" MsgTypeChunkAck MsgType = "chunk_ack" MsgTypeTransferDone MsgType = "transfer_done" MsgTypeError MsgType = "error" MsgTypeHeartbeat MsgType = "heartbeat" MsgTypeCancel MsgType = "cancel" )
type P2PMessage ¶
type P2PMessage struct {
Type MsgType `json:"type"`
Payload json.RawMessage `json:"payload,omitempty"`
}
P2PMessage P2P 消息
type P2PMigrateService ¶
type P2PMigrateService struct {
// contains filtered or unexported fields
}
P2PMigrateService P2P 迁移服务
func NewP2PMigrateService ¶
func NewP2PMigrateService(service *Service) *P2PMigrateService
NewP2PMigrateService 创建 P2P 迁移服务
func (*P2PMigrateService) CancelSession ¶
func (p *P2PMigrateService) CancelSession(sessionID string) error
CancelSession 取消会话
func (*P2PMigrateService) ConnectWithPairCode ¶
func (p *P2PMigrateService) ConnectWithPairCode(pairCode, targetURL string) (*MigrateSession, error)
ConnectWithPairCode 使用配对码连接(源端调用)
func (*P2PMigrateService) GeneratePairCode ¶
func (p *P2PMigrateService) GeneratePairCode() (*MigrateSession, error)
GeneratePairCode 生成配对码(目标端调用)
func (*P2PMigrateService) GetProgress ¶
func (p *P2PMigrateService) GetProgress(sessionID string) (*MigrateProgress, error)
GetProgress 获取迁移进度
func (*P2PMigrateService) GetSession ¶
func (p *P2PMigrateService) GetSession(sessionID string) (*MigrateSession, error)
GetSession 获取会话
func (*P2PMigrateService) GetSessionByPairCode ¶
func (p *P2PMigrateService) GetSessionByPairCode(pairCode string) (*MigrateSession, error)
GetSessionByPairCode 通过配对码获取会话
func (*P2PMigrateService) HandleWebSocket ¶
func (p *P2PMigrateService) HandleWebSocket(w http.ResponseWriter, r *http.Request, pairCode string) error
HandleWebSocket 处理 WebSocket 连接
func (*P2PMigrateService) StartTransfer ¶
func (p *P2PMigrateService) StartTransfer(sessionID string, content *MigrateContentSelection) error
StartTransfer 开始传输(源端调用)
func (*P2PMigrateService) ValidatePairCode ¶
func (p *P2PMigrateService) ValidatePairCode(pairCode string) (*MigrateSession, error)
ValidatePairCode 验证配对码
type ProgressReader ¶
ProgressReader 带进度回调的 Reader
type RemoteFile ¶
type RemoteFile struct {
Name string `json:"name"`
Path string `json:"path"`
Size int64 `json:"size"`
ModTime int64 `json:"mod_time"`
}
RemoteFile 远程文件信息
type RestoreRecordModel ¶
type RestoreRecordModel struct {
ID string `gorm:"primaryKey;size:36"`
BackupID string `gorm:"not null;size:36;index"` // 关联的备份记录
TargetPath string `gorm:"size:500"`
Status string `gorm:"not null;size:20"`
Progress int `gorm:"default:0"`
CurrentFile string `gorm:"size:500"`
Message string `gorm:"size:500"`
Error string `gorm:"type:text"`
StartedAt time.Time `gorm:"not null"`
CompletedAt *time.Time
CreatedAt time.Time `gorm:"autoCreateTime"`
}
RestoreRecordModel 还原记录数据库模型
func (RestoreRecordModel) TableName ¶
func (RestoreRecordModel) TableName() string
func (*RestoreRecordModel) ToRestoreStatus ¶
func (m *RestoreRecordModel) ToRestoreStatus() *RestoreStatus
ToRestoreStatus 转换为 RestoreStatus
type RestoreRequest ¶
type RestoreRequest struct {
RecordID string `json:"record_id"` // 备份记录ID
TargetPath string `json:"target_path,omitempty"` // 还原目标路径,空则还原到原位置
SelectedItems []string `json:"selected_items,omitempty"` // 选择性还原的项
Overwrite bool `json:"overwrite"` // 是否覆盖已存在文件
}
RestoreRequest 还原请求
type RestoreStatus ¶
type RestoreStatus struct {
ID string `json:"id"`
RecordID string `json:"record_id"`
Status BackupStatus `json:"status"`
Progress int `json:"progress"`
CurrentFile string `json:"current_file,omitempty"`
Message string `json:"message"`
Error string `json:"error,omitempty"`
StartedAt time.Time `json:"started_at"`
CompletedAt *time.Time `json:"completed_at,omitempty"`
}
RestoreStatus 还原状态
type S3Target ¶
type S3Target struct {
// contains filtered or unexported fields
}
S3Target S3 兼容存储目标
type S3TargetConfig ¶
type S3TargetConfig struct {
Endpoint string `json:"endpoint"`
Region string `json:"region"`
Bucket string `json:"bucket"`
Prefix string `json:"prefix,omitempty"`
AccessKeyID string `json:"access_key_id"`
SecretAccessKey string `json:"secret_access_key"`
UseSSL bool `json:"use_ssl"`
}
S3TargetConfig S3目标配置
type SFTPTarget ¶
type SFTPTarget struct {
// contains filtered or unexported fields
}
SFTPTarget SFTP 存储目标
func (*SFTPTarget) Configure ¶
func (t *SFTPTarget) Configure(config string) error
Configure 配置 SFTP 目标
type SFTPTargetConfig ¶
type SFTPTargetConfig struct {
Host string `json:"host"`
Port int `json:"port"`
Username string `json:"username"`
Password string `json:"password,omitempty"`
PrivateKey string `json:"private_key,omitempty"`
Path string `json:"path"`
}
SFTPTargetConfig SFTP目标配置
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler 备份调度器
func NewScheduler ¶
NewScheduler 创建调度器
func (*Scheduler) GetNextRun ¶
GetNextRun 获取任务下次运行时间
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service 备份服务
func NewService ¶
NewService 创建服务实例
func (*Service) CreateTask ¶
func (s *Service) CreateTask(req *CreateTaskRequest) (*BackupTask, error)
CreateTask 创建任务
func (*Service) ExportConfig ¶
func (s *Service) ExportConfig(req *ConfigExportRequest) ([]byte, error)
ExportConfig 导出配置
func (*Service) GetExportableConfigs ¶
func (s *Service) GetExportableConfigs() []ExportableConfig
GetExportableConfigs 获取可导出的配置项
func (*Service) GetOverview ¶
func (s *Service) GetOverview() (*BackupOverview, error)
GetOverview 获取备份概览
func (*Service) GetRecord ¶
func (s *Service) GetRecord(id string) (*BackupRecord, error)
GetRecord 获取记录详情
func (*Service) GetRestoreStatus ¶
func (s *Service) GetRestoreStatus(id string) (*RestoreStatus, error)
GetRestoreStatus 获取还原状态
func (*Service) ImportConfig ¶
func (s *Service) ImportConfig(data []byte, req *ConfigImportRequest) error
ImportConfig 导入配置
func (*Service) ListRecords ¶
func (s *Service) ListRecords(req *ListRecordsRequest) ([]*BackupRecord, int64, error)
ListRecords 获取备份记录
func (*Service) ListTasks ¶
func (s *Service) ListTasks(req *ListTasksRequest) ([]*BackupTask, int64, error)
ListTasks 获取任务列表
func (*Service) RegisterTarget ¶
func (s *Service) RegisterTarget(t TargetType, target Target)
RegisterTarget 注册备份目标
func (*Service) Restore ¶
func (s *Service) Restore(req *RestoreRequest) (*RestoreStatus, error)
Restore 执行还原
func (*Service) RunTask ¶
func (s *Service) RunTask(taskID string) (*BackupRecord, error)
RunTask 立即执行备份任务
func (*Service) SetEncryptionPassword ¶
SetEncryptionPassword 设置加密密码
func (*Service) SetNotifyCallback ¶
SetNotifyCallback 设置通知回调
func (*Service) TestTarget ¶
func (s *Service) TestTarget(req *TargetTestRequest) *TargetTestResponse
TestTarget 测试目标连接
func (*Service) UpdateTask ¶
func (s *Service) UpdateTask(id string, req *UpdateTaskRequest) (*BackupTask, error)
UpdateTask 更新任务
type StartTransferRequest ¶
type StartTransferRequest struct {
SystemConfig bool `json:"system_config"`
Users bool `json:"users"`
Docker bool `json:"docker"`
Network bool `json:"network"`
Samba bool `json:"samba"`
Files []string `json:"files"`
Apps []string `json:"apps"`
}
StartTransferRequest 开始传输请求
type Target ¶
type Target interface {
// Configure 配置目标(传入 JSON 配置字符串)
Configure(config string) error
// Test 测试连接
Test() *TargetTestResponse
// Upload 上传文件,返回远程路径
Upload(localPath, remoteName string, progress func(int)) (string, error)
// Download 下载文件
Download(remotePath, localPath string, progress func(int)) error
// Delete 删除远程文件
Delete(remotePath string) error
// List 列出备份文件
List() ([]RemoteFile, error)
}
Target 备份目标接口
type TargetTestRequest ¶
type TargetTestRequest struct {
Type TargetType `json:"type"`
Config string `json:"config"` // JSON 配置
}
TargetTestRequest 测试目标连接请求
type TargetTestResponse ¶
type TargetTestResponse struct {
Success bool `json:"success"`
Message string `json:"message"`
FreeSpace int64 `json:"free_space,omitempty"` // 可用空间(字节)
}
TargetTestResponse 测试目标连接响应
type TargetType ¶
type TargetType string
TargetType 备份目标类型
const ( TargetTypeLocal TargetType = "local" TargetTypeS3 TargetType = "s3" TargetTypeWebDAV TargetType = "webdav" TargetTypeSFTP TargetType = "sftp" )
type UpdateTaskRequest ¶
type UpdateTaskRequest struct {
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Sources []string `json:"sources,omitempty"`
TargetType TargetType `json:"target_type,omitempty"`
TargetConfig string `json:"target_config,omitempty"`
Schedule string `json:"schedule,omitempty"`
Retention *int `json:"retention,omitempty"`
Compression *bool `json:"compression,omitempty"`
Encryption *bool `json:"encryption,omitempty"`
Enabled *bool `json:"enabled,omitempty"`
}
UpdateTaskRequest 更新任务请求
type ValidatePairCodeRequest ¶
type ValidatePairCodeRequest struct {
PairCode string `json:"pair_code" binding:"required"`
}
ValidatePairCodeRequest 验证配对码请求
type WebDAVTarget ¶
type WebDAVTarget struct {
// contains filtered or unexported fields
}
WebDAVTarget WebDAV 存储目标
func (*WebDAVTarget) Configure ¶
func (t *WebDAVTarget) Configure(config string) error
Configure 配置 WebDAV 目标
func (*WebDAVTarget) Delete ¶
func (t *WebDAVTarget) Delete(remotePath string) error
Delete 删除 WebDAV 文件