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
|
--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
|
## License
|
||||||
|
|
||||||
```text
|
```text
|
||||||
|
@ -45,17 +45,24 @@ def get_databases_tables(client):
|
|||||||
def export(dumpfile=DUMPFILE):
|
def export(dumpfile=DUMPFILE):
|
||||||
client = clickhouse_connect.get_client(host='localhost', username='default', password='')
|
client = clickhouse_connect.get_client(host='localhost', username='default', password='')
|
||||||
databases = get_databases_tables(client)
|
databases = get_databases_tables(client)
|
||||||
|
print(f"exporting to {dumpfile}")
|
||||||
with open(dumpfile, "w") as f:
|
with open(dumpfile, "w") as f:
|
||||||
json.dump(databases, f, indent=4)
|
json.dump(databases, f, indent=4)
|
||||||
return
|
return
|
||||||
|
|
||||||
def dump(dumpfile=DUMPFILE):
|
def dump(dumpfile=DUMPFILE):
|
||||||
|
try:
|
||||||
with open(dumpfile, "r") as f:
|
with open(dumpfile, "r") as f:
|
||||||
a = json.load(f)
|
a = json.load(f)
|
||||||
for database,values in a.items():
|
for database,values in a.items():
|
||||||
|
print(f"--- database {database} ---")
|
||||||
|
print(f"CREATE DATABASE {database};\n")
|
||||||
for table,c in values["tables"].items():
|
for table,c in values["tables"].items():
|
||||||
print(f"# {database}.{table}")
|
print(f"-- table {database}.{table} --")
|
||||||
print(f"{c}\n")
|
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():
|
def main():
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
@ -68,8 +75,10 @@ def main():
|
|||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
if args.export:
|
if args.export:
|
||||||
export(args.dumpfile)
|
export(args.dumpfile)
|
||||||
if args.print_statements:
|
elif args.print_statements:
|
||||||
dump(args.dumpfile)
|
dump(args.dumpfile)
|
||||||
|
else:
|
||||||
|
parser.print_help()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
Loading…
Reference in New Issue
Block a user