Import and Export Data with Command Line Tools
- Capella Operational
Use Couchbase command line tools to import and export large amounts of data.
You can use the cbimport
and cbexport
command line tools included with Couchbase Server with a Couchbase Capella cluster. The command line tools are available as a separate package.
-
Use
cbimport
to import large datasets and multiple files at once, up to the maximum size of your Capella cluster. -
Use
cbexport
to export data from your Capella cluster.
Prerequisites
The procedures on this page assume the following:
-
You have configured cluster access by creating cluster access credentials. You’ll need the username and password for the cluster credentials to connect to the cluster.
-
You have added your IP address to the cluster’s list of allowed IPs.
-
You have downloaded your security certificate for your cluster.
-
You have downloaded and installed the command line tools package.
Import Data
-
Go to
. -
Copy the command under cbimport.
-
Replace
username
andpassword
with the username and password of your cluster access credentials respectively. -
Update
bucketname
with the name of your bucket. -
Update dataset with the
path to the dataset file
. -
Set the
cacert
to point to the downloaded CA cert.
You can also import from JSON. See the examples for more details. |
Export Data
-
Copy the command under cbexport.
-
Replace
username
andpassword
with the username and password of your cluster access credentials respectively. -
Update the path to the location where you want to create your JSON file export.
-
Update
bucketname
,scope
,collection
, and thecollection_field
with the name of your bucket, scope, and collection. -
Set the
cacert
to point to the downloaded CA cert.
Import and Export with Command Line Tools Examples
For production environments, use the secure --cacert <cert_file>
option shown in the examples. For development environments, replace --cacert <cert_file>
with --no-ssl-verify
.
cbimport
Import from CSV
Use the cbimport csv
command to import data into your Capella cluster from a CSV file:
$ cbimport csv --cluster couchbases://cb.zjhxs-12ab3cd4e5.cloud.couchbase.com --username dbuser --password '******' --bucket mybucket1 --dataset file:///home/someuser/test_records.csv --generate-key '#UUID#' --infer-types --cacert /root/capella.pem --threads 4
Import from JSON
Use the cbimport json
command to import data into your Capella cluster from a JSON file:
$ cbimport json --cluster couchbases://cb.zjhxs-12ab3cd4e5.cloud.couchbase.com --username dbuser --password '******' --bucket mybucket1 --dataset file://./profile_docs.json --format lines --generate-key %profile_id% --cacert /root/capella.pem --threads 4
In this example, the travel-sample-export.json
was created with the cbexport example.
$ cbimport json --cluster couchbases://cb.zjhxs-12ab3cd4e5.cloud.couchbase.com --username dbuser --password '******' --bucket mytravelsample --dataset file://./travel-sample-export.json --scope-collection-exp %myscopefield%.%mycollectionfield% --format lines --generate-key %doc_key% --ignore-fields doc_key,myscopefield,mycollectionfield --cacert /root/capella.pem
cbexport
Use the cbexport json
command to export JSON documents from your Capella cluster.
$ cbexport json --cluster couchbases://cb.zjhxs-12ab3cd4e5.cloud.couchbase.com --username dbuser --password '******' --bucket travel-sample --format lines --output /home/someuser/travel-sample-export.json --scope-field myscopefield --collection-field mycollectionfield --include-key doc_key --cacert /root/capella.pem