Migrate Data from one Couchbase server to another couchbase server

Hi everyone,

Inorder to copy data from one Couchbase bucket to another bucket within same server through python sdk, we use something like below:

cb = cluster.open_bucket(‘bucket1’)
cb1 = cluster.open_bucket(‘bucket2’)

meta = cb1.n1ql_query(N1QLQuery(‘INSERT INTO bucket1 (key _k, value _v) SELECT META().ID _k, _v FROM bucket2 _v;’)).execute().meta

But through Python SDK, I want to copy data from one bucket (bucket1) of couchbase server to a bucket (bucket2) in different couchbase server . Can anyone please help me on this.

Use XDCR, backup, import/export

If you want to do python sdk only, data has pass through client from source cluster to target cluster as follows.

  • scluster connect to source cluster bucket
  • tcluster connect to target cluster bucket
  • using scluster SELECT statement get the data
  • using tcluster INSERT the data

Hi @vsr1 sir,

How to insert the data in tcluster after getting the data from scluster?

I tried the below mentioned syntax

retrieving data from scluster bucket

result = scluster.n1ql_query(‘SELECT bucket1.* FROM bucket1’)

inserting data to tcluster bucket

result1 = tcluster.n1ql_query(‘INSERT INTO bucket2’)

also tried below syntax for inserting the data
result1 = tcluster.n1ql_query(‘INSERT INTO bucket2 FROM $1’, result)

Tried these 2 syntax for inserting the data but data is not being inserted.

Can you please correct me by giving correct syntax.

After retrieving data from scluster you need to iterate over results get the document key and and document
https://cloud.couchbase.com/sign-in
Each document key and document you need to insert into target cluster (the INSERT syntax is not right) directly KV CURD operations vs N1QL

1 Like