Exporting data
Enterprise Edition
This command is supported by the Enterprise Edition only.
$ tt [crud|tdg2] export URI SPACE:FILE ... [EXPORT_OPTION ...]
tt [crud|tdg2] export exports a space’s data to a file. Three export commands
cover the following cases:
tt exportexports data from a replica set using the box.space API.tt crud exportexports data from a sharded cluster through a router using the CRUD module.tt tdg2 exportexports data from a Tarantool Data Grid 2 cluster through its connector using TDG2 Repository API.
tt [crud|tdg2] export takes the following arguments:
URI: The URI of a router instance ifcrudis used. Otherwise, it should specify the URI of a storage.FILE: The name of a file for storing exported data.SPACE: The name of a space from which data is exported.
Примечание
Read access to the space is required to export its data.
tt export exports data in the following formats:
tt exportandtt crud export: CSVtt tdg2 export: JSON lines
Exporting isn’t supported for the interval field type.
The command below exports data of the customers space to the customers.csv file:
$ tt crud export localhost:3301 customers:customers.csv
If the customers space has five fields (id, bucket_id, firstname, lastname, and age), the file with exported data might look like this:
1,477,Andrew,Fuller,38
2,401,Michael,Suyama,46
3,2804,Robert,King,33
# ...
If a tuple contains a null value, for example, [1, 477, 'Andrew', null, 38], it is exported as an empty value:
1,477,Andrew,,38
To export data with a space’s field names in the first row of the CSV file, use the --header option:
$ tt crud export localhost:3301 customers:customers.csv \
--header
In this case, field values start from the second row, for example:
id,bucket_id,firstname,lastname,age
1,477,Andrew,Fuller,38
2,401,Michael,Suyama,46
3,2804,Robert,King,33
# ...
In the CSV format, tt exports empty values by default for fields containing compound data such as arrays or maps.
To export compound values in a specific format, use the --compound-value-format option.
For example, the command below exports compound values to CSV serialized in JSON:
$ tt crud export localhost:3301 customers:customers.csv \
--compound-value-format json
Примечание
In the TDG2 data model, a type represents a Tarantool space, and an object of a type represents a tuple in the type’s underlying space.
The command below exports data of the customers type from a TDG2 cluster to
the customers.jsonl file:
$ tt tdg2 export localhost:3301 customers:customers.jsonl
If token authentication is enabled in TDG2, pass the application token in the --token option:
$ tt tdg2 export localhost:3301 customers:customers.jsonl \
--token=2fc136cf-8cae-4655-a431-7c318967263d
If the customers type has four fields (id, firstname, lastname, and age),
the file with exported data might look like this:
{"age":30,"first_name":"Samantha","id":1,"second_name":"Carter"}
{"age":41,"first_name":"Fay","id":2,"second_name":"Rivers"}
{"age":74,"first_name":"Milo","id":4,"second_name":"Walters"}
null field values are skipped:
{"age":13,"first_name":"Zachariah","id":3}
Object fields that contain maps with non-string keys are converted to maps with string keys.
TDG2 sets a limit on the number of objects transferred from each storage during a query execution
(the hard-limits.returned
TDG2 configuration parameter). If an export batch size (--batch-size parameter)
is greater than this limit, it is possible that more than hard-limits.returned objects
will be requested from one storage and export will fail.
To make sure that hard-limits.returned is never exceeded during an export operation,
set the export batch size less or equal to this limit.
For example, if your TDG2 cluster has a 1000 objects hard-limits.returned limit:
# tdg2 config.yaml
# ...
hard-limits.returned: 1000
Set the tt tdg2 export batch size less or equal to 1000:
$ tt tdg2 export localhost:3301 customers:customers.jsonl --batch-size=1000
When connecting to the cluster with enabled authentication, specify access credentials
in the --username and --password command options:
$ tt crud export localhost:3301 customers:customers.csv \
--username myuser --password p4$$w0rD
To connect to instances that use SSL encryption,
provide the SSL certificate and SSL key files in the --sslcertfile and --sslkeyfile options.
If necessary, add other SSL parameters in the --ssl* options.
$ tt crud export localhost:3301 customers:customers.csv \
--username myuser --password p4$$w0rD \
--auth pap-sha256 --sslcertfile certs/server.crt \
--sslkeyfile certs/server.key
For connections that use SSL but don’t require additional parameters, add the --use-ssl
option:
$ tt crud export localhost:3301 customers:customers.csv \
--username myuser --password p4$$w0rD \
--use-ssl
-
--authSTRING¶ Applicable to:
tt crud export,tt tdg2 exportAuthentication type:
chap-sha1,pap-sha256, orauto.
-
--batch-queue-sizeINT¶ The maximum number of tuple batches in a queue between a fetch and write threads (the default is
32).ttexports data using two threads:- A fetch thread makes requests and receives data from a Tarantool instance.
- A write thread encodes received data and writes it to the output.
The fetch thread uses a queue to pass received tuple batches to the write thread. If a queue is full, the fetch thread waits until the write thread takes a batch from the queue.
-
--batch-sizeINT¶ The number of tuples to transfer per request. The default is:
10000fortt exportandtt crud export.100fortt tdg2 export.
Важно
When using
tt tdg2 export, make sure that the batch size does not exceed thehard-limits.returnedTDG2 parameter value set on the cluster.
-
--compound-value-formatSTRING¶ Applicable to:
tt export,tt crud exportA format used to export compound values like arrays or maps. By default,
ttexports empty values for fields containing such values.Supported formats:
json.See also: Exporting compound data.
-
--header¶ Applicable to:
tt export,tt crud exportAdd field names in the first row.
See also: Exporting headers.
-
--passwordSTRING¶ A password used to connect to the instance.
-
--sslcafileSTRING¶ Applicable to:
tt crud export,tt tdg2 exportThe path to a trusted certificate authorities (CA) file for encrypted connections.
See also Encrypted connection.
-
--sslcertfileSTRING¶ Applicable to:
tt crud export,tt tdg2 exportThe path to an SSL certificate file for encrypted connections.
See also Encrypted connection.
-
--sslciphersfileSTRING¶ Applicable to:
tt crud export,tt tdg2 exportThe list of SSL cipher suites used for encrypted connections, separated by colons (
:).See also Encrypted connection.
-
--sslkeyfileSTRING¶ Applicable to:
tt crud export,tt tdg2 exportThe path to a private SSL key file for encrypted connections.
See also Encrypted connection.
-
--sslpasswordSTRING¶ Applicable to:
tt crud export,tt tdg2 exportThe password for the SSL key file for encrypted connections.
See also Encrypted connection.
-
--sslpasswordfileSTRING¶ Applicable to:
tt crud export,tt tdg2 exportA file with list of passwords to the SSL key file for encrypted connections.
See also Authentication.
-
--tokenSTRING¶ Applicable to:
tt tdg2 exportAn application token for connecting to TDG2.
-
--use-sslSTRING¶ Use SSL without providing any additional SSL parameters.
See also Encrypted connection.
-
--usernameSTRING¶ A username for connecting to the instance.