Clone Snapshot API

edit

The Clone Snapshot API clones part or all of a snapshot into a new snapshot.

Request

edit

A CloneSnapshotRequest:

CloneSnapshotRequest request = new CloneSnapshotRequest(repositoryName, sourceSnapshotName, targetSnapshotName, indices);

Indices to Clone

edit

Use indices to specify a list of indices from the source snapshot to include in the snapshot clone:

request.indices("test_index"); 

Include only test_index from the source snapshot.

Index Settings and Options

edit

You can also customize index settings and options when cloning a snapshot:

request.indicesOptions(new IndicesOptions(
    EnumSet.of(IndicesOptions.Option.IGNORE_UNAVAILABLE),  
    EnumSet.of(
        IndicesOptions.WildcardStates.OPEN,
        IndicesOptions.WildcardStates.CLOSED,
        IndicesOptions.WildcardStates.HIDDEN))
);

Set IndicesOptions.Option.IGNORE_UNAVAILABLE in #indicesOptions() to have the clone succeed even if indices are missing in the source snapshot.

Further Arguments

edit

You can also provide the following optional arguments:

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
AcknowledgedResponse response = client.snapshot().clone(request, RequestOptions.DEFAULT);

Asynchronous Execution

edit

The asynchronous execution of a clone snapshot request requires both the CloneSnapshotRequest instance and an ActionListener instance to be passed to the asynchronous method:

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

The CloneSnapshotRequest 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 AcknowledgedResponse looks like:

ActionListener<AcknowledgedResponse> listener =
    new ActionListener<AcknowledgedResponse>() {
        @Override
        public void onResponse(AcknowledgedResponse acknowledgedResponse) {
            
        }

        @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.

Response

edit

AcknowledgedResponse indicates whether the request was received:

boolean acknowledged = response.isAcknowledged();  

A boolean value of true if the clone successfully completed. Otherwise, the value is false.