[Yandex Cloud documentation](../../index.md) > [Yandex Managed Service for OpenSearch](../index.md) > [Step-by-step guides](index.md) > Clusters > Managing backups

# Managing backups in Managed Service for OpenSearch

Managed Service for OpenSearch enables you to create [index](../concepts/indexing.md) backups using both the Yandex Cloud tools and the OpenSearch snapshot mechanism. Learn more about the snapshot mechanism in [this OpenSearch guide](https://opensearch.org/docs/latest/opensearch/snapshots/snapshot-restore/).

## Creating backups with the Yandex Cloud tools {#cloud-backups}

You can create [backups](../concepts/backup.md) and use existing backups to restore clusters.

Managed Service for OpenSearch also creates automatic hourly backups.

### Getting a list of backups {#list-backups}

You can get a list of backups created for the past 14 days.

{% list tabs group=instructions %}

- Management console {#console}

    To get a list of cluster backups:

    1. In the [management console](https://console.yandex.cloud), navigate to the relevant folder.
    1. Navigate to **Managed Service for&nbsp;OpenSearch**.
    1. Click the cluster name and open the ![backups](../../_assets/console-icons/archive.svg) **Backups** tab.

    To get a list of all backups in your folder:

    1. In the [management console](https://console.yandex.cloud), navigate to the relevant folder.
    1. Navigate to **Managed Service for&nbsp;OpenSearch**.
    1. Select ![backups](../../_assets/console-icons/archive.svg) **Backups**.

- CLI {#cli}

    If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../cli/quickstart.md#install).

    The folder used by default is the one specified when [creating](../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

    To get a list of all backups in a folder, run this command:

    ```bash
    yc managed-opensearch backup list
    ```

    Result:

    ```text
    +----------------------+---------------------+-------------------+---------------------+
    |          ID          |      CREATED AT     | SOURCE CLUSTER ID |      STARTED AT     |
    +----------------------+---------------------+-------------------+---------------------+
    | c9qlk4v13uq7******** | 2024-01-09 14:38:34 | c9qpm4i********   | 2024-01-09 14:38:28 |
    | c9qpm90p3pcg******** | 2024-01-09 13:38:31 | c9qpm4i********   | 2024-01-09 13:38:28 |
    +----------------------+---------------------+-------------------+---------------------+
    ```

    If you want to limit the backup list displayed after running the command, provide `--limit <number_of_records>` in the command. For example, if the output of the `yc managed-opensearch backup list` command takes up several screens, run the `yc managed-opensearch backup list --limit 5` command. In this case, the output will contain the list of five most recent backups.

- REST API {#api}

    1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

        ```bash
        export IAM_TOKEN="<IAM_token>"
        ```

    1. To get a list of cluster backups:

        1. Call the [Cluster.ListBackups](../api-ref/Cluster/listBackups.md) method, e.g., via the following [cURL](https://curl.se/) request:

            ```bash
            curl \
                --request GET \
                --header "Authorization: Bearer $IAM_TOKEN" \
                --url 'https://mdb.api.cloud.yandex.net/managed-opensearch/v1/clusters/<cluster_ID>/backups'
            ```

            You can get the cluster ID with the [list of clusters in the folder](cluster-list.md#list-clusters).

        1. Check the [server response](../api-ref/Cluster/listBackups.md#yandex.cloud.mdb.opensearch.v1.ListClusterBackupsResponse) to make sure your request was successful.

    1. To list backups for all clusters in your folder:

        1. Call the [Backup.List](../api-ref/Backup/list.md) method, e.g., via the following [cURL](https://curl.se/) request:

            ```bash
            curl \
                --request GET \
                --header "Authorization: Bearer $IAM_TOKEN" \
                --url 'https://mdb.api.cloud.yandex.net/managed-opensearch/v1/backups' \
                --url-query folderId=<folder_ID>
            ```

            
            You can get the folder ID with the [list of folders in the cloud](../../resource-manager/operations/folder/get-id.md).


        1. Check the [server response](../api-ref/Backup/list.md#yandex.cloud.mdb.opensearch.v1.ListBackupsResponse) to make sure your request was successful.

- gRPC API {#grpc-api}

    1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

        ```bash
        export IAM_TOKEN="<IAM_token>"
        ```

    1. Clone the [cloudapi](https://github.com/yandex-cloud/cloudapi) repository:
       
       ```bash
       cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
       ```
       
       Below, we assume that the repository contents reside in the `~/cloudapi/` directory.
    1. To get a list of cluster backups:

        1. Call the [ClusterService.ListBackups](../api-ref/grpc/Cluster/listBackups.md) method, e.g., via the following [gRPCurl](https://github.com/fullstorydev/grpcurl) request:

            ```bash
            grpcurl \
                -format json \
                -import-path ~/cloudapi/ \
                -import-path ~/cloudapi/third_party/googleapis/ \
                -proto ~/cloudapi/yandex/cloud/mdb/opensearch/v1/cluster_service.proto \
                -rpc-header "Authorization: Bearer $IAM_TOKEN" \
                -d '{
                      "cluster_id": "<cluster_ID>"
                    }' \
                mdb.api.cloud.yandex.net:443 \
                yandex.cloud.mdb.opensearch.v1.ClusterService.ListBackups
            ```

            You can get the cluster ID with the [list of clusters in the folder](cluster-list.md#list-clusters).

        1. Check the [server response](../api-ref/grpc/Cluster/listBackups.md#yandex.cloud.mdb.opensearch.v1.ListClusterBackupsResponse) to make sure your request was successful.

    1. To list backups for all clusters in your folder:

        1. Call the [BackupService.List](../api-ref/grpc/Backup/list.md) method, e.g., via the following [gRPCurl](https://github.com/fullstorydev/grpcurl) request:

            ```bash
            grpcurl \
                -format json \
                -import-path ~/cloudapi/ \
                -import-path ~/cloudapi/third_party/googleapis/ \
                -proto ~/cloudapi/yandex/cloud/mdb/opensearch/v1/backup_service.proto \
                -rpc-header "Authorization: Bearer $IAM_TOKEN" \
                -d '{
                      "folder_id": "<folder_ID>"
                    }' \
                mdb.api.cloud.yandex.net:443 \
                yandex.cloud.mdb.opensearch.v1.BackupService.List
            ```

            
            You can get the folder ID with the [list of folders in the cloud](../../resource-manager/operations/folder/get-id.md).


        1. Check the [server response](../api-ref/grpc/Backup/list.md#yandex.cloud.mdb.opensearch.v1.ListBackupsResponse) to make sure your request was successful.

{% endlist %}

### Getting backup information {#get-backup}

{% list tabs group=instructions %}

- Management console {#console}

    To get backup details for an existing cluster:

    1. In the [management console](https://console.yandex.cloud), navigate to the relevant folder.
    1. Navigate to **Managed Service for&nbsp;OpenSearch**.
    1. Click the cluster name and open the ![backups](../../_assets/console-icons/archive.svg) **Backups** tab.

    To get backup details for a previously deleted cluster:

    1. In the [management console](https://console.yandex.cloud), navigate to the relevant folder.
    1. Navigate to **Managed Service for&nbsp;OpenSearch**.
    1. Select ![backups](../../_assets/console-icons/archive.svg) **Backups**.

- CLI {#cli}

    If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../cli/quickstart.md#install).

    The folder used by default is the one specified when [creating](../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

    To get information about a cluster backup:

    1. Get the backup ID with the list of all backups in the folder:

        ```bash
        yc managed-opensearch backup list
        ```

        You will see the ID in the `ID` column of the command output.

    1. Get information about the backup you need:

        ```bash
        yc managed-opensearch backup get <backup_ID>
        ```

        Command output example:

        ```text
        id: c9qlk4v13uq7********
        folder_id: b1g86q4m5vej********
        source_cluster_id: c9qpm4i********
        started_at: "2024-01-09T10:38:28.683Z"
        created_at: "2024-01-09T10:38:31.685Z"
        indices:
          - .mdb-sli
          - .opendistro_security
          - .kibana_1
          - .opendistro-job-scheduler-lock
          - .opensearch-observability
          - .opendistro-ism-config
        opensearch_version: 2.8.0
        indices_total: "6"
        ```

- REST API {#api}

    1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

        ```bash
        export IAM_TOKEN="<IAM_token>"
        ```

    1. Call the [Backup.Get](../api-ref/Backup/get.md) method, e.g., via the following [cURL](https://curl.se/) request:

        ```bash
        curl \
            --request GET \
            --header "Authorization: Bearer $IAM_TOKEN" \
            --url 'https://mdb.api.cloud.yandex.net/managed-opensearch/v1/backups/<backup_ID>'
        ```

        You can get the backup ID with the [list of backups](#list-backups).

    1. Check the [server response](../api-ref/Backup/get.md#yandex.cloud.mdb.opensearch.v1.Backup) to make sure your request was successful.

- gRPC API {#grpc-api}

    1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

        ```bash
        export IAM_TOKEN="<IAM_token>"
        ```

    1. Clone the [cloudapi](https://github.com/yandex-cloud/cloudapi) repository:
       
       ```bash
       cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
       ```
       
       Below, we assume that the repository contents reside in the `~/cloudapi/` directory.
    1. Call the [BackupService.Get](../api-ref/grpc/Backup/get.md) method, e.g., via the following [gRPCurl](https://github.com/fullstorydev/grpcurl) request:

        ```bash
        grpcurl \
            -format json \
            -import-path ~/cloudapi/ \
            -import-path ~/cloudapi/third_party/googleapis/ \
            -proto ~/cloudapi/yandex/cloud/mdb/opensearch/v1/backup_service.proto \
            -rpc-header "Authorization: Bearer $IAM_TOKEN" \
            -d '{
                  "backup_id": "<backup_ID>"
                }' \
            mdb.api.cloud.yandex.net:443 \
            yandex.cloud.mdb.opensearch.v1.BackupService.Get
        ```

        You can get the backup ID with the [list of backups](#list-backups).

    1. View the [server response](../api-ref/grpc/Backup/get.md#yandex.cloud.mdb.opensearch.v1.Backup) to make sure your request was successful.

{% endlist %}

### Creating a backup {#create-backup}

{% list tabs group=instructions %}

- Management console {#console}
  
    1. In the [management console](https://console.yandex.cloud), navigate to the relevant folder.
    1. Navigate to **Managed Service for&nbsp;OpenSearch**.
    1. Click the cluster name and open the ![backups](../../_assets/console-icons/archive.svg) **Backups** tab.
    1. Click ![image](../../_assets/console-icons/plus.svg) **Create backup**.

    This will initiate creating a backup without any additional confirmation.

- CLI {#cli}

    If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../cli/quickstart.md#install).

    The folder used by default is the one specified when [creating](../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

    To create a backup of cluster data, run this command:

    ```bash
    yc managed-opensearch cluster backup <cluster_name_or_ID>
    ```

    You can get the cluster name and ID with the [list of clusters in the folder](cluster-list.md#list-clusters).

- REST API {#api}

    1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

        ```bash
        export IAM_TOKEN="<IAM_token>"
        ```

    1. Call the [Cluster.Backup](../api-ref/Cluster/backup.md) method, e.g., via the following [cURL](https://curl.se/) request:

        ```bash
        curl \
            --request POST \
            --header "Authorization: Bearer $IAM_TOKEN" \
            --header "Content-Type: application/json" \
            --url 'https://mdb.api.cloud.yandex.net/managed-opensearch/v1/clusters/<cluster_ID>:backup'
        ```

        You can get the cluster ID with the [list of clusters in the folder](cluster-list.md#list-clusters).

    1. Check the [server response](../api-ref/Cluster/backup.md#yandex.cloud.operation.Operation) to make sure your request was successful.

- gRPC API {#grpc-api}

    1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

        ```bash
        export IAM_TOKEN="<IAM_token>"
        ```

    1. Clone the [cloudapi](https://github.com/yandex-cloud/cloudapi) repository:
       
       ```bash
       cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
       ```
       
       Below, we assume that the repository contents reside in the `~/cloudapi/` directory.
    1. Call the [ClusterService.Backup](../api-ref/grpc/Cluster/backup.md) method, e.g., via the following [gRPCurl](https://github.com/fullstorydev/grpcurl) request:

        ```bash
        grpcurl \
            -format json \
            -import-path ~/cloudapi/ \
            -import-path ~/cloudapi/third_party/googleapis/ \
            -proto ~/cloudapi/yandex/cloud/mdb/opensearch/v1/cluster_service.proto \
            -rpc-header "Authorization: Bearer $IAM_TOKEN" \
            -d '{
                  "cluster_id": "<cluster_ID>"
                }' \
            mdb.api.cloud.yandex.net:443 \
            yandex.cloud.mdb.opensearch.v1.ClusterService.Backup
        ```

        You can get the cluster ID with the [list of clusters in the folder](cluster-list.md#list-clusters).

    1. View the [server response](../api-ref/grpc/Cluster/backup.md#yandex.cloud.operation.Operation) to make sure your request was successful.

{% endlist %}

While you are creating a backup, the cluster performance may degrade.

### Restoring a cluster from a backup {#restore}

{% note warning %}

For clusters running an unsupported [DBMS version](../concepts/update-policy.md#versioning-policy), restoring from backups is not available.

{% endnote %}


Before you begin, [assign](../../iam/operations/roles/grant.md) the following roles to your Yandex Cloud account:

* [managed-opensearch.restorer](../../iam/roles-reference.md#managed-opensearch-restorer) or higher for the backup folder and the new cluster folder.
* [iam.serviceAccounts.user](../../iam/security/index.md#iam-serviceAccounts-user) or higher if restoring a cluster attached to a [service account](../../iam/concepts/users/service-accounts.md).


{% list tabs group=instructions %}

- Management console {#console}

    To restore an existing cluster from a backup:

    1. In the [management console](https://console.yandex.cloud), navigate to the relevant folder.
    1. Navigate to **Managed Service for&nbsp;OpenSearch**.
    1. Click the cluster name and open the ![backups](../../_assets/console-icons/archive.svg) **Backups** tab.
    1. Click ![image](../../_assets/console-icons/ellipsis.svg) for the backup you need and then click **Restore cluster**.
    1. Configure the new cluster.
    1. Click **Restore cluster**.

    To restore a previously deleted cluster from a backup:

    1. In the [management console](https://console.yandex.cloud), navigate to the relevant folder.
    1. Navigate to **Managed Service for&nbsp;OpenSearch**.
    1. Select ![backups](../../_assets/console-icons/archive.svg) **Backups**.
    1. Find the backup you need using the backup creation time and cluster ID. The **ID** column contains IDs in `<cluster_ID>:<backup_ID>` format.
    1. Click ![image](../../_assets/console-icons/ellipsis.svg) for the backup you need and then click **Restore cluster**.
    1. Configure the new cluster.
    1. Click **Restore cluster**.

    Managed Service for OpenSearch will start creating the cluster from the backup.

- CLI {#cli}

    If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../cli/quickstart.md#install).

    The folder used by default is the one specified when [creating](../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

    To restore a cluster from a backup:

    1. Get the backup ID with the list of all backups in the folder:

        ```bash
        yc managed-opensearch backup list
        ```

        Result:

        ```text
        +----------------------+---------------------+-------------------+---------------------+
        |          ID          |      CREATED AT     | SOURCE CLUSTER ID |      STARTED AT     |
        +----------------------+---------------------+-------------------+---------------------+
        | c9qlk4v13uq7******** | 2024-01-09 14:38:34 | c9qpm4i********   | 2024-01-09 14:38:28 |
        | ...                                                                                  |
        +----------------------+---------------------+-------------------+---------------------+
        ```

        You will see the backup ID in the `ID` column. The `CREATED AT` column shows the backup completion time in `yyyy-mm-dd hh:mm:ss` format.

    1. Make the following request to create a cluster from a backup:

        ```bash
        yc managed-opensearch cluster restore --backup-id <backup_ID>
        ```

        You can also run this command, providing the parameters you set when creating a cluster. For the description of these parameters, see [Creating a cluster](cluster-create.md).

- REST API {#api}

    1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

        ```bash
        export IAM_TOKEN="<IAM_token>"
        ```

    1. Create a file named `body.json` and paste the following code into it:

        ```json
        {
            "backupId": "<backup_ID>",
            "folderId": "<folder_ID>",
            "name": "<cluster_name>",
            "environment": "<environment>",
            "networkId": "<network_ID>",
            "configSpec": {
                "version": "<OpenSearch_version>",
                "adminPassword": "<admin_password>",
                "opensearchSpec": {
                    "nodeGroups": [
                        {
                            "name": "<OpenSearch_host_group_name>",
                            "resources": {
                                "resourcePresetId": "<host_class>",
                                "diskSize": "<storage_size_in_bytes>",
                                "diskTypeId": "<disk_type>"
                            },
                            "roles": ["<role_1>","<role_2>"],
                            "hostsCount": "<number_of_hosts>",
                            "zoneIds": [
                                "<availability_zone_1>",
                                "<availability_zone_2>",
                                "<availability_zone_3>"
                            ],
                            "subnetIds": [
                                "<subnet_1_ID>",
                                "<subnet_2_ID>",
                                "<subnet_3_ID>"
                            ]
                        }
                    ]
                },
                "dashboardsSpec": {
                    "nodeGroups": [
                        {
                            "name": "<Dashboards_host_group_name>",
                            "resources": {
                                "resourcePresetId": "<host_class>",
                                "diskSize": "<storage_size_in_bytes>",
                                "diskTypeId": "<disk_type>"
                            },
                            "hostsCount": "<number_of_hosts>",
                            "zoneIds": [
                                "<availability_zone_1>",
                                "<availability_zone_2>",
                                "<availability_zone_3>"
                            ],
                            "subnetIds": [
                                "<subnet_1_ID>",
                                "<subnet_2_ID>",
                                "<subnet_3_ID>"
                            ]
                        }
                    ]
                }
            }
        }
        ```

        Where:

        * `backupId`: ID of the backup you are restoring the cluster from. You can get it with the [list of backups](#list-backups).
        * `folderId`: Folder ID. You can get it from the [list of your cloud folders](../../resource-manager/operations/folder/get-id.md).
        * `name`: Cluster name.
        * `environment`: Cluster environment, `PRODUCTION` or `PRESTABLE`.
        * `networkId`: ID of the [network](../../vpc/concepts/network.md#network) where the cluster will be deployed.
        * `configSpec`: Cluster settings:

            * `version`: OpenSearch version.
            * `adminPassword`: `admin` password.

                The password must include three groups of characters out of these four:
                
                * Lowercase Latin letters
                * Uppercase Latin letters
                * Numbers
                * Special characters
                
                The password must be from 10 to 72 characters long.

            * `opensearchSpec`: `OpenSearch` host group settings that contain an array of `nodeGroups` elements, one per host group. Each element has the following structure:

                * `name`: Host group name.
                * `resources`: Cluster resources:

                    * `resourcePresetId`: [Host class](../concepts/instance-types.md).
                    * `diskSize`: Disk size, in bytes.
                    * `diskTypeId`: [Disk type](../concepts/storage.md).

                * `roles`: List of [host roles](../concepts/host-roles.md). A cluster must include at least one group of `DATA` hosts and one group of `MANAGER` hosts. This can be a single group with two roles or multiple groups with different roles.
                * `hostsCount`: Number of hosts in the group. Minimum number of `DATA` hosts: one; minimum number of `MANAGER` hosts: three.
                * `zoneIds`: List of availability zones the cluster hosts are located in.
                * `subnetIds`: List of subnet IDs.

            * `dashboardsSpec`: `Dashboards` host group settings that contain an array of `nodeGroups` elements that has the same structure as `opensearchSpec.nodeGroups`, except for the `roles` parameter. The `Dashboards` hosts have only one role, `DASHBOARDS`, so there is no need to specify it.

    1. Call the [Cluster.Restore](../api-ref/Cluster/restore.md) method, e.g., via the following [cURL](https://curl.se/) request:

        ```bash
        curl \
            --request POST \
            --header "Authorization: Bearer $IAM_TOKEN" \
            --header "Content-Type: application/json" \
            --url 'https://mdb.api.cloud.yandex.net/managed-opensearch/v1/clusters:restore' \
            --data "@body.json"
        ```

    1. Check the [server response](../api-ref/Cluster/restore.md#yandex.cloud.operation.Operation) to make sure your request was successful.

- gRPC API {#grpc-api}

    1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

        ```bash
        export IAM_TOKEN="<IAM_token>"
        ```

    1. Clone the [cloudapi](https://github.com/yandex-cloud/cloudapi) repository:
       
       ```bash
       cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
       ```
       
       Below, we assume that the repository contents reside in the `~/cloudapi/` directory.
    1. Create a file named `body.json` and paste the following code into it:

        ```json
        {
            "backup_id": "<backup_ID>",
            "folder_id": "<folder_ID>",
            "name": "<cluster_name>",
            "environment": "<environment>",
            "network_id": "<network_ID>",
            "config_spec": {
                "version": "<OpenSearch_version>",
                "admin_password": "<admin_user_password>",
                "opensearch_spec": {
                    "node_groups": [
                        {
                            "name": "<OpenSearch_host_group_name>",
                            "resources": {
                                "resource_preset_id": "<host_class>",
                                "disk_size": "<storage_size_in_bytes>",
                                "disk_type_id": "<disk_type>"
                            },
                            "roles": ["<role_1>","<role_2>"],
                            "hosts_count": "<number_of_hosts>",
                            "zone_ids": [
                                "<availability_zone_1>",
                                "<availability_zone_2>",
                                "<availability_zone_3>"
                            ],
                            "subnet_ids": [
                                "<subnet_1_ID>",
                                "<subnet_2_ID>",
                                "<subnet_3_ID>"
                            ]
                        }
                    ]
                },
                "dashboards_spec": {
                    "node_groups": [
                        {
                            "name": "<Dashboards_host_group_name>",
                            "resources": {
                                "resource_preset_id": "<host_class>",
                                "disk_size": "<storage_size_in_bytes>",
                                "disk_type_id": "<disk_type>"
                            },
                            "hosts_count": "<number_of_hosts>",
                            "zone_ids": [
                                "<availability_zone_1>",
                                "<availability_zone_2>",
                                "<availability_zone_3>"
                            ],
                            "subnet_ids": [
                                "<subnet_1_ID>",
                                "<subnet_2_ID>",
                                "<subnet_3_ID>"
                            ]
                        }
                    ]
                }
            }
        }
        ```

        Where:

        * `backup_id`: ID of the backup you are restoring the cluster from. You can get it with the [list of backups](#list-backups).
        * `folder_id`: Folder ID. You can get it with the [list of folders in the cloud](../../resource-manager/operations/folder/get-id.md).
        * `name`: Cluster name.
        * `environment`: Cluster environment, `PRODUCTION` or `PRESTABLE`.
        * `network_id`: ID of the [network](../../vpc/concepts/network.md#network) where the cluster will be deployed.
        * `config_spec`: Cluster settings:

            * `version`: OpenSearch version.
            * `admin_password`: `admin` password.

                The password must include three groups of characters out of these four:
                
                * Lowercase Latin letters
                * Uppercase Latin letters
                * Numbers
                * Special characters
                
                The password must be from 10 to 72 characters long.

            * `opensearch_spec`: `OpenSearch` host group settings that contain an array of `nodeGroups` elements, one per host group. Each element has the following structure:

                * `name`: Host group name.
                * `resources`: Cluster resources:

                    * `resource_preset_id`: [Host class](../concepts/instance-types.md).
                    * `disk_size`: Disk size, in bytes.
                    * `disk_type_id`: [Disk type](../concepts/storage.md).

                * `roles`: List of [host roles](../concepts/host-roles.md). A cluster must include at least one group of `DATA` hosts and one group of `MANAGER` hosts. This can be a single group with two roles or multiple groups with different roles.
                * `hosts_count`: Number of hosts in the group. Minimum number of `DATA` hosts: one; minimum number of `MANAGER` hosts: three.
                * `zone_ids`: List of availability zones the cluster hosts are located in.
                * `subnet_ids`: List of subnet IDs.

            * `dashboards_spec`: `Dashboards` host group settings that contain an array of `node_groups` elements that has the same structure as `opensearch_spec.node_groups`, except for the `roles` parameter. The `Dashboards` hosts have only one role, `DASHBOARDS`, so there is no need to specify it.

    1. Call the [ClusterService.Restore](../api-ref/grpc/Cluster/restore.md) method, e.g., via the following [gRPCurl](https://github.com/fullstorydev/grpcurl) request:

        ```bash
        grpcurl \
            -format json \
            -import-path ~/cloudapi/ \
            -import-path ~/cloudapi/third_party/googleapis/ \
            -proto ~/cloudapi/yandex/cloud/mdb/opensearch/v1/cluster_service.proto \
            -rpc-header "Authorization: Bearer $IAM_TOKEN" \
            -d @ \
            mdb.api.cloud.yandex.net:443 \
            yandex.cloud.mdb.opensearch.v1.ClusterService.Restore \
            < body.json
        ```

    1. Check the [server response](../api-ref/grpc/Cluster/restore.md#yandex.cloud.operation.Operation) to make sure your request was successful.

{% endlist %}

### Deleting a backup {#delete-backup}

{% list tabs group=instructions %}

- Management console {#console}

    1. Navigate to the folder dashboard and select **Managed Service for&nbsp;OpenSearch**.
    1. Click the cluster name and open the ![backups](../../_assets/console-icons/archive.svg) **Backups** tab.
    1. Click ![image](../../_assets/console-icons/ellipsis.svg) for your backup and click **Delete backup**.

- REST API {#api}

    1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

        ```bash
        export IAM_TOKEN="<IAM_token>"
        ```

    1. Call the [Cluster.DeleteBackup](../api-ref/Cluster/deleteBackup.md) method, e.g., via the following [cURL](https://curl.se/) request:

        ```bash
        curl \
            --request DELETE \
            --header "Authorization: Bearer $IAM_TOKEN" \
            --header "Content-Type: application/json" \
            --url 'https://mdb.api.cloud.yandex.net/managed-opensearch/v1/clusters/<cluster_ID>/backups/<backup_ID>'
        ```

        You can get the cluster ID with the [list of clusters in the folder](cluster-list.md#list-clusters).

    1. Check the [server response](../api-ref/Cluster/deleteBackup.md#yandex.cloud.operation.Operation) to make sure your request was successful.

- gRPC API {#grpc-api}

    1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

        ```bash
        export IAM_TOKEN="<IAM_token>"
        ```

    1. Clone the [cloudapi](https://github.com/yandex-cloud/cloudapi) repository:
       
       ```bash
       cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
       ```
       
       Below, we assume that the repository contents reside in the `~/cloudapi/` directory.
    1. Call the [ClusterService.DeleteBackup](../api-ref/grpc/Cluster/deleteBackup.md) method, e.g., via the following [gRPCurl](https://github.com/fullstorydev/grpcurl) request:

        ```bash
        grpcurl \
            -format json \
            -import-path ~/cloudapi/ \
            -import-path ~/cloudapi/third_party/googleapis/ \
            -proto ~/cloudapi/yandex/cloud/mdb/opensearch/v1/cluster_service.proto \
            -rpc-header "Authorization: Bearer $IAM_TOKEN" \
            -d '{
                  "cluster_id": "<cluster_ID>",
                  "backup_id": "<backup_ID>"
                }' \
            mdb.api.cloud.yandex.net:443 \
            yandex.cloud.mdb.opensearch.v1.ClusterService.deleteBackup
        ```

        You can get the cluster ID with the [list of clusters in the folder](cluster-list.md#list-clusters).

    1. Check the [server response](../api-ref/grpc/Cluster/deleteBackup.md#yandex.cloud.operation.Operation) to make sure your request was successful.

{% endlist %}

## Backing up using snapshots {#snapshot-backups}

Work with snapshots via the [OpenSearch public API](https://opensearch.org/docs/latest/api-reference/index/) and store them in a bucket in Object Storage.

{% note info %}

Snapshots created with Yandex Cloud tools are stored in the `yc-automatic-backups` repository under the following names: `yc-automatic-backups-******` (for automatic backups) or `manual-snapshot-******` (for manual backups).

{% endnote %}

### Getting a snapshot list {#list-snapshots}

##### **For snapshots created with Yandex Cloud tools**

Get a list of snapshots in the `yc-automatic-backups` repository:

 ```http
 GET https://admin:<password>@<ID_of_OpenSearch_host_with_DATA_role>.mdb.yandexcloud.net:9200/_snapshot/<repository_name>/_all
 ```
Each snapshot is a single backup.

##### **For snapshots created with OpenSearch tools**

1. Get a list of OpenSearch repositories:

    ```http
    GET https://admin:<password>@<ID_of_OpenSearch_host_with_DATA_role>.mdb.yandexcloud.net:9200/_snapshot/_all
    ```

   If the repository you need is not on the list, [add it](s3-access.md).

1. Find the relevant repository with snapshots.

1. Get a list of snapshots in the repository:

    ```http
    GET https://admin:<password>@<ID_of_OpenSearch_host_with_DATA_role>.mdb.yandexcloud.net:9200/_snapshot/<repository_name>/_all
    ```

   Each snapshot is a single backup.

### Creating a snapshot {#create-snapshot}

{% note warning %}

You cannot create a snapshot in the `yc-automatic-backups` repository.

{% endnote %}

1. In the OpenSearch repository list, find the repository where you want to create a snapshot backup:

    ```http
    GET https://admin:<password>@<ID_of_OpenSearch_host_with_DATA_role>.mdb.yandexcloud.net:9200/_snapshot/_all
    ```

    If the repository you need is not on the list, [add it](s3-access.md).

1. [Create a snapshot](https://opensearch.org/docs/latest/opensearch/snapshots/snapshot-restore/#take-snapshots) of the specific data or cluster in this repository:

    ```http
    PUT https://admin:<password>@<ID_of_OpenSearch_host_with_DATA_role>.mdb.yandexcloud.net:9200/_snapshot/<repository_name>/<snapshot_name>
    ```


### Restoring an index from a snapshot {#restore-index-from-snapshot}

To restore one or multiple indexes from a snapshot:

1. Close any existing indexes that you want to restore:
    
    ```http
    POST https://admin:<password>@<FQDN_of_OpenSearch_host_with_DATA_role>.mdb.yandexcloud.net:9200/<index_list>/_close
    ```

    To learn how to get a host’s FQDN, see [FQDNs of OpenSearch hosts](connect/fqdn.md).

    For more information on closing indexes, see [this OpenSearch guide](https://opensearch.org/docs/latest/api-reference/index-apis/close-index/).

1. Restore the indexes from the snapshot:

    ```http
    POST https://admin:<password>@<FQDN_of_OpenSearch_host_with_DATA_role>.mdb.yandexcloud.net:9200/_snapshot/<repository_name>/<snapshot_name>/_restore?wait_for_completion=true&pretty
    
    {
      "indices": "<list_of_indexes>",
      "ignore_unavailable": false,
      "include_global_state": false
    }
    ```

    Where:
    
    * `indices`: Comma-separated list of indexes to restore.
    * `ignore_unavailable`: Behavior if a requested index is missing from the snapshot.
      
      * `true`: Missing indexes are ignored.
      * `false`: Restore operation fails with an error.
    
    * `include_global_state`: Restoring the global state of the cluster:

      * `true`: Cluster state is restored.
      * `false`: Cluster state is not restored.

    You can get the snapshot name with the [list of snapshots](#list-snapshots).

    For more on restoration from snapshots, see [this OpenSearch guide](https://opensearch.org/docs/latest/api-reference/snapshots/restore-snapshot/).


### Restoring a cluster from a snapshot {#restore-from-snapshot}

{% note warning %}

When restoring a cluster from a snapshot, the OpenSearch version in the cluster must be the same or higher than the OpenSearch version where the snapshot was taken.

{% endnote %}

1. [Create an OpenSearch cluster](cluster-create.md) with the required configuration but do not populate it with data.

    When creating a cluster, select:

    * Number and class of hosts as well as the storage size and disk type based on the snapshot size and performance requirements.

    * OpenSearch version used to make the snapshot or a higher one.

1. Close any open indexes using the [OpenSearch API](https://opensearch.org/docs/latest/api-reference/index-apis/close-index/):

    ```http
    POST https://admin:<password>@<ID_of_OpenSearch_host_with_DATA_role>.mdb.yandexcloud.net:9200/<index_name>/_close
    ```

    To restore an entire cluster, close all open indexes. To restore individual indexes, close only those indexes.

1. [Get a list of backups](#list-snapshots) and find the required snapshot.
1. [Start restoring](https://opensearch.org/docs/latest/opensearch/snapshots/snapshot-restore/#restore-snapshots) an entire cluster or individual data indexes and streams from this snapshot.

### Deleting a snapshot {#delete-snapshot}

1. Find the repository containing snapshot backups in the OpenSearch repository list:

    ```http
    GET https://admin:<password>@<ID_of_OpenSearch_host_with_DATA_role>.mdb.yandexcloud.net:9200/_snapshot/_all
    ```

   If the repository you need is not on the list, [add it](s3-access.md).

1. Delete the snapshot from the repository:

    ```http
    DELETE https://admin:<password>@<ID_of_OpenSearch_host_with_DATA_role>.mdb.yandexcloud.net:9200/_snapshot/<repository_name>/<snapshot_name>
    ```