Documentation
¶
Index ¶
- Constants
- Variables
- func IsInformationSchema(database string) bool
- func NewBackupName() string
- func ShallSkipDatabase(cfg *config.Config, targetDB, tablePattern string) bool
- type BackupInfo
- type Backuper
- func (b *Backuper) AddTableToLocalBackup(ctx context.Context, backupName string, ...) (map[string][]metadata.Part, map[string]int64, map[string]int64, ...)
- func (b *Backuper) CalculateMaxSize(ctx context.Context) error
- func (b *Backuper) CalculateNonSkipTables(tables []clickhouse.Table) int
- func (b *Backuper) CheckDisksUsage(backup storage.Backup, disks []clickhouse.Disk, isResumeExists bool, ...) error
- func (b *Backuper) Classify(err error) retrier.Action
- func (b *Backuper) Clean(ctx context.Context) error
- func (b *Backuper) CleanBrokenRetention(commandId int, includeGlobs, excludeGlobs []string, commit bool) error
- func (b *Backuper) CleanLocalBroken(commandId int) error
- func (b *Backuper) CleanRemoteBroken(commandId int, includeGlobs []string) error
- func (b *Backuper) CleanShadowUUIDs(disks []clickhouse.Disk) error
- func (b *Backuper) CollectAllBackups(ctx context.Context, ptype string) []BackupInfo
- func (b *Backuper) CollectLocalBackups(ctx context.Context, ptype string) []BackupInfo
- func (b *Backuper) CollectRemoteBackups(ctx context.Context, ptype string) []BackupInfo
- func (b *Backuper) CreateBackup(backupName, diffFromRemote, tablePattern string, partitions []string, ...) error
- func (b *Backuper) CreateToRemote(backupName string, deleteSource bool, ...) error
- func (b *Backuper) Delete(backupType, backupName string, commandId int) error
- func (b *Backuper) Download(backupName string, tablePattern string, partitions []string, ...) error
- func (b *Backuper) GetLocalBackups(ctx context.Context, disks []clickhouse.Disk) ([]LocalBackup, []clickhouse.Disk, error)
- func (b *Backuper) GetLocalDataSize(ctx context.Context) (float64, error)
- func (b *Backuper) GetRemoteBackups(ctx context.Context, parseMetadata bool) ([]storage.Backup, error)
- func (b *Backuper) GetStateDir() string
- func (b *Backuper) GetTableRowsForLive(ctx context.Context, tablePattern string, ...) ([]TableRow, error)
- func (b *Backuper) GetTableRowsForLocalBackup(ctx context.Context, backupName, tablePattern string, ...) ([]TableRow, error)
- func (b *Backuper) GetTableRowsForRemoteBackup(ctx context.Context, backupName, tablePattern string, ...) ([]TableRow, error)
- func (b *Backuper) GetTables(ctx context.Context, tablePattern string) ([]clickhouse.Table, error)
- func (b *Backuper) List(what, ptype, format string) error
- func (b *Backuper) NewBackupWatchName(ctx context.Context, backupType string) (string, error)
- func (b *Backuper) PrintBackup(backupInfos []BackupInfo, format string) error
- func (b *Backuper) PrintTables(printAll bool, tablePattern, remoteBackup, localBackup, format string, ...) error
- func (b *Backuper) ReadBackupMetadataLocal(ctx context.Context, backupName string) (*metadata.BackupMetadata, error)
- func (b *Backuper) ReadBackupMetadataRemote(ctx context.Context, backupName string) (*metadata.BackupMetadata, error)
- func (b *Backuper) Rebalance(backupName string, tablePattern string, dryRun bool, commandId int) error
- func (b *Backuper) Rebase(backupName string, commandId int) error
- func (b *Backuper) RemoveBackupLocal(ctx context.Context, backupName string, disks []clickhouse.Disk) error
- func (b *Backuper) RemoveBackupRemote(ctx context.Context, backupName string) error
- func (b *Backuper) RemoveOldBackupsLocal(ctx context.Context, keepLastBackup bool, disks []clickhouse.Disk) error
- func (b *Backuper) RemoveOldBackupsRemote(ctx context.Context) error
- func (b *Backuper) Restore(backupName, tablePattern string, ...) error
- func (b *Backuper) RestoreData(ctx context.Context, backupName string, backupMetadata metadata.BackupMetadata, ...) error
- func (b *Backuper) RestoreFromRemote(backupName, tablePattern string, ...) error
- func (b *Backuper) RestoreSchema(ctx context.Context, backupName string, backupMetadata metadata.BackupMetadata, ...) error
- func (b *Backuper) Upload(backupName string, deleteSource bool, ...) error
- func (b *Backuper) ValidateWatchParams(watchInterval, fullInterval, watchBackupNameTemplate string, ...) error
- func (b *Backuper) Watch(watchInterval, fullInterval, watchBackupNameTemplate string, ...) error
- type BackuperOpt
- type InfoResult
- type ListOfTables
- type LocalBackup
- type PartRow
- type PartitionRow
- type TableRow
Constants ¶
const ( // TimeFormatForBackup - default backup name format TimeFormatForBackup = "2006-01-02T15-04-05" MetaFileName = "metadata.json" )
const DirectoryFormat = "directory"
Variables ¶
var CreateDatabaseRE = regexp.MustCompile(`(?m)^CREATE DATABASE (\s*)(\S+)(\s*)(.*)`)
var (
ErrBackupIsAlreadyExists = errors.New("backup is already exists")
)
var ( // ErrUnknownClickhouseDataPath - ErrUnknownClickhouseDataPath = errors.New("clickhouse data path is unknown, you can set data_path in config file") )
var UUIDWithMergeTreeRE = regexp.MustCompile(`^(.+)(UUID)(\s+)'([^']+)'(.+)({uuid})(.*)`)
Functions ¶
func IsInformationSchema ¶
Types ¶
type BackupInfo ¶ added in v2.6.32
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, map[string][]metadata.Part, error)
AddTableToLocalBackup freezes a table and moves its parts into the local backup. It returns the per-disk parts/sizes/checksums plus the per-disk data parts that were skipped as broken. Broken parts are only tolerated (skipped instead of aborting) when general.max_broken_part_ratio > 0; the caller aggregates the broken/total counts across all tables, enforces the configured ratio and stores the broken parts in the table metadata, see https://github.com/Altinity/clickhouse-backup/issues/1418
func (*Backuper) CalculateMaxSize ¶ added in v2.6.0
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) 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 (*Backuper) CleanRemoteBroken ¶
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) 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 (*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 (*Backuper) GetTableRowsForLive ¶ added in v2.8.0
func (b *Backuper) GetTableRowsForLive(ctx context.Context, tablePattern string, printAll, listParts, listPartitions bool) ([]TableRow, error)
GetTableRowsForLive returns per-table rows for the live ClickHouse server, optionally including the parts/partitions breakdown from `system.parts` (see collectTablesFromLive); intended for callers like the REST API. When printAll is false, tables matching skip_tables are filtered out.
func (*Backuper) GetTableRowsForLocalBackup ¶ added in v2.7.0
func (b *Backuper) GetTableRowsForLocalBackup(ctx context.Context, backupName, tablePattern string, printAll, listParts, listPartitions 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, listParts, listPartitions 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 ¶
GetTables - get all tables for use by CreateBackup, PrintTables, and API
func (*Backuper) NewBackupWatchName ¶
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, listParts, listPartitions bool) 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. `listParts` and `listPartitions` are independent toggles, usable alone or together, against the live server or `--local-backup`/`--remote-backup` alike:
- listParts attaches every physical part (name, partition_id, and against the live server also size), read from `system.parts` live or from backup metadata otherwise.
- listPartitions attaches the distinct partitions (parts grouped by partition_id), with the human-readable partition value and size only available against the live server.
Against `--local-backup`/`--remote-backup`, partition_id is derived from each part's name (the `_`-delimited prefix, same convention as filesystemhelper.IsPartInPartition).
func (*Backuper) ReadBackupMetadataLocal ¶
func (*Backuper) ReadBackupMetadataRemote ¶
func (*Backuper) Rebalance ¶ added in v2.8.0
func (b *Backuper) Rebalance(backupName string, tablePattern string, dryRun bool, commandId int) error
Rebalance - move data parts of a local backup between disks, https://github.com/Altinity/clickhouse-backup/issues/1024 Rule 1: the live part from system.parts is on the same disk as in the backup - do nothing; Rule 2: the live part is on another usable disk - hardlink it into the backup shadow on that disk; Rule 3: the part is not in system.parts - copy it to the policy disk of the same type with the most effective free space; a part on a still valid disk (present in system.disks and in the table storage policy) moves only to a strictly roomier disk, a part on an invalid disk must move or the command fails; parts on object disks are skipped, metadata in table.json / metadata.json is rewritten accordingly
func (*Backuper) Rebase ¶ added in v2.8.0
Rebase - copy required parts from the required backups chain into backupName on remote storage and remove the required_backup dependency, so backupName becomes a full backup
func (*Backuper) RemoveBackupLocal ¶
func (*Backuper) RemoveBackupRemote ¶
func (*Backuper) RemoveOldBackupsLocal ¶
func (*Backuper) RemoveOldBackupsRemote ¶ added in v2.4.28
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) ValidateWatchParams ¶
func (*Backuper) Watch ¶
func (b *Backuper) Watch(watchInterval, fullInterval, watchBackupNameTemplate string, schedules []string, 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 PartRow ¶ added in v2.8.0
type PartRow struct {
Name string `json:"name" yaml:"name" csv:"name"`
PartitionID string `json:"partition_id" yaml:"partition_id" csv:"partition_id"`
TotalBytes uint64 `json:"total_bytes,omitempty" yaml:"total_bytes,omitempty" csv:"total_bytes"`
Size string `json:"size,omitempty" yaml:"size,omitempty" csv:"size"`
}
PartRow describes one physical data part of a table, as returned by `tables --list-parts` (alias `--parts`). Against the live server it comes straight from `system.parts`; against `--local-backup`/`--remote-backup` only Name and PartitionID are available (from backup metadata), PartitionID being the `_`-delimited prefix of Name, same convention as filesystemhelper.IsPartInPartition.
type PartitionRow ¶ added in v2.8.0
type PartitionRow struct {
PartitionID string `json:"partition_id" yaml:"partition_id" csv:"partition_id"`
Partition string `json:"partition,omitempty" yaml:"partition,omitempty" csv:"partition"`
Parts int `json:"parts" yaml:"parts" csv:"parts"`
TotalBytes uint64 `json:"total_bytes,omitempty" yaml:"total_bytes,omitempty" csv:"total_bytes"`
Size string `json:"size,omitempty" yaml:"size,omitempty" csv:"size"`
}
PartitionRow describes one distinct partition of a table (parts grouped by partition_id), as returned by `tables --partitions` (alias `--list-partitions`). Against the live server it comes from `system.parts`, including the human-readable Partition value and total size. Against `--local-backup`/`--remote-backup` it's aggregated from part names (same convention as PartRow.PartitionID), so Partition/TotalBytes/Size stay empty/zero there.
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"`
PartsList []PartRow `json:"parts_list,omitempty" yaml:"parts_list,omitempty" csv:"-"`
Partitions []PartitionRow `json:"partitions,omitempty" yaml:"partitions,omitempty" csv:"-"`
}
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.