added support for database UUIDs
This commit is contained in:
parent
c9bc6db145
commit
69a8fbe7d8
@ -11,21 +11,22 @@ import clickhouse_connect
|
||||
DUMPFILE = "/tmp/ch_export"
|
||||
createre = re.compile("(?P<begin>CREATE (TABLE|(MATERIALIZED )?VIEW)) (?P<database>\w+)\.(?P<table>\w+) (?P<query>.*)")
|
||||
|
||||
database_exclude = {
|
||||
"default": True,
|
||||
"INFORMATION_SCHEMA": True,
|
||||
"information_schema": True,
|
||||
"system": True,
|
||||
}
|
||||
database_exclude = [
|
||||
"default",
|
||||
"INFORMATION_SCHEMA",
|
||||
"information_schema",
|
||||
"system",
|
||||
]
|
||||
|
||||
def get_databases_tables(client):
|
||||
databases = {}
|
||||
q_db = client.query("show databases;")
|
||||
db_exclude_join = ["'{}'".format(i) for i in database_exclude]
|
||||
q_db_exclude = "({})".format(",".join(db_exclude_join))
|
||||
q_db = client.query(f"SELECT database,toString(uuid) FROM system.databases WHERE database NOT IN {q_db_exclude};")
|
||||
for d in q_db.result_rows:
|
||||
dbname = d[0]
|
||||
if database_exclude.get(dbname):
|
||||
continue
|
||||
databases[dbname] = {"schema":"", "tables":{}}
|
||||
dbuuid = d[1]
|
||||
databases[dbname] = {"ddl": f"CREATE DATABASE {dbname} UUID '{dbuuid}'", "tables":{}}
|
||||
q_tables = client.query(f"show tables from {dbname};")
|
||||
for t in q_tables.result_rows:
|
||||
tablename = t[0]
|
||||
@ -56,13 +57,13 @@ def dump(dumpfile=DUMPFILE):
|
||||
a = json.load(f)
|
||||
for database,values in a.items():
|
||||
print(f"--- database {database} ---")
|
||||
print(f"CREATE DATABASE {database};\n")
|
||||
print("{};\n".format(values["ddl"]))
|
||||
for table,c in values["tables"].items():
|
||||
print(f"-- table {database}.{table} --")
|
||||
print(f"{c};\n")
|
||||
except FileNotFoundError as e:
|
||||
print(e)
|
||||
print("to re-create replicas, run 'clickhouse-client --multiquery < generated_file.sql' on new replica server")
|
||||
print("-- to re-create replicas, run 'clickhouse-client --multiquery < generated_file.sql' on new replica server")
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
|
Loading…
Reference in New Issue
Block a user