<commit_before>#!/bin/bash

set -e

# Redirect stdout and stderr to syslog
exec 1> >(/usr/bin/logger -s -t $(basename $0)) 2>&1

ES_SNAPSHOT=snapshot_$(date +%F)

# PARAMETERS FOR ELASTICSEARCH SNAPSHOT RESTORE
RESTORE_DATA=$(cat <<EOD
{
  "indices": "<%= @json_es_indices %>",
  "include_global_state": false,
  "rename_pattern": "index_(.+)",
  "rename_replacement": "restored_index_$1"
}
EOD
)

# List the snapshots and grab the last one
LATEST_SNAPSHOT=$(/usr/bin/curl --connect-timeout 10 -sS -XGET "127.0.0.1:9200/_snapshot/<%= @es_repo %>/_all?pretty" | /usr/bin/jq --raw-output ".snapshots[].snapshot" |tail -1)

curl -XPOST "localhost:9200/_snapshot/${ES_REPO}/${LATEST_SNAPSHOT}/_restore" -d $"${RESTORE_DATA}"<commit_msg>Update restore task<commit_after>#!/bin/bash

set -e

# Redirect stdout and stderr to syslog
exec 1> >(/usr/bin/logger -s -t $(basename $0)) 2>&1

INDEX=$1

if [[ -z $INDEX ]]; then
  echo "Must set index to restore"
  echo "Available indices: "
  curl -s 127.0.0.1:9200/_snapshot/snapshots/_all?pretty | jq '.snapshots[].indices'
  exit 1
fi

# PARAMETERS FOR ELASTICSEARCH SNAPSHOT RESTORE
RESTORE_DATA=$(cat <<EOD
{
  "indices": "${INDEX}",
  "include_global_state": false,
  "rename_pattern": "index_(.+)",
  "rename_replacement": "restored_index_$1"
}
EOD
)

# List the snapshots and grab the last one
LATEST_SNAPSHOT=$(/usr/bin/curl --connect-timeout 10 -sS -XGET "127.0.0.1:9200/_snapshot/<%= @es_repo %>/_all?pretty" | /usr/bin/jq --raw-output ".snapshots[].snapshot" |tail -1)

curl -XPOST "localhost:9200/_snapshot/<%= @es_repo %>/${LATEST_SNAPSHOT}/_restore" -d $"${RESTORE_DATA}"
{'fraction_non_alphanumeric': 0.18237831176833025, 'fraction_numerical': 0.03450400492914356, 'mean_word_length': 4.638888888888889, 'pattern_counts': {'":': 8, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 3, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6198815', 'n_tokens_mistral': 697, 'n_tokens_neox': 667, 'n_words': 145}