|
| 1 | +<!-- |
| 2 | +
|
| 3 | + Licensed to the Apache Software Foundation (ASF) under one |
| 4 | + or more contributor license agreements. See the NOTICE file |
| 5 | + distributed with this work for additional information |
| 6 | + regarding copyright ownership. The ASF licenses this file |
| 7 | + to you under the Apache License, Version 2.0 (the |
| 8 | + "License"); you may not use this file except in compliance |
| 9 | + with the License. You may obtain a copy of the License at |
| 10 | + |
| 11 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | + |
| 13 | + Unless required by applicable law or agreed to in writing, |
| 14 | + software distributed under the License is distributed on an |
| 15 | + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 16 | + KIND, either express or implied. See the License for the |
| 17 | + specific language governing permissions and limitations |
| 18 | + under the License. |
| 19 | +
|
| 20 | +--> |
| 21 | + |
| 22 | +# Schema Export |
| 23 | + |
| 24 | +## 1. Overview |
| 25 | + |
| 26 | +The schema export tool `export-schema.sh/bat` is located in the `tools` directory. It can export schema from a specified database in IoTDB to a script file. |
| 27 | + |
| 28 | +## 2. Detailed Functionality |
| 29 | + |
| 30 | +### 2.1 Parameter |
| 31 | + |
| 32 | +| **Short Param** | **Full Param** | **Description** | Required | Default | |
| 33 | +| ----------------------- | -------------------------- | ------------------------------------------------------------------------ | ------------------------------------- | -------------------------------------------------------- | |
| 34 | +| `-h` | `-- host` | Hostname | No | 127.0.0.1 | |
| 35 | +| `-p` | `--port` | Port number | No | 6667 | |
| 36 | +| `-u` | `--username` | Username | No | root | |
| 37 | +| `-pw` | `--password` | Password | No | root | |
| 38 | +| `-sql_dialect` | `--sql_dialect` | Specifies whether the server uses`tree `model or`table `model | No | tree | |
| 39 | +| `-db` | `--database` | Target database to export (only applies when`-sql_dialect=table`) | Required if`-sql_dialect=table` | - | |
| 40 | +| `-table` | `--table` | Target table to export (only applies when`-sql_dialect=table`) | No | - | |
| 41 | +| `-t` | `--target` | Output directory (created if it doesn't exist) | Yes | | |
| 42 | +| `-path` | `--path_pattern` | Path pattern for metadata export | Required if`-sql_dialect=tree` | | |
| 43 | +| `-pfn` | `--prefix_file_name` | Output filename prefix | No | `dump_dbname.sql` | |
| 44 | +| `-lpf` | `--lines_per_file` | Maximum lines per dump file (only applies when`-sql_dialect=tree`) | No | `10000` | |
| 45 | +| `-timeout` | `--query_timeout` | Query timeout in milliseconds (`-1`= no timeout) | No | -1Range:`-1 to Long. max=9223372036854775807` | |
| 46 | +| `-help` | `--help` | Display help information | No | | |
| 47 | + |
| 48 | +### 2.2 Command |
| 49 | + |
| 50 | +```Bash |
| 51 | +Shell |
| 52 | +# Unix/OS X |
| 53 | +> tools/export-schema.sh [-sql_dialect<sql_dialect>] -db<database> -table<table> |
| 54 | + [-h <host>] [-p <port>] [-u <username>] [-pw <password>] |
| 55 | + -t <target_directory> [-path <exportPathPattern>] [-pfn <prefix_file_name>] |
| 56 | + [-lpf <lines_per_file>] [-timeout <query_timeout>] |
| 57 | +# Windows |
| 58 | +> tools\export-schema.bat [-sql_dialect<sql_dialect>] -db<database> -table<table> |
| 59 | + [-h <host>] [-p <port>] [-u <username>] [-pw <password>] |
| 60 | + -t <target_directory> [-path <exportPathPattern>] [-pfn <prefix_file_name>] |
| 61 | + [-lpf <lines_per_file>] [-timeout <query_timeout>] |
| 62 | +``` |
| 63 | + |
| 64 | +### 2.3 Examples |
| 65 | + |
| 66 | +Export schema from `database1` to `/home`: |
| 67 | + |
| 68 | +```Bash |
| 69 | +./export-schema.sh -sql_dialect table -t /home/ -db database1 |
| 70 | +``` |
| 71 | + |
| 72 | +Output `dump_database1.sql`: |
| 73 | + |
| 74 | +```sql |
| 75 | +DROP TABLE IF EXISTS table1; |
| 76 | +CREATE TABLE table1( |
| 77 | + time TIMESTAMP TIME, |
| 78 | + region STRING TAG, |
| 79 | + plant_id STRING TAG, |
| 80 | + device_id STRING TAG, |
| 81 | + model_id STRING ATTRIBUTE, |
| 82 | + maintenance STRING ATTRIBUTE, |
| 83 | + temperature FLOAT FIELD, |
| 84 | + humidity FLOAT FIELD, |
| 85 | + status BOOLEAN FIELD, |
| 86 | + arrival_time TIMESTAMP FIELD |
| 87 | +); |
| 88 | +DROP TABLE IF EXISTS table2; |
| 89 | +CREATE TABLE table2( |
| 90 | + time TIMESTAMP TIME, |
| 91 | + region STRING TAG, |
| 92 | + plant_id STRING TAG, |
| 93 | + device_id STRING TAG, |
| 94 | + model_id STRING ATTRIBUTE, |
| 95 | + maintenance STRING ATTRIBUTE, |
| 96 | + temperature FLOAT FIELD, |
| 97 | + humidity FLOAT FIELD, |
| 98 | + status BOOLEAN FIELD, |
| 99 | + arrival_time TIMESTAMP FIELD |
| 100 | +); |
| 101 | +``` |
0 commit comments