updated help, fixed tables
This commit is contained in:
parent
0f2cfd9454
commit
c9bc6db145
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/tmp
|
17
README.md
17
README.md
@ -16,6 +16,23 @@ options:
|
||||
--print-statements
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
Export tables from source node
|
||||
```
|
||||
clickhouse_ddl_export.py --export /tmp/source_db_tables.json
|
||||
clickhouse_ddl_export.py --print-statements /tmp/source_db_tables.json > /tmp/ddl.sql
|
||||
```
|
||||
|
||||
In destination node
|
||||
```
|
||||
clickhouse client --multiquery < /tmp/ddl.sql
|
||||
```
|
||||
|
||||
Then replication is applied, and data is fetched from source node(s)
|
||||
|
||||
Have fun!
|
||||
|
||||
## License
|
||||
|
||||
```text
|
||||
|
@ -45,17 +45,24 @@ def get_databases_tables(client):
|
||||
def export(dumpfile=DUMPFILE):
|
||||
client = clickhouse_connect.get_client(host='localhost', username='default', password='')
|
||||
databases = get_databases_tables(client)
|
||||
print(f"exporting to {dumpfile}")
|
||||
with open(dumpfile, "w") as f:
|
||||
json.dump(databases, f, indent=4)
|
||||
return
|
||||
|
||||
def dump(dumpfile=DUMPFILE):
|
||||
try:
|
||||
with open(dumpfile, "r") as f:
|
||||
a = json.load(f)
|
||||
for database,values in a.items():
|
||||
print(f"--- database {database} ---")
|
||||
print(f"CREATE DATABASE {database};\n")
|
||||
for table,c in values["tables"].items():
|
||||
print(f"# {database}.{table}")
|
||||
print(f"{c}\n")
|
||||
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")
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
@ -68,8 +75,10 @@ def main():
|
||||
args = parser.parse_args()
|
||||
if args.export:
|
||||
export(args.dumpfile)
|
||||
if args.print_statements:
|
||||
elif args.print_statements:
|
||||
dump(args.dumpfile)
|
||||
else:
|
||||
parser.print_help()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
Loading…
Reference in New Issue
Block a user