|
7 | 7 | "context" |
8 | 8 | "encoding/json" |
9 | 9 | "fmt" |
| 10 | + "github.com/Altinity/clickhouse-backup/v2/pkg/common" |
10 | 11 | "github.com/Altinity/clickhouse-backup/v2/pkg/config" |
11 | 12 | pool "github.com/jolestar/go-commons-pool/v2" |
12 | 13 | "math/rand" |
@@ -2385,7 +2386,47 @@ func TestCheckSystemPartsColumns(t *testing.T) { |
2385 | 2386 | env.Cleanup(t, r) |
2386 | 2387 | } |
2387 | 2388 |
|
2388 | | -// // https://github.com/Altinity/clickhouse-backup/issues/871 |
| 2389 | +// https://github.com/Altinity/clickhouse-backup/issues/1151 |
| 2390 | +func TestSlashesInDatabaseAndTableNamesAndTableQuery(t *testing.T) { |
| 2391 | + env, r := NewTestEnvironment(t) |
| 2392 | + env.connectWithWait(t, r, 500*time.Millisecond, 1*time.Second, 1*time.Minute) |
| 2393 | + version, err := env.ch.GetVersion(t.Context()) |
| 2394 | + r.NoError(err) |
| 2395 | + |
| 2396 | + dbName := `db\db2/db3` |
| 2397 | + tableName := `z\z2/z3` |
| 2398 | + createSchemaSQL := "(`s`" + ` String DEFAULT replaceRegexpAll('test', '(\\\\=|\\\\\\\\)', '\\\\\\\\\\\\1')) ENGINE = MergeTree ORDER BY s` |
| 2399 | + createTableSQL := fmt.Sprintf("CREATE TABLE `%s`.`%s` "+createSchemaSQL, dbName, tableName) |
| 2400 | + env.queryWithNoError(r, fmt.Sprintf("CREATE DATABASE `%s`", dbName)) |
| 2401 | + env.queryWithNoError(r, createTableSQL) |
| 2402 | + env.DockerExecNoError(r, "clickhouse-backup", "clickhouse-backup", "create", "--env", "CLICKHOUSE_HOST=clickhouse", "--tables", dbName+".*", t.Name()) |
| 2403 | + |
| 2404 | + backupTableFile := fmt.Sprintf("/var/lib/clickhouse/backup/%s/metadata/%s/%s.json", t.Name(), common.TablePathEncode(dbName), common.TablePathEncode(tableName)) |
| 2405 | + backupContent, err := env.DockerExecOut("clickhouse-backup", "cat", backupTableFile) |
| 2406 | + r.NoError(err) |
| 2407 | + escapedCreateTableSQL := fmt.Sprintf("CREATE TABLE `%s`.`%s`", strings.ReplaceAll(dbName, `\`, `\\`), strings.ReplaceAll(tableName, `\`, `\\`)) |
| 2408 | + escapedSchemaSQL := strings.ReplaceAll(createSchemaSQL, `\`, `\\`) |
| 2409 | + r.Contains(backupContent, escapedCreateTableSQL) |
| 2410 | + r.Contains(backupContent, escapedSchemaSQL) |
| 2411 | + |
| 2412 | + r.NoError(env.ch.DropOrDetachTable(clickhouse.Table{Database: dbName, Name: tableName, CreateTableQuery: createTableSQL}, createTableSQL, "", false, version, "", false, "")) |
| 2413 | + r.NoError(env.dropDatabase(dbName, false)) |
| 2414 | + env.DockerExecNoError(r, "clickhouse-backup", "clickhouse-backup", "restore", "--config", "/etc/clickhouse-backup/config-s3.yml", "--tables", dbName+".*", t.Name()) |
| 2415 | + restoredSQL := "" |
| 2416 | + r.NoError(env.ch.SelectSingleRow(t.Context(), &restoredSQL, fmt.Sprintf("SHOW CREATE TABLE `%s`.`%s`", dbName, tableName))) |
| 2417 | + |
| 2418 | + r.Contains(restoredSQL, escapedCreateTableSQL) |
| 2419 | + //SHOW CREATE SQL transform original query |
| 2420 | + restoredSQL = regexp.MustCompile(`[\n\s]+`).ReplaceAllString(restoredSQL, " ") |
| 2421 | + restoredSQL = regexp.MustCompile(`\(\s+`).ReplaceAllString(restoredSQL, "(") |
| 2422 | + restoredSQL = regexp.MustCompile(`\s+\)`).ReplaceAllString(restoredSQL, ")") |
| 2423 | + r.Contains(restoredSQL, createSchemaSQL) |
| 2424 | + |
| 2425 | + r.NoError(env.dropDatabase(dbName, false)) |
| 2426 | + env.Cleanup(t, r) |
| 2427 | +} |
| 2428 | + |
| 2429 | +// https://github.com/Altinity/clickhouse-backup/issues/871 |
2389 | 2430 | func TestKeepBackupRemoteAndDiffFromRemote(t *testing.T) { |
2390 | 2431 | if isTestShouldSkip("RUN_ADVANCED_TESTS") { |
2391 | 2432 | t.Skip("Skipping Advanced integration tests...") |
|
0 commit comments