ClickHouse/tests/queries/0_stateless/03032_async_backup_restore.sh

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

58 lines
1.7 KiB
Bash
Raw Normal View History

2024-04-02 20:38:02 +00:00
#!/usr/bin/env bash
CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# shellcheck source=../shell_config.sh
. "$CUR_DIR"/../shell_config.sh
2024-08-07 10:55:16 +00:00
${CLICKHOUSE_CLIENT} -m --query "
2024-04-02 20:38:02 +00:00
DROP TABLE IF EXISTS tbl;
DROP TABLE IF EXISTS tbl2;
CREATE TABLE tbl (a Int32) ENGINE = MergeTree() ORDER BY tuple();
INSERT INTO tbl VALUES (2), (80), (-12345);
"
function start_async()
{
local command="$1"
local first_column="s/^\([^\t]*\)\t.*/\1/"
2024-04-18 14:25:33 +00:00
${CLICKHOUSE_CLIENT} --query "$command" | sed "${first_column}"
2024-04-02 20:38:02 +00:00
}
function wait_status()
{
local operation_id="$1"
local expected_status="$2"
local timeout=60
local start=$EPOCHSECONDS
while true; do
2024-04-18 14:25:33 +00:00
local current_status
current_status=$(${CLICKHOUSE_CLIENT} --query "SELECT status FROM system.backups WHERE id='${operation_id}'")
2024-04-02 20:38:02 +00:00
if [ "${current_status}" == "${expected_status}" ]; then
echo "${current_status}"
break
fi
if ((EPOCHSECONDS-start > timeout )); then
echo "Timeout while waiting for operation ${operation_id} to come to status ${expected_status}. The current status is ${current_status}."
exit 1
fi
sleep 0.1
done
}
# Making a backup.
backup_name="Disk('backups', '${CLICKHOUSE_TEST_UNIQUE_NAME}')"
backup_operation_id=$(start_async "BACKUP TABLE tbl TO ${backup_name} ASYNC")
2024-04-18 14:25:33 +00:00
wait_status "${backup_operation_id}" "BACKUP_CREATED"
2024-04-02 20:38:02 +00:00
# Restoring from that backup.
restore_operation_id=$(start_async "RESTORE TABLE tbl AS tbl2 FROM ${backup_name} ASYNC")
2024-04-18 14:25:33 +00:00
wait_status "${restore_operation_id}" "RESTORED"
2024-04-02 20:38:02 +00:00
# Check the result of that restoration.
${CLICKHOUSE_CLIENT} --query "SELECT * FROM tbl2"
2024-08-07 10:55:16 +00:00
${CLICKHOUSE_CLIENT} -m --query "
2024-04-02 20:38:02 +00:00
DROP TABLE tbl;
DROP TABLE tbl2;
"