diff --git a/regression-test/suites/backup_restore/test_backup_restore.groovy b/regression-test/suites/backup_restore/test_backup_restore.groovy index 0fccd42bef..68f73f6892 100644 --- a/regression-test/suites/backup_restore/test_backup_restore.groovy +++ b/regression-test/suites/backup_restore/test_backup_restore.groovy @@ -56,7 +56,7 @@ suite("test_backup_restore", "backup_restore") { Thread.sleep(3000) } - snapshot = syncer.getSnapshotTimestamp(repoName, snapshotName) + def snapshot = syncer.getSnapshotTimestamp(repoName, snapshotName) assertTrue(snapshot != null) sql "TRUNCATE TABLE ${dbName}.${tableName}" diff --git a/regression-test/suites/backup_restore/test_backup_restore_alias.groovy b/regression-test/suites/backup_restore/test_backup_restore_alias.groovy index 532d04ed13..57851fa824 100644 --- a/regression-test/suites/backup_restore/test_backup_restore_alias.groovy +++ b/regression-test/suites/backup_restore/test_backup_restore_alias.groovy @@ -57,7 +57,7 @@ suite("test_backup_restore_alias", "backup_restore") { Thread.sleep(3000) } - snapshot = syncer.getSnapshotTimestamp(repoName, snapshotName) + def snapshot = syncer.getSnapshotTimestamp(repoName, snapshotName) assertTrue(snapshot != null) sql "INSERT INTO ${dbName}.${tableName} VALUES (20, 21), (123, 341)" diff --git a/regression-test/suites/backup_restore/test_backup_restore_db.groovy b/regression-test/suites/backup_restore/test_backup_restore_db.groovy new file mode 100644 index 0000000000..7f3c6e5f83 --- /dev/null +++ b/regression-test/suites/backup_restore/test_backup_restore_db.groovy @@ -0,0 +1,96 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +suite("test_backup_restore_db", "backup_restore") { + String dbName = "backup_restore_db_1" + String suiteName = "test_backup_restore_db" + String repoName = "${suiteName}_repo" + String snapshotName = "${suiteName}_snapshot" + String tableNamePrefix = "${suiteName}_tables" + + def syncer = getSyncer() + syncer.createS3Repository(repoName) + sql "CREATE DATABASE IF NOT EXISTS ${dbName}" + + int numTables = 10; + int numRows = 10; + List tables = [] + for (int i = 0; i < numTables; ++i) { + String tableName = "${tableNamePrefix}_${i}" + tables.add(tableName) + sql "DROP TABLE IF EXISTS ${dbName}.${tableName}" + sql """ + CREATE TABLE ${dbName}.${tableName} ( + `id` LARGEINT NOT NULL, + `count` LARGEINT SUM DEFAULT "0" + ) + AGGREGATE KEY(`id`) + DISTRIBUTED BY HASH(`id`) BUCKETS 2 + PROPERTIES + ( + "replication_num" = "1" + ) + """ + List values = [] + for (int j = 1; j <= numRows; ++j) { + values.add("(${j}, ${j})") + } + sql "INSERT INTO ${dbName}.${tableName} VALUES ${values.join(",")}" + def result = sql "SELECT * FROM ${dbName}.${tableName}" + assertEquals(result.size(), numRows); + } + + sql """ + BACKUP SNAPSHOT ${dbName}.${snapshotName} + TO `${repoName}` + """ + + while (!syncer.checkSnapshotFinish(dbName)) { + Thread.sleep(3000) + } + + def snapshot = syncer.getSnapshotTimestamp(repoName, snapshotName) + assertTrue(snapshot != null) + + for (def tableName in tables) { + sql "TRUNCATE TABLE ${dbName}.${tableName}" + } + + sql """ + RESTORE SNAPSHOT ${dbName}.${snapshotName} + FROM `${repoName}` + PROPERTIES + ( + "backup_timestamp" = "${snapshot}", + "replication_num" = "1" + ) + """ + + while (!syncer.checkAllRestoreFinish(dbName)) { + Thread.sleep(3000) + } + + for (def tableName in tables) { + result = sql "SELECT * FROM ${dbName}.${tableName}" + assertEquals(result.size(), numRows); + sql "DROP TABLE ${dbName}.${tableName} FORCE" + } + + sql "DROP DATABASE ${dbName} FORCE" + sql "DROP REPOSITORY `${repoName}`" +} + diff --git a/regression-test/suites/backup_restore/test_backup_restore_exclude.groovy b/regression-test/suites/backup_restore/test_backup_restore_exclude.groovy index 6d248bb47f..012d77cc75 100644 --- a/regression-test/suites/backup_restore/test_backup_restore_exclude.groovy +++ b/regression-test/suites/backup_restore/test_backup_restore_exclude.groovy @@ -65,7 +65,7 @@ suite("test_backup_restore_exclude", "backup_restore") { Thread.sleep(3000) } - snapshot = syncer.getSnapshotTimestamp(repoName, snapshotName) + def snapshot = syncer.getSnapshotTimestamp(repoName, snapshotName) assertTrue(snapshot != null) // Overwrite exists table. diff --git a/regression-test/suites/backup_restore/test_backup_restore_multi_tables.groovy b/regression-test/suites/backup_restore/test_backup_restore_multi_tables.groovy index 109a4a1304..a795ae0ded 100644 --- a/regression-test/suites/backup_restore/test_backup_restore_multi_tables.groovy +++ b/regression-test/suites/backup_restore/test_backup_restore_multi_tables.groovy @@ -65,7 +65,7 @@ suite("test_backup_restore_multi_tables", "backup_restore") { Thread.sleep(3000) } - snapshot = syncer.getSnapshotTimestamp(repoName, snapshotName) + def snapshot = syncer.getSnapshotTimestamp(repoName, snapshotName) assertTrue(snapshot != null) for (def tableName in backupTables) { diff --git a/regression-test/suites/backup_restore/test_backup_restore_multi_tables_overwrite.groovy b/regression-test/suites/backup_restore/test_backup_restore_multi_tables_overwrite.groovy index e7e2a7f3fe..67cf37bc6e 100644 --- a/regression-test/suites/backup_restore/test_backup_restore_multi_tables_overwrite.groovy +++ b/regression-test/suites/backup_restore/test_backup_restore_multi_tables_overwrite.groovy @@ -65,7 +65,7 @@ suite("test_backup_restore_multi_tables_overwrite", "backup_restore") { Thread.sleep(3000) } - snapshot = syncer.getSnapshotTimestamp(repoName, snapshotName) + def snapshot = syncer.getSnapshotTimestamp(repoName, snapshotName) assertTrue(snapshot != null) // Overwrite exists table. diff --git a/regression-test/suites/backup_restore/test_restore_mix_exists_and_new_table.groovy b/regression-test/suites/backup_restore/test_restore_mix_exists_and_new_table.groovy index 2c9b0b31ae..7bb6c91c19 100644 --- a/regression-test/suites/backup_restore/test_restore_mix_exists_and_new_table.groovy +++ b/regression-test/suites/backup_restore/test_restore_mix_exists_and_new_table.groovy @@ -64,7 +64,7 @@ suite("test_restore_mix_exists_and_new_table", "backup_restore") { Thread.sleep(3000) } - snapshot = syncer.getSnapshotTimestamp(repoName, snapshotName) + def snapshot = syncer.getSnapshotTimestamp(repoName, snapshotName) assertTrue(snapshot != null) def dropTables = tables[0..5] diff --git a/regression-test/suites/backup_restore/test_restore_to_new_table.groovy b/regression-test/suites/backup_restore/test_restore_to_new_table.groovy index 74d2ec08bb..76f82eb8c9 100644 --- a/regression-test/suites/backup_restore/test_restore_to_new_table.groovy +++ b/regression-test/suites/backup_restore/test_restore_to_new_table.groovy @@ -56,7 +56,7 @@ suite("test_restore_to_new_table", "backup_restore") { Thread.sleep(3000) } - snapshot = syncer.getSnapshotTimestamp(repoName, snapshotName) + def snapshot = syncer.getSnapshotTimestamp(repoName, snapshotName) assertTrue(snapshot != null) sql "DROP TABLE ${dbName}.${tableName} FORCE"