Restoring snapshots by using _snapshot API

You can restore indices of OpenSearch data by using _snapshot API.

About this task

The _snapshot API is described on the Take and restore snapshots External link opens a new window or tab page of the OpenSearch documentation.

Procedure

  1. Scale down the operator deployment.
    1. Retrieve the initial number of initial replicas.
      kubectl get deployment ibm-bai-insights-engine-operator -o jsonpath='{.spec.replicas}'
    2. Scale down the number of operator deployments to 0.
      kubectl scale --replicas=0 deployment ibm-insights-engine-operator
  2. Stop the Flink event processors.
    1. Delete the Flink job submitters.
      kubectl delete Job -l 'app.kubernetes.io/name in (ibm-business-automation-insights)'
    2. Retrieve the management service URL and credentials.
    3. Cancel the Flink jobs.
      curl -X POST -k -u ${MANAGEMENT_USERNAME}:${MANAGEMENT_PASSWORD} "${MANAGEMENT_URL}/api/v1/processing/jobs/savepoints?cancel-Job=true"
  3. List the indices to restore.
    OPENSEARCH_URL="https://$(kubectl get routes opensearch-route -o jsonpath="{.spec.host}" -n "$NAMESPACE")"
    OPENSEARCH_USERNAME=$(kubectl get secret/opensearch-admin-user -o json -n "$NAMESPACE" | jq -r '.data|keys[0]')
    OPENSEARCH_PASSWORD=$(kubectl extract secret/opensearch-admin-user --keys="$OPENSEARCH_USERNAME" --to=- -n "$NAMESPACE" 2>/dev/null)
    OPENSEARCH_INDEXES=$(curl -k -u ${OPENSEARCH_USERNAME}:${OPENSEARCH_PASSWORD} -X GET "${OPENSEARCH_URL}/_cat/indices?h=index" | grep "icp4ba-bai")
  4. Close each index in the list.
    echo "$OPENSEARCH_INDEXES" | while read -r idx; do
    curl -k -u ${OPENSEARCH_USERNAME}:${OPENSEARCH_PASSWORD} -X POST "${OPENSEARCH_URL}/${idx}/_close"
    done
    for idx in ${OPENSEARCH_INDEXES}; do
      curl -k -u "${OPENSEARCH_USERNAME}:${OPENSEARCH_PASSWORD}" -X POST "${OPENSEARCH_URL}/${idx}/_close"
    done
  5. List all available repositories.
    curl -k -u "${OPENSEARCH_USERNAME}:${OPENSEARCH_PASSWORD}" -H "Content-Type: application/json" -X GET "${OPENSEARCH_URL}/_snapshot/"
  6. List all snapshots in the repository.
    REPOSITORY_NAME=my_backup
    curl -k -u "${OPENSEARCH_USERNAME}:${OPENSEARCH_PASSWORD}" -H "Content-Type: application/json" -X GET "${OPENSEARCH_URL}/_snapshot/${REPOSITORY_NAME}/_all" | jq
  7. Restore these indices by using the OpenSearch _snapshot API.
    curl -k -u "${OPENSEARCH_USERNAME}:${OPENSEARCH_PASSWORD}" -H "Content-Type: application/json" -X POST "${OPENSEARCH_URL}/_snapshot/<your_repository_name>/<your_snapshot_name>/_restore" -d '{"indices": "icp4ba-bai*"}'
  8. Scale the operator deployment back up to redeploy the Flink jobs.
    kubectl scale --replicas=<initialReplicas> deployment ibm-insights-engine-operator