Snapshots Status API

edit

The Snapshots Status API allows to retrieve detailed information about snapshots in progress.

Snapshots Status Request

edit

A SnapshotsStatusRequest:

SnapshotsStatusRequest request = new SnapshotsStatusRequest();

Required Arguments

edit

The following arguments must be provided:

request.repository(repositoryName); 

Sets the repository to check for snapshot statuses

String [] snapshots = new String[] {snapshotName};
request.snapshots(snapshots); 

The list of snapshot names to check the status of

Optional Arguments

edit

The following arguments can optionally be provided:

request.ignoreUnavailable(true); 

The command will fail if some of the snapshots are unavailable. The ignore_unavailable flag set to true will return all snapshots that are currently available.

request.masterNodeTimeout(TimeValue.timeValueMinutes(1)); 
request.masterNodeTimeout("1m"); 

Timeout to connect to the master node as a TimeValue

Timeout to connect to the master node as a String

Synchronous Execution

edit
SnapshotsStatusResponse response = client.snapshot().status(request, RequestOptions.DEFAULT);

Asynchronous Execution

edit

The asynchronous execution of retrieving snapshot statuses requires both the SnapshotsStatusRequest instance and an ActionListener instance to be passed to the asynchronous method:

client.snapshot().statusAsync(request, RequestOptions.DEFAULT, listener); 

The SnapshotsStatusRequest to execute and the ActionListener to use when the execution completes

The asynchronous method does not block and returns immediately. Once it is completed the ActionListener is called back using the onResponse method if the execution successfully completed or using the onFailure method if it failed.

A typical listener for SnapshotsStatusResponse looks like:

ActionListener<SnapshotsStatusResponse> listener =
    new ActionListener<SnapshotsStatusResponse>() {
        @Override
        public void onResponse(SnapshotsStatusResponse snapshotsStatusResponse) {
            
        }

        @Override
        public void onFailure(Exception e) {
            
        }
    };

Called when the execution is successfully completed. The response is provided as an argument

Called in case of a failure. The raised exception is provided as an argument

Snapshots Status Response

edit

The returned SnapshotsStatusResponse allows to retrieve information about the executed operation as follows:

List<SnapshotStatus> snapshotStatusesResponse = response.getSnapshots();
SnapshotStatus snapshotStatus = snapshotStatusesResponse.get(0); 
SnapshotsInProgress.State snapshotState = snapshotStatus.getState(); 
SnapshotStats shardStats = snapshotStatus.getIndices().get(indexName).getShards().get(0).getStats(); 

Request contains a list of snapshot statuses

Each status contains information about the snapshot

Example of reading snapshot statistics about a specific index and shard