backup

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 16 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 负责配置备份的打包、加密、解析与保留策略,供手动导出、定时备份与恢复共用。

Index

Constants

View Source
const (
	// NamePrefix 是备份文件名前缀,保留策略只处理带此前缀的文件
	NamePrefix = "gately-backup-"
	// ExtZip 是未加密备份的扩展名
	ExtZip = ".zip"
	// ExtEncrypted 是加密备份的扩展名
	ExtEncrypted = ".zip.enc"
)

文件名约定

Variables

View Source
var ErrBadPassword = errors.New("备份口令错误或文件已损坏")

ErrBadPassword 表示口令错误或备份已损坏。

View Source
var ErrPasswordRequired = errors.New("备份已加密,需要提供备份口令")

ErrPasswordRequired 表示备份已加密但未提供口令。

Functions

func Build

func Build(dir, password string, now time.Time) ([]byte, error)

Build 打包配置目录。password 非空时加密输出。

func Collect

func Collect(dir string) (map[string][]byte, error)

Collect 读取配置目录下全部 *.json。

func Decrypt

func Decrypt(data []byte, password string) ([]byte, error)

Decrypt 解密 Encrypt 的输出。

func Encrypt

func Encrypt(data []byte, password string) ([]byte, error)

Encrypt 用口令以 scrypt + AES-256-GCM 加密。

func IsBackupName

func IsBackupName(name string) bool

IsBackupName 判断文件名是否为本包生成的备份。

func IsEncrypted

func IsEncrypted(data []byte) bool

IsEncrypted 判断数据是否为加密备份。

func Name

func Name(now time.Time, encrypted bool) string

Name 生成备份文件名。

func Parse

func Parse(data []byte, password string) (map[string][]byte, error)

Parse 解析备份(自动识别是否加密),返回其中的配置文件。 只接受位于 zip 根目录、非隐藏的 *.json,且内容必须是合法 JSON。

func Pick

func Pick(names []string, keep int) []string

Pick 返回 names 中应被删除的旧备份:只统计备份文件,按文件名(含时间)倒序保留 keep 个。 keep 小于 1 时不删除任何文件。

func Zip

func Zip(files map[string][]byte, now time.Time) ([]byte, error)

Zip 把文件集合打包为 zip,文件按名称排序以保证输出稳定。

Types

This section is empty.

Jump to

Keyboard shortcuts

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