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 export
exports data from a replica set using the box.space API.tt crud export
exports data from a sharded cluster through a router using the CRUD module.tt tdg2 export
exports 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 ifcrud
is 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 export
andtt 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
-
--auth
STRING
¶ Applicable to:
tt crud export
,tt tdg2 export
Authentication type:
chap-sha1
,pap-sha256
, orauto
.
-
--batch-queue-size
INT
¶ The maximum number of tuple batches in a queue between a fetch and write threads (the default is
32
).tt
exports 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-size
INT
¶ The number of tuples to transfer per request. The default is:
10000
fortt export
andtt crud export
.100
fortt tdg2 export
.
Важно
When using
tt tdg2 export
, make sure that the batch size does not exceed thehard-limits.returned
TDG2 parameter value set on the cluster.
-
--compound-value-format
STRING
¶ Applicable to:
tt export
,tt crud export
A format used to export compound values like arrays or maps. By default,
tt
exports empty values for fields containing such values.Supported formats:
json
.See also: Exporting compound data.
-
--header
¶
Applicable to:
tt export
,tt crud export
Add field names in the first row.
See also: Exporting headers.
-
--password
STRING
¶ A password used to connect to the instance.
-
--sslcafile
STRING
¶ Applicable to:
tt crud export
,tt tdg2 export
The path to a trusted certificate authorities (CA) file for encrypted connections.
See also Encrypted connection.
-
--sslcertfile
STRING
¶ Applicable to:
tt crud export
,tt tdg2 export
The path to an SSL certificate file for encrypted connections.
See also Encrypted connection.
-
--sslciphersfile
STRING
¶ Applicable to:
tt crud export
,tt tdg2 export
The list of SSL cipher suites used for encrypted connections, separated by colons (
:
).See also Encrypted connection.
-
--sslkeyfile
STRING
¶ Applicable to:
tt crud export
,tt tdg2 export
The path to a private SSL key file for encrypted connections.
See also Encrypted connection.
-
--sslpassword
STRING
¶ Applicable to:
tt crud export
,tt tdg2 export
The password for the SSL key file for encrypted connections.
See also Encrypted connection.
-
--sslpasswordfile
STRING
¶ Applicable to:
tt crud export
,tt tdg2 export
A file with list of passwords to the SSL key file for encrypted connections.
See also Authentication.
-
--token
STRING
¶ Applicable to:
tt tdg2 export
An application token for connecting to TDG2.
-
--use-ssl
STRING
¶ Use SSL without providing any additional SSL parameters.
See also Encrypted connection.
-
--username
STRING
¶ A username for connecting to the instance.