How to create or copy indexes from one couchbase server to couchbase another server

In my case i have around 40 secondary GSI indexes including 2 primary indexes on my development server.
My confusion is how can i copy these indexes to around 70 couchbase servers in production plus FTS too.

Right now what i am doing is i am creating all the indexes using NIQL one by one which is too time taking .Is there anything which automates this process Thanks

here is what i am doing now

try

    {

        $sql = CouchbaseN1qlQuery::fromString("CREATE INDEX `cash_register_payment` ON `stitchit_data_bucket`(`store_id`,`date`,`type`)");

        $result = $this->db_obj->query($sql);


    }

    catch(CouchbaseException $ex)

    {

        echo $ex;

    }

Hi @muhammad_ibrahim,

Which couchbase server version are you using? Community edition or enterprise edition?

If you can explain your “index copy” use case in detail, then I can suggest best possible solution.

One possibility is using backup/restore:
If you are using enterprise edition, one way of copying indexes from one couchbase cluster to the other couchbase cluster is using cbbackupmgr utility. Using this utility, you can backup the indexes from the source cluster and restore the indexes to the destination cluster. Using cbbackupmgr, you can restore FTS indexes as well.

Please note that by default, the cbbackupmgr does backup and restore of entire key value data. During restore, you can use “–disable-data” option to avoid restoring of the data. The documentation provides details about the config parameters.

Also note that the restore of global secondary index doesn’t “build” the index. You will have to build the indexes using build index command.

If you are using Community edition, you can use cbbackup and cbrestore utilities.

Hope this helps.

Thanks cbbackup and restore does the job but it will need to write build query, i am using community version.

With couchbase server version 6.5, you can build all unbuilt indexes belonging to a bucket using a single n1ql statement.

Details can be found in MB-32153. The command to do this is as follows:

BUILD INDEX ON <bucketName> ((SELECT RAW name from system:indexes WHERE keyspace_id = <bucketName> AND state = `deferred`))

I am not aware of any way of doing this before couchbase server version 6.5.