backup

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 29 Imported by: ? 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.

README

集群备份与单空间恢复

公开包 github.com/lfhy/compactfs/fs/cluster/backup 实现协调捕获与离线恢复。

完整备份使用 manifest v1/v2,单空间备份使用 v3。两者均把镜像与不可变对象根写入独立 Local/S3 backend,manifest 最后发布;GC 的持久保护根必须与备份创建/保留操作协调。Header.Scope 非空时只有该空间的逻辑 namespace 和筛选 placement 镜像,不包含其他租户数据或可回放全局旧状态的 authority 镜像。Store.List 可发现两类备份,保留数分别计算。

Store.CreateNamespace(ctx, coordinatedSource, namespaceID) 复用完整备份的 quiesce、backend drain 与统一 authority barrier,在捕获后的私有镜像上筛选目标空间。每个引用必须在该空间的 placement 中有完全匹配的 descriptor。历史和未知空间内扩展记录都会保留,原始 AK/SK 不属于这些文件元数据镜像。

cpfs server namespace-backup create -gw http://127.0.0.1:7420 \
  --cluster-config ./admin.json --namespace team-a --backend /backup/cpfs
cpfs server namespace-backup list --all --backend /backup/cpfs

恢复前停止全部 Meta 和文件导出,并隔离旧主;以停止后的当前三库为基底,不能把某个旧全库备份当作“只恢复一个空间”。当前库可以由 --current-directory 指定(namespace.db、placement.db、authority/authority.db),或分别使用 --current-namespace、--current-placement、--current-authority 指定实际路径。

cpfs server namespace-backup restore --backend /backup/cpfs --key MANIFEST_KEY \
  --cluster-config ./current-meta-a.json --current-directory /srv/cpfs/current \
  --directory /srv/cpfs/restored --members ./data-members.json \
  --node-id meta-a --peer-node-id meta-b --output-config ./restored-meta-a.json

Store.InspectCurrent 校验当前完整 namespace/placement/authority 的水位和身份。RestoreNamespace 将当前库复制到全新目录,只替换选中 ID 的文件数据与历史,保留当前 catalog、其他空间及其 VolumeID;目标的备份保护根取当前与备份的并集,pin ID 相同但内容不同会拒绝。当前与选中备份的所有最终对象都经过完整读取验证后才发布。

恢复使用更高 epoch 和不同 incarnation(可显式传 --new-epoch、--new-incarnation),保留当前 WAL 前缀并追加目标空间替换记录,使全新 standby 仍可重建所有租户。整个恢复批次默认上限 64MiB,可用 --max-mutation-bytes 调整至最多 256MiB;单 namespace WAL payload 最多 4MiB,超限拒绝。镜像及记录复制有界,失败不修改来源、不发布半目录。

输出 authority 仍未激活。当前加权 Raft 部署先隔离原投票组,再用 cpfs server raft-init --journal 把完整恢复日志生成新组;空 native 副本从已提交日志重建,完成新 quorum 屏障和 Data 持久门禁 ACK 后才准入。独立 Auth 同样须对齐新 signing generation。命令顺序见Meta恢复。CLI 不自动启动进程或隔离旧主。完整 Store.Restore 拒绝 v3,单空间恢复必须显式使用 RestoreNamespace 和当前完整状态。

Documentation

Overview

Package backup publishes coordinated authority, namespace and placement checkpoints to an independent backend and restores them only while offline.

Index

Constants

View Source
const DefaultPrefix = "cluster/backups"
View Source
const NamespaceVersion = 2
View Source
const SingleNamespaceVersion = 3
View Source
const Version = 1

Variables

This section is empty.

Functions

This section is empty.

Types

type CaptureConfig

type CaptureConfig struct {
	Authority  *clustermeta.Authority
	Namespace  meta.Snapshotter
	Placement  *clusterstore.Store
	VolumeID   string
	Format     fsformat.Volume
	Namespaces []Namespace
}

CaptureConfig captures three images at one authority barrier. The caller must already hold the shared file server's quiesce gate and have completed backend drain. Wrap this in SourceFunc to acquire that outer gate, returning before Store.Create uploads any image to the backup backend.

func (CaptureConfig) Capture

func (c CaptureConfig) Capture(ctx context.Context, directory string) (checkpoint Checkpoint, err error)

type Checkpoint

type Checkpoint struct {
	Header        Header
	NamespacePath string
	PlacementPath string
	AuthorityPath string
}

Checkpoint paths belong to the private directory supplied to Capture. The source must freeze mutations, drain backend writes, cross the authority barrier and capture all three images at Header.Sequence before returning.

type Header struct {
	ClusterID     string            `json:"cluster_id"`
	VolumeID      string            `json:"volume_id"`
	Incarnation   string            `json:"incarnation"`
	Epoch         uint64            `json:"epoch"`
	Sequence      uint64            `json:"sequence"`
	HeadHash      string            `json:"head_hash"`
	DomainApplied map[string]uint64 `json:"domain_applied"`
	Format        fsformat.Volume   `json:"format"`
	Namespaces    []Namespace       `json:"namespaces,omitempty"`
	Scope         *Namespace        `json:"scope,omitempty"`
	ProtectionID  string            `json:"protection_id,omitempty"`
}

func (Header) Validate

func (h Header) Validate() error

type Hooks

type Hooks struct {
	BeforePublish func(context.Context, Info) error
	AfterPrune    func(context.Context, Info) error
	Finish        func(context.Context, string, bool) error
}

Hooks borrows the caller's metadata protection lifecycle. BeforePublish must durably bind Info to its protection before the manifest can become visible. AfterPrune runs only after exact manifest absence and image deletion are confirmed. Finish ends process-local upload activity; published is true only if the manifest upload returned success, independently of retention errors. A failed/unknown upload must never cause Finish to discard its object roots.

type Image

type Image struct {
	Kind string `json:"kind"`
	Key  string `json:"key"`
	Size int64  `json:"size"`
	XXH3 string `json:"xxh3_128"`
}

type Info

type Info struct {
	Key      string   `json:"key"`
	XXH3     string   `json:"xxh3_128"`
	Manifest Manifest `json:"manifest"`
}

type Manifest

type Manifest struct {
	Version int          `json:"version"`
	ID      string       `json:"id"`
	Created time.Time    `json:"created"`
	Header  Header       `json:"header"`
	Images  []Image      `json:"images"`
	Objects []ObjectRoot `json:"objects"`
}

type Namespace

type Namespace struct {
	Name     string          `json:"name"`
	ID       string          `json:"id"`
	VolumeID string          `json:"volume_id"`
	Format   fsformat.Volume `json:"format"`
}

Namespace identifies one independently scoped volume in the shared image. Empty Name/ID is the default namespace; root is only its external alias.

type NamespaceRestoreOptions

type NamespaceRestoreOptions struct {
	// Current is an immutable checkpoint of the current cluster, not the old
	// backup being restored. The caller must stop all exports/Meta and hold the
	// source writer lock until this method returns.
	Current      Checkpoint
	Authority    clustermeta.RestoreOptions
	VerifyObject func(context.Context, ObjectRoot) error
	// MaxMutationBytes bounds the complete in-memory restore WAL batch.
	MaxMutationBytes int
}

type ObjectRoot

type ObjectRoot struct {
	Key    string              `json:"key"`
	Record clusterstore.Record `json:"record"`
}

type RestoreOptions

type RestoreOptions struct {
	Authority clustermeta.RestoreOptions
	// VerifyObject must fetch and verify each complete encoded object using the
	// manifest's descriptor/replicas, not the lost online placement index.
	VerifyObject func(context.Context, ObjectRoot) error
	// MaxMutationBytes bounds the offline suffix which drops unreferenced index rows.
	MaxMutationBytes int
}

type Restored

type Restored struct {
	Version          int                `json:"version"`
	SourceKey        string             `json:"source_key"`
	Source           Header             `json:"source"`
	Header           Header             `json:"restored"`
	Authority        clustermeta.Status `json:"authority"`
	Created          time.Time          `json:"created"`
	ActivationNeeded bool               `json:"activation_needed"`
}

type Source

type Source interface {
	Capture(context.Context, string) (Checkpoint, error)
}

func NamespaceSource

func NamespaceSource(source Source, namespaceID string) Source

NamespaceSource filters an already coordinated checkpoint before upload. The underlying Source must quiesce files, drain backend and cross the authority barrier exactly as for full backups. Full intermediate images stay private and are removed with the caller's checkpoint temporary directory.

type SourceFunc

type SourceFunc func(context.Context, string) (Checkpoint, error)

func (SourceFunc) Capture

func (f SourceFunc) Capture(ctx context.Context, dir string) (Checkpoint, error)

type Store

type Store struct {
	Backend          backend.Backend
	Prefix           string
	ClusterID        string
	VolumeID         string
	Retention        int
	TempDir          string
	MaxImageBytes    int64
	MaxManifestBytes int64
	MaxObjects       int
	MaxBackups       int
	Hooks            *Hooks
}

Store owns no live metadata. Backend must be independent of the placement index being backed up, for example a separate Local directory or S3 prefix.

func (Store) Create

func (s Store) Create(ctx context.Context, source Source) (created Info, result error)

func (Store) CreateNamespace

func (s Store) CreateNamespace(ctx context.Context, source Source, namespaceID string) (Info, error)

func (Store) InspectCurrent

func (s Store) InspectCurrent(ctx context.Context, namespace, placement, authority string) (Checkpoint, error)

InspectCurrent validates offline current files without changing any source. Unlike a backup manifest it reflects every namespace at its current state.

func (Store) List

func (s Store) List(ctx context.Context) ([]Info, error)

func (Store) Load

func (s Store) Load(ctx context.Context, key string) (Info, error)

Load discovers a checkpoint from its immutable manifest alone. The caller may retain Key separately; no online cluster index is required.

func (Store) Prune

func (s Store) Prune(ctx context.Context) error

func (Store) Restore

func (s Store) Restore(ctx context.Context, key, destination string, options RestoreOptions) (Restored, error)

Restore creates a new offline root with namespace.db, placement.db and an authority/ directory. Source objects remain unchanged. Activation always requires runtime reconciliation and durable acknowledgements from Data.

func (Store) RestoreNamespace

func (s Store) RestoreNamespace(ctx context.Context, key, destination string, options NamespaceRestoreOptions) (Restored, error)

RestoreNamespace preserves all current scopes except the explicitly selected one. It publishes a new directory only after the merged DBs, all object roots and the appended restore WAL agree. Activation/fencing remains external.

Jump to

Keyboard shortcuts

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