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


(David Reagan) #1

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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/6418b7e0-fa47-4446-8292-859017976658%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(David Reagan) #2

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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/2470204b-bd53-442b-94c6-b9ab2be92cec%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(system) #3