# How to take a snapshots of a specific index with the php library?

**URL:** <https://discuss.elastic.co/t/how-to-take-a-snapshots-of-a-specific-index-with-the-php-library/23508>\
**Category:** Elasticsearch\
**Created:** [May 1, 2015, 12:10am UTC](https://discuss.elastic.co/t/how-to-take-a-snapshots-of-a-specific-index-with-the-php-library/23508 "2015-05-01T00:10:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jerrac](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jerrac/32/52980_2.png) [@jerrac](https://discuss.elastic.co/u/jerrac)\
**Post date:** [May 1, 2015, 12:10am UTC](https://discuss.elastic.co/t/how-to-take-a-snapshots-of-a-specific-index-with-the-php-library/23508/1 "2015-05-01T00:10:58Z")

</div>

When I try to list a specific index to take a snapshot of, the library  
seems to ignore it, and instead takes a snapshot of my entire cluster. It's  
the end of the day, and I'm likely missing something obvious, so any help  
would be appreciated.

Ultimately, I'm trying to do the equivalent of:

curl -XPUT "localhost:9200/\_snapshot/my\_backup/snapshot\_1" -d '{

> ```
> "indices": "logstash-2014.09.25",
> "ignore_unavailable": "true",
> "include_global_state": false
> 
> ```
> 
> }'

Here is my function:

function take(

> ```
> $name,
> $indices = array(),
> $settings = array(
> 'wait_for_completion' => true,
> 'ignore_unavailable' => "true",
> 'include_global_state' => false
> )
> ) {
> $params['repository'] = $this->clusterConfig['repository'];
> $params['snapshot'] = $name;
> $params['custom'] = array(
> 'ignore_unavailable' => $settings['ignore_unavailable'],
> 'include_global_state' => $settings['include_global_state']
> );
> $indicesString = "";
> if (!empty($indices)) {
> foreach ($indices as $value) {
> $indicesString .= $value . ",";
> }
> //remove ending comma
> $indicesString = rtrim($indicesString, ",");
> $params['custom']['indices'] = $indicesString;
> }
> $result = $this->es->snapshot()->create($params);
> if (!$result['acknowledged']) {
> $this->logger->addError("Failed to take snapshot $name in 
> 
> ```
> 
> cluster $this-\>clusterName.");  
> }  
> }

Called like:

take("testingstuff-logstash-2014.09.25",array("logstash-2014.09.25"));

> 

$this-\>es is an instance of Elasticsearch\Client.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/6418b7e0-fa47-4446-8292-859017976658%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/6418b7e0-fa47-4446-8292-859017976658%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![jerrac](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jerrac/32/52980_2.png) [@jerrac](https://discuss.elastic.co/u/jerrac)\
**Post date:** [May 1, 2015, 7:57pm UTC](https://discuss.elastic.co/t/how-to-take-a-snapshots-of-a-specific-index-with-the-php-library/23508/2 "2015-05-01T19:57:09Z")

</div>

Figured it out. The key was to use $params['body'] instead of  
$params['custom']. Which is odd since that's what I tried in the first  
place. I guess I must have had some other bug in the way at the time that  
got fixed as I was testing things...

On Thursday, April 30, 2015 at 5:10:58 PM UTC-7, David Reagan wrote:

> When I try to list a specific index to take a snapshot of, the library  
> seems to ignore it, and instead takes a snapshot of my entire cluster. It's  
> the end of the day, and I'm likely missing something obvious, so any help  
> would be appreciated.
> 
> Ultimately, I'm trying to do the equivalent of:
> 
> curl -XPUT "localhost:9200/\_snapshot/my\_backup/snapshot\_1" -d '{
> 
> > ```
> > "indices": "logstash-2014.09.25",
> > "ignore_unavailable": "true",
> > "include_global_state": false
> > 
> > ```
> > 
> > }'
> 
> Here is my function:
> 
> function take(
> 
> > ```
> > $name,
> > $indices = array(),
> > $settings = array(
> > 'wait_for_completion' => true,
> > 'ignore_unavailable' => "true",
> > 'include_global_state' => false
> > )
> > ) {
> > $params['repository'] = $this->clusterConfig['repository'];
> > $params['snapshot'] = $name;
> > $params['custom'] = array(
> > 'ignore_unavailable' => $settings['ignore_unavailable'],
> > 'include_global_state' => $settings['include_global_state']
> > );
> > $indicesString = "";
> > if (!empty($indices)) {
> > foreach ($indices as $value) {
> > $indicesString .= $value . ",";
> > }
> > //remove ending comma
> > $indicesString = rtrim($indicesString, ",");
> > $params['custom']['indices'] = $indicesString;
> > }
> > $result = $this->es->snapshot()->create($params);
> > if (!$result['acknowledged']) {
> > $this->logger->addError("Failed to take snapshot $name in 
> > 
> > ```
> > 
> > cluster $this-\>clusterName.");  
> > }  
> > }
> 
> Called like:
> 
> take("testingstuff-logstash-2014.09.25",array("logstash-2014.09.25"));
> 
> > 
> 
> $this-\>es is an instance of Elasticsearch\Client.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/2470204b-bd53-442b-94c6-b9ab2be92cec%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/2470204b-bd53-442b-94c6-b9ab2be92cec%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [July 6, 2017, 12:16am UTC](https://discuss.elastic.co/t/how-to-take-a-snapshots-of-a-specific-index-with-the-php-library/23508/3 "2017-07-06T00:16:12Z")

</div>


