# Determine when clone index has completed

**URL:** <https://discuss.elastic.co/t/determine-when-clone-index-has-completed/291675>\
**Category:** Elasticsearch\
**Created:** [December 13, 2021, 2:49pm UTC](https://discuss.elastic.co/t/determine-when-clone-index-has-completed/291675 "2021-12-13T14:49:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![madshov](https://avatars.discourse-cdn.com/v4/letter/m/2bfe46/32.png) [@madshov](https://discuss.elastic.co/u/madshov)\
**Post date:** [December 13, 2021, 2:49pm UTC](https://discuss.elastic.co/t/determine-when-clone-index-has-completed/291675/1 "2021-12-13T14:49:58Z")

</div>

Hi,  
I'm writing some functionality where step 1 would be to backup the current ES index. For this I'm using the \_cloneIndex request. This seems like the most appropriate choice. But how would I know for sure when that has finished? Is it enough to check if the cluster status is yellow or green?

Would it be smarter to use \_reindex instead to create a copy of my index? I just realised the \_clone request requires the index to be in block-write mode, which will cause a problem with all new incoming index requests while cloning.

---

<div class="post-metadata">

**Author:** ![DineshNaik](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dineshnaik/32/89308_2.png) [@DineshNaik](https://discuss.elastic.co/u/DineshNaik)\
**Post date:** [December 14, 2021, 4:56am UTC](https://discuss.elastic.co/t/determine-when-clone-index-has-completed/291675/2 "2021-12-14T04:56:37Z")

</div>

The cloning process can be monitored with the [`_cat recovery` API](https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-recovery.html), or the [`cluster health` API](https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-health.html) can be used to wait until all primary shards have been allocated by setting the `wait_for_status` parameter to `yellow` .

The `_clone` API returns as soon as the target index has been added to the cluster state, before any shards have been allocated. At this point, all shards are in the state `unassigned` . If, for any reason, the target index can’t be allocated, its primary shard will remain `unassigned` until it can be allocated on that node.

Once the primary shard is allocated, it moves to state `initializing` , and the clone process begins. When the clone operation completes, the shard will become `active` . At that point, Elasticsearch will try to allocate any replicas and may decide to relocate the primary shard to another node.

And Yes , **To clone an index** the index must be marked as read-only and have a [cluster health](https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-health.html) status of `green`.  
The documentation is pretty good and has all details you need. please refer:

1. [Clone API](https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-clone-index.html)
2. [Reindex API](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html)

you can check the prerequisites section for both of the options.

---

<div class="post-metadata">

**Author:** ![madshov](https://avatars.discourse-cdn.com/v4/letter/m/2bfe46/32.png) [@madshov](https://discuss.elastic.co/u/madshov)\
**Post date:** [December 14, 2021, 12:19pm UTC](https://discuss.elastic.co/t/determine-when-clone-index-has-completed/291675/3 "2021-12-14T12:19:47Z")

</div>

Hi Dinesh,  
Thanks for your reply and links to documentation. One thing I was wondering is the following scenario. Let's say I have a big index that I want to backup into another index. I assume this will take a short while to create the new index and create all the documents there as well. What happens to new documents that are indexed during that period? If clone requires read-only, I assume these new index requests will fail. Should I be using reindex instead?

---

<div class="post-metadata">

**Author:** ![DineshNaik](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dineshnaik/32/89308_2.png) [@DineshNaik](https://discuss.elastic.co/u/DineshNaik)\
**Post date:** [December 14, 2021, 2:14pm UTC](https://discuss.elastic.co/t/determine-when-clone-index-has-completed/291675/4 "2021-12-14T14:14:05Z")

</div>

@madshov ,

yes, you can go for reindex api , but even with this, the suggested approach would be to stop the ingestion if possible during the process.

if that's not a possibility then you might have to take care of delta updates in the new index.

You can create an alias if possible. The benefit of using the alias is that we can avoid downtime and easily roll back the migration if there is something wrong with the new index. That’s because just switching the alias can be completed quickly.

---

<div class="post-metadata">

**Author:** ![madshov](https://avatars.discourse-cdn.com/v4/letter/m/2bfe46/32.png) [@madshov](https://discuss.elastic.co/u/madshov)\
**Post date:** [December 16, 2021, 11:52am UTC](https://discuss.elastic.co/t/determine-when-clone-index-has-completed/291675/5 "2021-12-16T11:52:03Z")

</div>

Hi @DineshNaik  
Thanks for you advice.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [January 13, 2022, 11:52am UTC](https://discuss.elastic.co/t/determine-when-clone-index-has-completed/291675/6 "2022-01-13T11:52:25Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
