backup

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const MaxSize = 16 << 20
View Source
const SchemaVersion = 1

Variables

View Source
var ErrConflict = errors.New("merge conflict")
View Source
var ErrInvalid = errors.New("invalid backup")

Functions

func CSVTemplate added in v0.3.0

func CSVTemplate(kind string) ([]byte, error)

func CSVToMerge added in v0.3.0

func CSVToMerge(kind string, data []byte) ([]byte, error)

CSVToMerge 把单一对象类型的 UTF-8 CSV 转成现有合并导入文件,后续仍走同一审批路径。

func Directory added in v0.3.0

func Directory(ctx context.Context, db *sql.DB) (string, error)

func IsInvalid

func IsInvalid(err error) bool

func Parse

func Parse(data []byte) (File, Preview, error)

func ReadManaged added in v0.3.0

func ReadManaged(dir, name string) ([]byte, error)

func SaveManaged added in v0.3.0

func SaveManaged(dir string, data []byte, now time.Time, dailyKeep, weeklyKeep int, weeklyInterval time.Duration) error

func Validate

func Validate(ctx context.Context, f File) error

Validate 在独立临时库中执行完整恢复,再检查引用和索引。

func WriteAtomic

func WriteAtomic(path string, data []byte) error

WriteAtomic writes one private backup in the data directory and fsyncs it before rename.

Types

type ChangePreview added in v0.3.0

type ChangePreview struct {
	ID       string `json:"id"`
	ObjectID string `json:"object_id"`
	Action   string `json:"action"`
	Reason   string `json:"reason"`
	State    string `json:"state"`
}

type DifferenceCount added in v0.3.0

type DifferenceCount struct {
	Added    int `json:"added"`
	Modified int `json:"modified"`
	Deleted  int `json:"deleted"`
}

type File

type File struct {
	SchemaVersion int                         `yaml:"schema_version" json:"schema_version"`
	Kind          string                      `yaml:"kind" json:"kind"`
	ExportedAt    string                      `yaml:"exported_at" json:"exported_at"`
	Tables        map[string][]map[string]any `yaml:"tables" json:"tables"`
	Objects       []map[string]any            `yaml:"objects,omitempty" json:"objects,omitempty"`
}

type ManagedFile added in v0.3.0

type ManagedFile struct {
	Name      string `json:"name"`
	Kind      string `json:"kind"`
	CreatedAt string `json:"created_at"`
	Size      int64  `json:"size"`
}

func ListManaged added in v0.3.0

func ListManaged(dir string) ([]ManagedFile, error)

type ObjectPreview added in v0.3.0

type ObjectPreview struct {
	ID     string `json:"id"`
	Type   string `json:"type"`
	Action string `json:"action"`
	Reason string `json:"reason,omitempty"`
}

type Pending

type Pending struct {
	ID        string  `json:"id"`
	Kind      string  `json:"kind"`
	Proposer  string  `json:"proposer"`
	CreatedAt string  `json:"created_at"`
	State     string  `json:"state"`
	Preview   Preview `json:"preview"`
}

type Preview

type Preview struct {
	Kind              string                     `json:"kind"`
	Counts            map[string]int             `json:"counts"`
	Objects           []ObjectPreview            `json:"objects,omitempty"`
	Differences       map[string]DifferenceCount `json:"differences,omitempty"`
	ObjectDifferences map[string]DifferenceCount `json:"object_differences,omitempty"`
	LostChanges       []ChangePreview            `json:"lost_changes,omitempty"`
}

type Service

type Service struct{ DB *sql.DB }

func (Service) CleanupExpired added in v0.3.0

func (s Service) CleanupExpired(ctx context.Context) error

func (Service) Export

func (s Service) Export(ctx context.Context, kind string) ([]byte, error)

func (Service) List

func (s Service) List(ctx context.Context) ([]Pending, error)

func (Service) MergePreview added in v0.3.0

func (s Service) MergePreview(ctx context.Context, f File) (Preview, error)

func (Service) Restore

func (s Service) Restore(ctx context.Context, f File) error

func (Service) RestorePreview added in v0.3.0

func (s Service) RestorePreview(ctx context.Context, target File) (Preview, string, error)

func (Service) Review

func (s Service) Review(ctx context.Context, id string, approve bool, reviewer string) error

func (Service) Submit

func (s Service) Submit(ctx context.Context, data []byte, actor auth.Principal) (Pending, error)

Jump to

Keyboard shortcuts

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