Skip to content

Commit 8a9447a

Browse files
committed
final improvements for check system.clusters during restore engine=Distributed and is not exists and if not macros use RESTORE_SCHEMA_ON_CLUSTER or CLICKHOUSE_RESTORE_DISTRIBUTED_CLUSTER config parameter as cluster value, fix #1252
Signed-off-by: Slach <[email protected]>
1 parent 9d07576 commit 8a9447a

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

pkg/backup/restore.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,12 @@ func (b *Backuper) Restore(backupName, tablePattern string, databaseMapping, tab
104104
log.Warn().Msgf("%v", err)
105105
return ErrUnknownClickhouseDataPath
106106
}
107-
if b.cfg.General.RestoreSchemaOnCluster != "" {
108-
if b.cfg.General.RestoreSchemaOnCluster, err = b.ch.ApplyMacros(ctx, b.cfg.General.RestoreSchemaOnCluster); err != nil {
109-
log.Warn().Msgf("%v", err)
110-
return err
111-
}
112-
}
107+
//if b.cfg.General.RestoreSchemaOnCluster != "" && version < 22000000 {
108+
// if b.cfg.General.RestoreSchemaOnCluster, err = b.ch.ApplyMacros(ctx, b.cfg.General.RestoreSchemaOnCluster); err != nil {
109+
// log.Warn().Msgf("%v", err)
110+
// return err
111+
// }
112+
//}
113113
b.adjustResumeFlag(resume)
114114
backupMetafileLocalPaths := []string{path.Join(b.DefaultDataPath, "backup", backupName, "metadata.json")}
115115
var backupMetadataBody []byte

pkg/clickhouse/clickhouse.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ func (ch *ClickHouse) CreateTable(table Table, query string, dropTable, ignoreDe
10201020
}
10211021

10221022
// https://github.com/Altinity/clickhouse-backup/issues/574, replace ENGINE=Distributed to new cluster name
1023-
// https://github.com/Altinity/clickhouse-backup/issues/1252, check exists
1023+
// https://github.com/Altinity/clickhouse-backup/issues/1252, if cluster don't exist, replace it to RESTORE_SCHEMA_ON_CLUSTER or CLICKHOUSE_RESTORE_DISTRIBUTED_CLUSTER
10241024
if distributedRE.MatchString(query) {
10251025
matches := distributedRE.FindAllStringSubmatch(query, -1)
10261026
oldCluster := strings.Trim(matches[0][2], "'\" ")
@@ -1035,7 +1035,7 @@ func (ch *ClickHouse) CreateTable(table Table, query string, dropTable, ignoreDe
10351035
}
10361036
}
10371037
if newCluster != "" && existCluster == "" && newCluster != oldCluster && !macroRE.MatchString(oldCluster) {
1038-
newCluster = "'" + strings.Trim(ch.Config.RestoreDistributedCluster, "'\" ") + "'"
1038+
newCluster = "'" + strings.Trim(newCluster, "'\" ") + "'"
10391039
log.Warn().Msgf("will replace cluster ENGINE=Distributed %s -> %s", matches[0][2], newCluster)
10401040
query = distributedRE.ReplaceAllString(query, fmt.Sprintf("${1}(%s,${3})", newCluster))
10411041
}

0 commit comments

Comments
 (0)