backup

package
v1.9.3 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// 备份类型
	BackupTypeMongoCollection = "mongo_collection"
	BackupTypeMySQLTable      = "mysql_table"

	// 备份状态
	BackupStatusCompleted = "completed"
	BackupStatusFailed    = "failed"
	BackupStatusPartial   = "partial"

	// 集合名称
	MetaCollectionName = "c_upgrade_backup_meta"
	DataCollectionName = "c_upgrade_backup_data"
)

常量定义

Variables

This section is empty.

Functions

This section is empty.

Types

type BackupManager

type BackupManager struct {
	// contains filtered or unexported fields
}

BackupManager 备份管理器

func NewBackupManager

func NewBackupManager(app *ioc.App) *BackupManager

NewBackupManager 创建备份管理器

func (*BackupManager) BackupMongoCollection

func (bm *BackupManager) BackupMongoCollection(ctx context.Context, collectionName string, opts Options) (*Result, error)

BackupMongoCollection 备份 MongoDB 集合

func (*BackupManager) BackupMySQLTable

func (bm *BackupManager) BackupMySQLTable(ctx context.Context, tableName string, opts Options) (*Result, error)

BackupMySQLTable 备份 MySQL 表

func (*BackupManager) CleanupOldBackups

func (bm *BackupManager) CleanupOldBackups(ctx context.Context, sourceName string, providerType string, keepDays int) error

CleanupOldBackups 清理旧备份

func (*BackupManager) ListBackups

func (bm *BackupManager) ListBackups(ctx context.Context, sourceName string, providerType string) ([]Info, error)

ListBackups 列出备份

func (*BackupManager) RestoreMongoCollection

func (bm *BackupManager) RestoreMongoCollection(ctx context.Context, collectionName string, backupID string) error

RestoreMongoCollection 恢复 MongoDB 集合

func (*BackupManager) RestoreMySQLTable

func (bm *BackupManager) RestoreMySQLTable(ctx context.Context, tableName string, backupID string) error

RestoreMySQLTable 恢复 MySQL 表

type Info

type Info struct {
	BackupID    string `bson:"backup_id"`    // 备份ID
	Version     string `bson:"version"`      // 版本号
	BackupTime  int64  `bson:"backup_time"`  // 备份时间戳
	BackupDate  string `bson:"backup_date"`  // 备份日期
	Description string `bson:"description"`  // 备份描述
	SourceName  string `bson:"source_name"`  // 源名称
	BackupType  string `bson:"backup_type"`  // 备份类型
	RecordCount int64  `bson:"record_count"` // 记录数
	Status      string `bson:"status"`       // 备份状态
}

Info 备份信息(用于列表显示)

type Meta

type Meta struct {
	BackupID     string            `bson:"backup_id"`      // 备份批次ID
	Version      string            `bson:"version"`        // 版本号
	BackupTime   int64             `bson:"backup_time"`    // 备份时间戳
	BackupDate   string            `bson:"backup_date"`    // 备份日期
	Description  string            `bson:"description"`    // 备份描述
	SourceName   string            `bson:"source_name"`    // 源名称(表名或集合名)
	BackupType   string            `bson:"backup_type"`    // 备份类型
	TotalRecords int64             `bson:"total_records"`  // 总记录数
	Status       string            `bson:"status"`         // 备份状态
	Tags         map[string]string `bson:"tags,omitempty"` // 额外标签
	CreatedAt    time.Time         `bson:"created_at"`     // 创建时间
}

Meta 备份元数据

type MongoBackupData

type MongoBackupData struct {
	BackupID   string      `bson:"backup_id"`   // 关联的备份ID
	OriginalID interface{} `bson:"original_id"` // 原始文档ID
	Data       interface{} `bson:"data"`        // 原始数据
	CreatedAt  time.Time   `bson:"created_at"`  // 创建时间
}

MongoBackupData MongoDB 备份数据

type MongoBackupProvider

type MongoBackupProvider struct {
	// contains filtered or unexported fields
}

MongoBackupProvider MongoDB 备份提供者

func (*MongoBackupProvider) Backup

func (p *MongoBackupProvider) Backup(ctx context.Context, collectionName string, opts Options) (*Result, error)

Backup 备份 MongoDB 集合

func (*MongoBackupProvider) CleanupOldBackups

func (p *MongoBackupProvider) CleanupOldBackups(ctx context.Context, sourceName string, keepDays int) error

CleanupOldBackups 清理旧备份

func (*MongoBackupProvider) GetProviderType

func (p *MongoBackupProvider) GetProviderType() string

GetProviderType 获取提供者类型

func (*MongoBackupProvider) ListBackups

func (p *MongoBackupProvider) ListBackups(ctx context.Context, sourceName string) ([]Info, error)

ListBackups 列出备份

func (*MongoBackupProvider) Restore

func (p *MongoBackupProvider) Restore(ctx context.Context, collectionName string, backupID string) error

Restore 恢复 MongoDB 集合

type MySQLBackupData

type MySQLBackupData struct {
	BackupID     string      `bson:"backup_id"`     // 关联的备份ID
	OriginalID   interface{} `bson:"original_id"`   // 原始记录ID
	Data         interface{} `bson:"data"`          // 原始数据(保留兼容性)
	SQLStatement string      `bson:"sql_statement"` // SQL 语句
	CreatedAt    time.Time   `bson:"created_at"`    // 创建时间
}

MySQLBackupData MySQL 备份数据

type MySQLBackupProvider

type MySQLBackupProvider struct {
	// contains filtered or unexported fields
}

MySQLBackupProvider MySQL 备份提供者

func (*MySQLBackupProvider) Backup

func (p *MySQLBackupProvider) Backup(ctx context.Context, tableName string, opts Options) (*Result, error)

Backup 备份 MySQL 表

func (*MySQLBackupProvider) CleanupOldBackups

func (p *MySQLBackupProvider) CleanupOldBackups(ctx context.Context, sourceName string, keepDays int) error

CleanupOldBackups 清理旧备份

func (*MySQLBackupProvider) GetProviderType

func (p *MySQLBackupProvider) GetProviderType() string

GetProviderType 获取提供者类型

func (*MySQLBackupProvider) ListBackups

func (p *MySQLBackupProvider) ListBackups(ctx context.Context, sourceName string) ([]Info, error)

ListBackups 列出备份

func (*MySQLBackupProvider) Restore

func (p *MySQLBackupProvider) Restore(ctx context.Context, tableName string, backupID string) error

Restore 恢复 MySQL 表

type Options

type Options struct {
	Version     string            // 版本号
	Description string            // 备份描述
	Tags        map[string]string // 额外标签
}

Options 备份选项

type Provider

type Provider interface {
	// Backup 备份数据
	Backup(ctx context.Context, sourceName string, opts Options) (*Result, error)

	// Restore 恢复数据
	Restore(ctx context.Context, sourceName string, backupID string) error

	// ListBackups 列出备份
	ListBackups(ctx context.Context, sourceName string) ([]Info, error)

	// CleanupOldBackups 清理旧备份
	CleanupOldBackups(ctx context.Context, sourceName string, keepDays int) error

	// GetProviderType 获取提供者类型
	GetProviderType() string
}

Provider 备份提供者接口

func NewMongoBackupProvider

func NewMongoBackupProvider(app *ioc.App) Provider

NewMongoBackupProvider 创建 MongoDB 备份提供者

func NewMySQLBackupProvider

func NewMySQLBackupProvider(app *ioc.App) Provider

NewMySQLBackupProvider 创建 MySQL 备份提供者

type Result

type Result struct {
	BackupID     string   // 备份ID
	BackupTime   int64    // 备份时间戳
	Collections  []string // 备份的集合列表
	TotalRecords int64    // 总记录数
}

Result 备份结果

Jump to

Keyboard shortcuts

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