Documentation
¶
Overview ¶
Package backup 实现定时配置备份:按 cron 表达式打包全部配置,写入本地目录或存储挂载中的挂载点 (本地目录、WebDAV),支持口令加密与按数量保留,并在成功或失败时发布通知事件。
Index ¶
- Constants
- type LocalFile
- type Module
- func (m *Module) ID() string
- func (m *Module) Init(env module.Env) error
- func (m *Module) Routes(r module.Router)
- func (m *Module) Run(manual bool) Status
- func (m *Module) SetMailer(s mailer.Sender)
- func (m *Module) Start(context.Context) error
- func (m *Module) Stop() error
- func (m *Module) Title() string
- type Result
- type Settings
- type Status
- type Storage
- type Target
Constants ¶
const ( // KindMount 写入存储挂载中的挂载点(默认,旧配置没有 kind 字段时即此类型) KindMount = "mount" // KindMail 作为附件发送到通知中心的邮件渠道 KindMail = "mail" )
目的地类型
const ID = "backup"
ID 是模块标识。
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LocalFile ¶
type LocalFile struct {
Name string `json:"name"`
Size int64 `json:"size"`
ModTime time.Time `json:"modTime"`
}
LocalFile 是本地备份目录中的一个文件。
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
Module 是备份模块。
type Result ¶
type Result struct {
Target string `json:"target"`
OK bool `json:"ok"`
File string `json:"file,omitempty"`
Error string `json:"error,omitempty"`
Pruned int `json:"pruned,omitempty"`
}
Result 是一个目的地在一次备份中的结果。
type Settings ¶
type Settings struct {
Enable bool `json:"enable"`
// Schedule 为 5 段 cron 表达式或 @daily 等描述符
Schedule string `json:"schedule"`
// Keep 为每个目的地保留的备份数量
Keep int `json:"keep"`
// Password 非空时备份被加密;恢复时需要提供同一口令
Password string `json:"password"`
// LocalEnable 决定是否写入配置目录下的 backups 子目录
LocalEnable bool `json:"localEnable"`
}
Settings 是定时备份的全局设置。
type Status ¶
type Status struct {
Running bool `json:"running"`
LastRun time.Time `json:"lastRun,omitzero"`
NextRun time.Time `json:"nextRun,omitzero"`
// Manual 表示最近一次由手动触发
Manual bool `json:"manual"`
Results []Result `json:"results"`
}
Status 是最近一次备份的概况。
type Storage ¶
type Storage interface {
MountList() []storage.MountInfo
PutFile(mount, dir, name string, data []byte) error
ListNames(mount, dir string) ([]string, error)
RemoveFile(mount, p string) error
}
Storage 由存储挂载模块实现,备份通过它写入挂载点。
type Target ¶
type Target struct {
Key string `json:"key"`
Name string `json:"name"`
Enable bool `json:"enable"`
// Kind 为 mount(默认)或 mail
Kind string `json:"kind,omitempty"`
// Mount 为存储挂载中的挂载点 key(kind=mount)
Mount string `json:"mount"`
// Dir 为挂载点内的目录,留空为根目录(kind=mount)
Dir string `json:"dir"`
// Channel 为通知中心邮件渠道的 key,收件人取该渠道配置(kind=mail)
Channel string `json:"channel,omitempty"`
}
Target 是一个远程备份目的地:写入存储挂载中的某个挂载点,或发送到邮件渠道。