backup

package
v0.6.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 21 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package backup 实现定时配置备份:按 cron 表达式打包全部配置,写入本地目录或存储挂载中的挂载点 (本地目录、WebDAV),支持口令加密与按数量保留,并在成功或失败时发布通知事件。

Index

Constants

View Source
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 是备份模块。

func New

func New(st Storage) *Module

New 创建模块。st 为存储挂载模块,可为 nil(此时只支持本地目录)。

func (*Module) ID

func (m *Module) ID() string

ID 实现 module.Module。

func (*Module) Init

func (m *Module) Init(env module.Env) error

Init 实现 module.Module。

func (*Module) Routes

func (m *Module) Routes(r module.Router)

Routes 实现 module.Module。

func (*Module) Run

func (m *Module) Run(manual bool) Status

Run 执行一次备份。已有备份在运行时直接返回。manual 表示由用户触发。

func (*Module) Start

func (m *Module) Start(context.Context) error

Start 实现 module.Module。

func (*Module) Stop

func (m *Module) Stop() error

Stop 实现 module.Module。

func (*Module) Title

func (m *Module) Title() string

Title 实现 module.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 是定时备份的全局设置。

func (*Settings) Validate

func (s *Settings) Validate() error

Validate 校验并规范化设置。

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"`
	// Mount 为存储挂载中的挂载点 key
	Mount string `json:"mount"`
	// Dir 为挂载点内的目录,留空为根目录
	Dir string `json:"dir"`
}

Target 是一个远程备份目的地,写入存储挂载中的某个挂载点。

func (*Target) Validate

func (t *Target) Validate() error

Validate 校验并规范化目的地。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL