mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-17 13:13:36 +00:00
59 lines
2.0 KiB
Python
59 lines
2.0 KiB
Python
|
import pytest
|
||
|
from helpers.cluster import ClickHouseCluster
|
||
|
from helpers.test_tools import TSV
|
||
|
|
||
|
|
||
|
cluster = ClickHouseCluster(__file__)
|
||
|
|
||
|
instance = cluster.add_instance(
|
||
|
"instance",
|
||
|
main_configs=["configs/config.xml", "configs/config.d/backups.xml"],
|
||
|
stay_alive=True,
|
||
|
)
|
||
|
|
||
|
|
||
|
@pytest.fixture(scope="module", autouse=True)
|
||
|
def start_cluster():
|
||
|
try:
|
||
|
cluster.start()
|
||
|
yield cluster
|
||
|
finally:
|
||
|
cluster.shutdown()
|
||
|
|
||
|
|
||
|
def back_table_up(backup_name):
|
||
|
instance.query("CREATE DATABASE test")
|
||
|
instance.query("CREATE TABLE test.table(x UInt32) ENGINE=MergeTree ORDER BY x")
|
||
|
instance.query("INSERT INTO test.table SELECT number FROM numbers(10)")
|
||
|
return instance.query(f"BACKUP TABLE test.table TO {backup_name}").split("\t")[0]
|
||
|
|
||
|
|
||
|
def restore_table(backup_name):
|
||
|
return instance.query(f"RESTORE TABLE test.table FROM {backup_name}").split("\t")[0]
|
||
|
|
||
|
|
||
|
def test_backup_log():
|
||
|
backup_name = "File('/backups/test_backup/')"
|
||
|
assert instance.query("SELECT * FROM system.tables WHERE name = 'backup_log'") == ""
|
||
|
|
||
|
backup_id = back_table_up(backup_name)
|
||
|
assert instance.query(
|
||
|
f"SELECT status, error FROM system.backup_log WHERE id='{backup_id}' ORDER BY event_date, event_time_microseconds"
|
||
|
) == TSV([["CREATING_BACKUP", ""], ["BACKUP_CREATED", ""]])
|
||
|
|
||
|
instance.query("DROP TABLE test.table SYNC")
|
||
|
|
||
|
restore_id = restore_table(backup_name)
|
||
|
assert instance.query(
|
||
|
f"SELECT status, error FROM system.backup_log WHERE id='{restore_id}' ORDER BY event_date, event_time_microseconds"
|
||
|
) == TSV([["RESTORING", ""], ["RESTORED", ""]])
|
||
|
|
||
|
instance.restart_clickhouse()
|
||
|
|
||
|
assert instance.query(
|
||
|
f"SELECT status, error FROM system.backup_log WHERE id='{backup_id}' ORDER BY event_date, event_time_microseconds"
|
||
|
) == TSV([["CREATING_BACKUP", ""], ["BACKUP_CREATED", ""]])
|
||
|
assert instance.query(
|
||
|
f"SELECT status, error FROM system.backup_log WHERE id='{restore_id}' ORDER BY event_date, event_time_microseconds"
|
||
|
) == TSV([["RESTORING", ""], ["RESTORED", ""]])
|