Data Export

1. Function Overview

IoTDB supports two methods for data export:

  • Data Export Tool: export-data.sh/bat is located in the tools directory. It can export the query results of specified SQL statements into CSV, SQL, and TsFile (open-source time-series file format) files.
  • PIPE Framework-based TsFileBackup: tsfile-backup.sh/bat is located in the tools directory. It can export specified data files into TsFile format using the PIPE framework.

2. Data Export Tool

2.1 Common Parameters

ShortFull ParameterDescriptionRequiredDefault
-ft--file_typeExport file type: csv, sql, tsfile.Yes-
-h--hostHostname of the IoTDB server.No127.0.0.1
-p--portPort number of the IoTDB server.No6667
-u--usernameUsername for authentication.Noroot
-pw--passwordPassword for authentication. Supported for hidden input since V2.0.9.1NoTimechoDB@2021(Before V2.0.6 it is root)
-sql_dialect--sql_dialectSelect server model : tree or tableNotree
-db --databaseThe target database to be exported only takes effect when -sql_dialect is of the table type.Yes when -sql_dialect = table-
-table--tableThe target table to be exported only takes effect when -sql_dialect is of the table type. If the -q parameter is specified, this parameter will not take effect. If the export type is tsfile/sql, this parameter is mandatory.​ No-
-start_time--start_timeThe start time of the data to be exported only takes effect when -sql_dialect is of the table type. If -q is specified, this parameter will not take effect. The supported time formats are the same as those for the -tf parameter.No-
-end_time--end_timeThe end time of the data to be exported only takes effect when -sql_dialect is set to the table type. If -q is specified, this parameter will not take effect.No-
-t--targetTarget directory for the output files. If the path does not exist, it will be created.Yes-
-pfn--prefix_file_namePrefix for the exported file names. For example, abc will generate files like abc_0.tsfile, abc_1.tsfile.Nodump_0.tsfile
-q--querySQL query command to execute. Starting from v2.0.8, semicolons in SQL statements are automatically removed, and query execution proceeds normally.No-
-timeout--query_timeoutQuery timeout in milliseconds (ms).No-1 (before v2.0.8)
Long.MAX_VALUE (v2.0.8 and later)
(Range: -1~Long.MAX_VALUE)
-help--helpDisplay help information.No-
-usessl--use_sslUse SSL protocol. Supported since V2.0.9.1No-
-ts--trust_storeTrust store. Supports hidden input. Supported since V2.0.9.1No-
-tpw--trust_store_passwordTrust store password. Supports hidden input. Supported since V2.0.9.1No-

2.2 CSV Format

2.2.1 Command

# Unix/OS X
> tools/export-data.sh -ft<format> [-sql_dialect<sql_dialect>] -db<database> -table<table>  
                [-start_time<start_time>] [-end_time<end_time>] [-h <host>] [-p <port>] [-u <username>] [-pw <password>] 
                -t <target_directory> [-pfn <prefix_file_name>] [-dt <datatype>] [-lpf <lines_per_file>] [-tf <time_format>] 
               [-tz <timezone>] [-q <query_command>] [-timeout <query_timeout>]
# Windows
# Before version V2.0.4.x
> tools\export-data.bat -ft<format> [-sql_dialect<sql_dialect>] -db<database> -table<table>  
                [-start_time<start_time>] [-end_time<end_time>] [-h <host>] [-p <port>] [-u <username>] [-pw <password>] 
                -t <target_directory> [-pfn <prefix_file_name>] [-dt <datatype>] [-lpf <lines_per_file>] [-tf <time_format>] 
               [-tz <timezone>] [-q <query_command>] [-timeout <query_timeout>]
               
# V2.0.4.x and later versions
> tools\windows\export-data.bat -ft<format> [-sql_dialect<sql_dialect>] -db<database> -table<table>  
                [-start_time<start_time>] [-end_time<end_time>] [-h <host>] [-p <port>] [-u <username>] [-pw <password>] 
                -t <target_directory> [-pfn <prefix_file_name>] [-dt <datatype>] [-lpf <lines_per_file>] [-tf <time_format>] 
               [-tz <timezone>] [-q <query_command>] [-timeout <query_timeout>]

2.2.2 CSV-Specific Parameters

ShortFull ParameterDescriptionRequiredDefault
-dt--datatypeWhether to include data types in the CSV file header (true or false).Nofalse
-lpf--lines_per_fileNumber of rows per exported file.No10000 (Range:0~Integer.Max=2147483647)
-tf--time_formatTime format for the CSV file. Options: 1) Timestamp (numeric, long), 2) ISO8601 (default), 3) Custom pattern (e.g., yyyy-MM-dd HH:mm:ss). SQL file timestamps are unaffected by this setting.NoISO8601
-tz--timezoneTimezone setting (e.g., +08:00, -01:00).NoSystem default

2.2.3 Examples

# Valid Example
> export-data.sh -ft csv -sql_dialect table -t /path/export/dir -db database1 -q "select * from table1"

# Error Example
> export-data.sh -ft csv -sql_dialect table -t /path/export/dir -q "select * from table1"
Parse error: Missing required option: db

2.3 SQL Format

2.3.1 Command

# Unix/OS X
> tools/export-data.sh -ft<format> [-sql_dialect<sql_dialect>] -db<database> -table<table>  
                [-start_time<start_time>] [-end_time<end_time>] [-h <host>] [-p <port>] [-u <username>] [-pw <password>] 
          -t <target_directory> [-pfn <prefix_file_name>] [-aligned <export aligned insert sql>]
          -lpf <lines_per_file> - [-tf <time_format>] [-tz <timezone>] [-q <query_command>] [-timeout <query_timeout>]
      
# Windows
# Before version V2.0.4.x 
> tools\export-data.bat -ft<format> [-sql_dialect<sql_dialect>] -db<database> -table<table>  
                [-start_time<start_time>] [-end_time<end_time>] [-h <host> -p <port> -u <username> -pw <password>] 
          -t <target_directory> [-pfn <prefix_file_name>  -aligned <export aligned insert sql>  
          -lpf <lines_per_file> -tf <time_format> -tz <timezone> -q <query_command> -timeout <query_timeout>]
          
# V2.0.4.x and later versions
> tools\windows\export-data.bat -ft<format> [-sql_dialect<sql_dialect>] -db<database> -table<table>  
                [-start_time<start_time>] [-end_time<end_time>] [-h <host> -p <port> -u <username> -pw <password>] 
          -t <target_directory> [-pfn <prefix_file_name>  -aligned <export aligned insert sql>  
          -lpf <lines_per_file> -tf <time_format> -tz <timezone> -q <query_command> -timeout <query_timeout>]

2.3.2 SQL-Specific Parameters

ShortFull ParameterDescriptionRequiredDefault
-aligned--use_alignedWhether to export as aligned SQL format (true or false).Notrue
-lpf--lines_per_fileNumber of rows per exported file.No10000 (Range:0~Integer.Max=2147483647)
-tf--time_formatTime format for the CSV file. Options: 1) Timestamp (numeric, long), 2) ISO8601 (default), 3) Custom pattern (e.g., yyyy-MM-dd HH:mm:ss). SQL file timestamps are unaffected by this setting.NoISO8601
-tz--timezoneTimezone setting (e.g., +08:00, -01:00).NoSystem default

2.3.3 Examples

# Valid Example
> export-data.sh -ft sql -sql_dialect table -t /path/export/dir -db database1 -start_time 1

# Error Example
> export-data.sh -ft sql -sql_dialect table -t /path/export/dir -start_time 1
Parse error: Missing required option: db

2.4 TsFile Format

2.4.1 Command

# Unix/OS X
> tools/export-data.sh -ft<format> [-sql_dialect<sql_dialect>] -db<database> -table<table>  
                [-start_time<start_time>] [-end_time<end_time>] [-h <host>] [-p <port>] [-u <username>] [-pw <password>]
        -t <target_directory> [-pfn <prefix_file_name>] [-q <query_command>] [-timeout <query_timeout>]
      
# Windows
# Before version V2.0.4.x 
> tools\export-data.bat -ft<format> [-sql_dialect<sql_dialect>] -db<database> -table<table>  
                [-start_time<start_time>] [-end_time<end_time>] [-h <host>] [-p <port>] [-u <username>] [-pw <password>]
        -t <target_directory> [-pfn <prefix_file_name>] [-q <query_command>] [-timeout <query_timeout>]
        
# V2.0.4.x and later versions
> tools\windows\export-data.bat -ft<format> [-sql_dialect<sql_dialect>] -db<database> -table<table>  
                [-start_time<start_time>] [-end_time<end_time>] [-h <host>] [-p <port>] [-u <username>] [-pw <password>]
        -t <target_directory> [-pfn <prefix_file_name>] [-q <query_command>] [-timeout <query_timeout>]

2.4.2 TsFile-Specific Parameters

  • None

2.4.3 Examples

# Valid Example
> /tools/export-data.sh -ft tsfile -sql_dialect table -t /path/export/dir -db database1 -start_time 0

# Error Example
> /tools/export-data.sh -ft tsfile -sql_dialect table -t /path/export/dir -start_time 0
Parse error: Missing required option: db

3. TsFileBackup Based on PIPE Framework

Since V2.0.9.2, IoTDB supports the tsfile-backup.sh/bat script. This script can automatically generate and send the CREATE PIPE SQL command to the server, exporting specified data files to TsFile format.

Notes:

  1. To use this script, contact the Timecho Team to obtain the JAR package(tsfile-remote-sink-<version>-jar-with-dependencies.jar), and place it in a path accessible to IoTDB (e.g., all Data Node hosts).
  2. This script supports exporting Object-type data to TsFile files.

3.1 Execution Commands

# Unix/OS X
> tools/tsfile-backup.sh [-sql_dialect <sql_dialect>] [-h <host>] [-p <port>]
       [-u <username>] [-pw <password>] [-path <path>] [-db <db>] [-table
       <table>] [-s <start_time>] [-e <end_time>] [-t <target_directory>] 
       [-th <target_host>] [-tu <target_host_user>] [-tp <target_host_port>]
       [--rate_limit] [--plugin_jar] [-help]

# Windows
> tools\windows\tsfile-backup.bat [-sql_dialect <sql_dialect>] [-h <host>] [-p <port>]
       [-u <username>] [-pw <password>] [-path <path>]  [-db <db>] [-table
       <table>] [-s <start_time>] [-e <end_time>] [-t <target_directory>] 
       [-th <target_host>] [-tu <target_host_user>] [-tp <target_host_port>]
       [--rate_limit] [--plugin_jar] [-help]

3.2 Script Parameters

AbbreviationFull NameDescriptionRequiredDefault
-sql_dialect--sql_dialectSpecifies the data model type. Valid values: tree (Tree Model) or table (Table Model).Yes-
-h--hostLocal host address (IP of the IoTDB instance where the data resides).No127.0.0.1
-p--portPort number for the IoTDB RPC service.No6667
-u--userUsername for IoTDB authentication.Noroot
-pw--passwordPassword for IoTDB authentication (hidden input supported).Noroot
-t--targetExport target directory. In SCP mode, this is an absolute physical path on the remote server. TsFile and associated Object directories will be exported here.Yes-
-db--databaseDatabase name (optional for Table Model).No.*
-table--tableTable name (optional for Table Model).No.*
-s--start_timeStart time (ISO8601 format e.g. 2026-01-01T00:00:00 or millisecond timestamp). Only data from this time onwards is exported.No-
-e--end_timeEnd time (same format as above). Only data before this time is exported.No-
-th--target_hostRemote target host IP. If specified, the script automatically configures Pipe to use SCP for data transfer.No-
-tu--target_host_userUsername for SSH/SCP login to the remote server.No-
-tpw--target_host_pwPassword for remote authentication (hidden input supported).No-
-tp--target_host_portRemote SSH port.No22
--rate_limit--rate_limitTransfer rate limit (unit: Bytes/s) to prevent excessive bandwidth usage.No-
--plugin_jar--plugin_jarPath to the Pipe plugin JAR file.No-
--object-parallelism--object-parallelismSpecifies the maximum parallelism for object file transmission.No-
--object-batch-size--object-batch-sizeLimits the total byte size of each object file upload batch, used to control memory usage and single SCP transfer size.No-
-help--helpShow help information.No-

3.3 Execution Examples

Example 1: SCP Remote Export (Send Data to Another Server)

./tsfile-backup.sh -sql_dialect table -db test_db -t /remote/archive/ -th 192.168.1.100 -tu backup_user -tpw ComplexPass123!

Example 2: Remote Object Data Export with Rate Limiting

./tsfile-backup.sh -sql_dialect table -t /mnt/backup/ -th 10.0.0.5 -tu iot_admin -tpw Admin@2026 --rate_limit 5242880

Example 3: Specify Pipe Plugin JAR Directory

./tsfile-backup.sh -sql_dialect table -db test -table .* -tu luoluoyuyu -tpw -t /tmp/backup --plugin_jar /local/lib/tsfile-remote-sink-2.0.8-SNAPSHOT-jar-with-dependencies.jar

Note: When exporting Object-type data in SCP mode, to avoid handshake exceptions, connection failures, or frequent Pipe restarts, it is recommended to take any of the following measures:

  • Appropriately lower the configuration parameter object-parallelism
  • Increase the MaxStartups value on the target machine as needed. After modification, execute sshd reload or sshd restart for the configuration to take effect.