backup

package
v2.7.0 Latest Latest
Warning

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

Go to latest
Published: May 26, 2026 License: MIT Imports: 60 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TimeFormatForBackup - default backup name format
	TimeFormatForBackup = "2006-01-02T15-04-05"
	MetaFileName        = "metadata.json"
)
View Source
const DirectoryFormat = "directory"

Variables

View Source
var CreateDatabaseRE = regexp.MustCompile(`(?m)^CREATE DATABASE (\s*)(\S+)(\s*)(.*)`)
View Source
var (
	ErrBackupIsAlreadyExists = errors.New("backup is already exists")
)
View Source
var (
	// ErrUnknownClickhouseDataPath -
	ErrUnknownClickhouseDataPath = errors.New("clickhouse data path is unknown, you can set data_path in config file")
)
View Source
var UUIDWithMergeTreeRE = regexp.MustCompile(`^(.+)(UUID)(\s+)'([^']+)'(.+)({uuid})(.*)`)

Functions

func IsInformationSchema

func IsInformationSchema(database string) bool

func NewBackupName

func NewBackupName() string

NewBackupName - return default backup name

func ShallSkipDatabase

func ShallSkipDatabase(cfg *config.Config, targetDB, tablePattern string) bool

Types

type BackupInfo added in v2.6.32

type BackupInfo struct {
	BackupName     string
	CreationDate   time.Time
	Size           string
	Description    string
	RequiredBackup string // for incremental backup, this is the base full backup
	Type           string // local or remote
}

type Backuper

type Backuper struct {
	DiskToPathMap          map[string]string
	DefaultDataPath        string
	EmbeddedBackupDataPath string
	// contains filtered or unexported fields
}

func NewBackuper

func NewBackuper(cfg *config.Config, opts ...BackuperOpt) *Backuper

func (*Backuper) AddTableToLocalBackup added in v2.5.0

func (b *Backuper) AddTableToLocalBackup(ctx context.Context, backupName string, tablesDiffFromRemote map[metadata.TableTitle]metadata.TableMetadata, shadowBackupUUID string, diskList []clickhouse.Disk, table *clickhouse.Table, partitionsIdsMap common.EmptyMap, skipProjections []string, version int) (map[string][]metadata.Part, map[string]int64, map[string]int64, map[string]uint64, map[string]string, error)

func (*Backuper) CalculateMaxSize added in v2.6.0

func (b *Backuper) CalculateMaxSize(ctx context.Context) error

CalculateMaxSize https://github.com/Altinity/clickhouse-backup/issues/404

func (*Backuper) CalculateNonSkipTables added in v2.6.3

func (b *Backuper) CalculateNonSkipTables(tables []clickhouse.Table) int

func (*Backuper) CheckDisksUsage added in v2.6.6

func (b *Backuper) CheckDisksUsage(backup storage.Backup, disks []clickhouse.Disk, isResumeExists bool, tablePattern string) error

CheckDisksUsage - https://github.com/Altinity/clickhouse-backup/issues/878

func (*Backuper) Classify added in v2.6.24

func (b *Backuper) Classify(err error) retrier.Action

Classify need to log retries

func (*Backuper) Clean

func (b *Backuper) Clean(ctx context.Context) error

Clean - removed all data in shadow folder

func (*Backuper) CleanBrokenRetention added in v2.7.0

func (b *Backuper) CleanBrokenRetention(commandId int, includeGlobs, excludeGlobs []string, commit bool) error

CleanBrokenRetention walks remote `path` and `object_disks_path` top-level entries and removes everything that is NOT present in the live BackupList and NOT matched by excludeGlobs. Uses BatchDeleter with retry and parallel batch deletion for object_disks_path orphans. When commit=false, only logs orphans without deleting (dry-run mode). When includeGlobs is non-empty, only orphans matching at least one includeGlob are considered. excludeGlobs and includeGlobs follow path.Match syntax (e.g. "prod-*", "snapshot-2026-??-*").

func (*Backuper) CleanLocalBroken added in v2.6.27

func (b *Backuper) CleanLocalBroken(commandId int) error

func (*Backuper) CleanRemoteBroken

func (b *Backuper) CleanRemoteBroken(commandId int, includeGlobs []string) error

func (*Backuper) CleanShadowUUIDs added in v2.7.0

func (b *Backuper) CleanShadowUUIDs(disks []clickhouse.Disk) error

CleanShadowUUIDs - remove only specific shadow backup UUID directories, don't touch other shadows https://github.com/Altinity/clickhouse-backup/issues/1345

func (*Backuper) CollectAllBackups added in v2.6.32

func (b *Backuper) CollectAllBackups(ctx context.Context, ptype string) []BackupInfo

func (*Backuper) CollectLocalBackups added in v2.6.32

func (b *Backuper) CollectLocalBackups(ctx context.Context, ptype string) []BackupInfo

func (*Backuper) CollectRemoteBackups added in v2.6.32

func (b *Backuper) CollectRemoteBackups(ctx context.Context, ptype string) []BackupInfo

func (*Backuper) CreateBackup

func (b *Backuper) CreateBackup(backupName, diffFromRemote, tablePattern string, partitions []string, schemaOnly, createRBAC, rbacOnly, createConfigs, configsOnly, createNamedCollections, namedCollectionsOnly, skipCheckPartsColumns bool, skipProjections []string, resume bool, backupVersion string, commandId int) error

CreateBackup - create new backup of all tables matched by tablePattern If backupName is empty string will use default backup name

func (*Backuper) CreateToRemote

func (b *Backuper) CreateToRemote(backupName string, deleteSource bool, diffFrom, diffFromRemote, tablePattern string, partitions, skipProjections []string, schemaOnly, backupRBAC, rbacOnly, backupConfigs, configsOnly, namedCollections, namedCollectionsOnly, skipCheckPartsColumns, resume bool, version string, commandId int) error

func (*Backuper) Delete

func (b *Backuper) Delete(backupType, backupName string, commandId int) error

Delete - remove local or remote backup

func (*Backuper) Download

func (b *Backuper) Download(backupName string, tablePattern string, partitions []string, schemaOnly, rbacOnly, configsOnly, namedCollectionsOnly, resume bool, hardlinkExistsFiles bool, backupVersion string, commandId int) error

func (*Backuper) GetLocalBackups

func (b *Backuper) GetLocalBackups(ctx context.Context, disks []clickhouse.Disk) ([]LocalBackup, []clickhouse.Disk, error)

GetLocalBackups - return slice of all backups stored locally

func (*Backuper) GetLocalDataSize added in v2.6.3

func (b *Backuper) GetLocalDataSize(ctx context.Context) (float64, error)

func (*Backuper) GetRemoteBackups

func (b *Backuper) GetRemoteBackups(ctx context.Context, parseMetadata bool) ([]storage.Backup, error)

GetRemoteBackups - get all backups stored on remote storage

func (*Backuper) GetStateDir added in v2.6.3

func (b *Backuper) GetStateDir() string

func (*Backuper) GetTableRowsForLocalBackup added in v2.7.0

func (b *Backuper) GetTableRowsForLocalBackup(ctx context.Context, backupName, tablePattern string, printAll bool) ([]TableRow, error)

GetTableRowsForLocalBackup returns per-table rows (db, table, size, parts, disks, skip) for a local backup, reading metadata from disk; intended for callers like the REST API. When printAll is false, tables matching skip_tables are filtered out.

func (*Backuper) GetTableRowsForRemoteBackup added in v2.7.0

func (b *Backuper) GetTableRowsForRemoteBackup(ctx context.Context, backupName, tablePattern string, printAll bool) ([]TableRow, error)

GetTableRowsForRemoteBackup returns per-table rows (db, table, size, parts, disks, skip) for a remote backup, downloading per-table metadata; intended for callers like the REST API. When printAll is false, tables matching skip_tables are filtered out.

func (*Backuper) GetTables

func (b *Backuper) GetTables(ctx context.Context, tablePattern string) ([]clickhouse.Table, error)

GetTables - get all tables for use by CreateBackup, PrintTables, and API

func (*Backuper) GetTablesRemote added in v2.5.0

func (b *Backuper) GetTablesRemote(ctx context.Context, backupName string, tablePattern string) ([]clickhouse.Table, error)

func (*Backuper) List

func (b *Backuper) List(what, ptype, format string) error

List - list backups to stdout from command line

func (*Backuper) NewBackupWatchName

func (b *Backuper) NewBackupWatchName(ctx context.Context, backupType string) (string, error)

func (*Backuper) PrintBackup added in v2.6.32

func (b *Backuper) PrintBackup(backupInfos []BackupInfo, format string) error

func (*Backuper) PrintTables

func (b *Backuper) PrintTables(printAll bool, tablePattern, remoteBackup, localBackup, format string) error

PrintTables - print all tables suitable for backup. When localBackup or remoteBackup is set, list tables from the corresponding backup (per-table size and parts count are read from `metadata.TableMetadata`); both flags may be set simultaneously to render `local` and `remote` sections in one go. Otherwise tables are read from the live ClickHouse server. `format` controls output: text (default), json, yaml, csv, tsv.

func (*Backuper) ReadBackupMetadataLocal

func (b *Backuper) ReadBackupMetadataLocal(ctx context.Context, backupName string) (*metadata.BackupMetadata, error)

func (*Backuper) ReadBackupMetadataRemote

func (b *Backuper) ReadBackupMetadataRemote(ctx context.Context, backupName string) (*metadata.BackupMetadata, error)

func (*Backuper) RemoveBackupLocal

func (b *Backuper) RemoveBackupLocal(ctx context.Context, backupName string, disks []clickhouse.Disk) error

func (*Backuper) RemoveBackupRemote

func (b *Backuper) RemoveBackupRemote(ctx context.Context, backupName string) error

func (*Backuper) RemoveOldBackupsLocal

func (b *Backuper) RemoveOldBackupsLocal(ctx context.Context, keepLastBackup bool, disks []clickhouse.Disk) error

func (*Backuper) RemoveOldBackupsRemote added in v2.4.28

func (b *Backuper) RemoveOldBackupsRemote(ctx context.Context) error

func (*Backuper) Restore

func (b *Backuper) Restore(backupName, tablePattern string, databaseMapping, tableMapping, partitions, skipProjections []string, schemaOnly, dataOnly, dropExists, ignoreDependencies, restoreRBAC, rbacOnly, restoreConfigs, configsOnly, restoreNamedCollections, namedCollectionsOnly, resume, schemaAsAttach, replicatedCopyToDetached, skipEmptyTables bool, backupVersion string, commandId int) error

Restore - restore tables matched by tablePattern from backupName

func (*Backuper) RestoreData

func (b *Backuper) RestoreData(ctx context.Context, backupName string, backupMetadata metadata.BackupMetadata, dataOnly bool, metadataPath, tablePattern string, partitions, skipProjections []string, disks []clickhouse.Disk, version int, replicatedCopyToDetached bool, filteredTables ListOfTables, existingTablesSnapshot []clickhouse.Table) error

RestoreData - restore data for tables matched by tablePattern from backupName

func (*Backuper) RestoreFromRemote

func (b *Backuper) RestoreFromRemote(backupName, tablePattern string, databaseMapping, tableMapping, partitions, skipProjections []string, schemaOnly, dataOnly, dropExists, ignoreDependencies, restoreRBAC, rbacOnly, restoreConfigs, configsOnly, restoreNamedCollections, namedCollectionsOnly, resume, schemaAsAttach, replicatedCopyToDetached, skipEmptyTables, hardlinkExistsFiles bool, version string, commandId int) error

func (*Backuper) RestoreSchema

func (b *Backuper) RestoreSchema(ctx context.Context, backupName string, backupMetadata metadata.BackupMetadata, disks []clickhouse.Disk, tablesForRestore ListOfTables, ignoreDependencies bool, version int, schemaAsAttach bool) error

RestoreSchema - restore schemas matched by tablePattern from backupName

func (*Backuper) Upload

func (b *Backuper) Upload(backupName string, deleteSource bool, diffFrom, diffFromRemote, tablePattern string, partitions, skipProjections []string, schemaOnly, rbacOnly, configsOnly, namedCollectionsOnly, resume bool, backupVersion string, commandId int) error

func (*Backuper) ValidateWatchParams

func (b *Backuper) ValidateWatchParams(watchInterval, fullInterval, watchBackupNameTemplate string) error

func (*Backuper) Watch

func (b *Backuper) Watch(watchInterval, fullInterval, watchBackupNameTemplate, tablePattern string, partitions, skipProjections []string, schemaOnly, backupRBAC, backupConfigs, backupNamedCollections, skipCheckPartsColumns, deleteSource bool, version string, commandId int, metrics *metrics.APIMetrics, cliCtx *cli.Context) error

Watch - run create_remote full + delete local full, even when upload failed

  • if success save backup type full, next will increment, until reach full interval
  • if fail save previous backup type empty, next try will also full

- each watch-interval, run create_remote increment --diff-from=prev-name + delete local increment, even when upload failed

  • save previous backup type incremental, next try will also incremental, until reach full interval

type BackuperOpt

type BackuperOpt func(*Backuper)

func WithBackupSharder

func WithBackupSharder(s backupSharder) BackuperOpt

func WithVersioner

func WithVersioner(v versioner) BackuperOpt

type InfoResult added in v2.7.0

type InfoResult struct {
	BackupName   string     `json:"backup_name" yaml:"backup_name"`
	BackupType   string     `json:"backup_type" yaml:"backup_type"`
	TablePattern string     `json:"table_pattern,omitempty" yaml:"table_pattern,omitempty"`
	TableCount   int        `json:"table_count" yaml:"table_count"`
	TotalBytes   uint64     `json:"total_bytes" yaml:"total_bytes"`
	TotalSize    string     `json:"total_size" yaml:"total_size"`
	TotalParts   int        `json:"total_parts" yaml:"total_parts"`
	Tables       []TableRow `json:"tables" yaml:"tables"`
}

InfoResult wraps a per-backup result with aggregate fields for JSON/YAML output of `tables --local-backup` / `tables --remote-backup`.

type ListOfTables

type ListOfTables []*metadata.TableMetadata

func (ListOfTables) Sort

func (lt ListOfTables) Sort(dropTable bool)

Sort - sorting ListOfTables slice orderly by engine priority

type LocalBackup

type LocalBackup struct {
	metadata.BackupMetadata
	Broken string
}

func GetBackupsToDeleteLocal added in v2.4.28

func GetBackupsToDeleteLocal(backups []LocalBackup, keep int) []LocalBackup

type TableRow added in v2.7.0

type TableRow struct {
	Database   string   `json:"database" yaml:"database" csv:"database"`
	Table      string   `json:"table" yaml:"table" csv:"table"`
	TotalBytes uint64   `json:"total_bytes" yaml:"total_bytes" csv:"total_bytes"`
	Size       string   `json:"size" yaml:"size" csv:"size"`
	Parts      int      `json:"parts" yaml:"parts" csv:"parts"`
	Disks      []string `json:"disks" yaml:"disks" csv:"-"`
	DisksStr   string   `json:"-" yaml:"-" csv:"disks"`
	Skip       bool     `json:"skip" yaml:"skip" csv:"skip"`
	BackupType string   `json:"backup_type,omitempty" yaml:"backup_type,omitempty" csv:"backup_type"`
}

TableRow is the output projection used by the `tables` command for non-text formats. Disks is exposed as a structured list in JSON/YAML and as a comma-joined string in CSV/TSV.

Jump to

Keyboard shortcuts

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