elasticsearch: ajout de methode pour le snapshot depuis plusieurs serveurs sans s'écraser

This commit is contained in:
Jérémy Lecour 2023-12-21 19:04:59 +01:00 committed by Jérémy Lecour
parent 19bd3ea599
commit 06a59812fc
Signed by: jlecour
SSH key fingerprint: SHA256:h+5LgHRKwN9lS0SsdVR5yZPeFlJE4Mt+8UtL4CcP8dY

View file

@ -870,13 +870,7 @@ path.repo: /home/backup-elasticsearch
Il faut redémarrer Elasticsearch et créer un dépôt de _snapshots_ :
~~~
$ curl -H'Content-Type: application/json' -XPUT 'http://localhost:9200/_snapshot/snaprepo' -d '{
"type": "fs",
"settings": {
"location": "/home/backup-elasticsearch",
"compress": true
}
}'
$ curl -H 'Content-Type: application/json' -XPUT 'http://localhost:9200/_snapshot/snaprepo' -d '{"type": "fs", "settings": {"location": "/home/backup-elasticsearch", "compress": true}}'
{"acknowledged":true}
~~~
@ -987,7 +981,7 @@ $ for i in $(ls -1d snapshot-* | head -n -10 | sed s'/snapshot-snapshot_//g'); d
hot_${i}"; done
~~~
Dans le cas de _snapshot_ pour un ElasticSearsch _clusterisé_ :
Dans le cas de _snapshot_ pour un Elasticsearch _clusterisé_ :
~~~
# if ss | grep ':nfs' | grep -q 'ip\.add\.res\.s1' && ss | grep ':nfs' | grep -q 'ip\.add\.res\.s2'
@ -1004,6 +998,26 @@ Dans le cas de _snapshot_ pour un ElasticSearsch _clusterisé_ :
# curl -s -XPUT "localhost:9200/_snapshot/snaprepo/snapshot_${date}?wait_for_completion=true" -o /tmp/es_snapshot_${date}.log
~~~
Si on veut tester la présence d'un _snapshot_ du jour avant de le faire (attention, il faut avoir `jq` installé) :
~~~
ES_HOST="http://localhost:9200"
ES_CURL_COMMON_OPTIONS="--insecure -u USER:PASSWORD --silent"
ES_SNAPSHOT_REPO="snaprepo"
ES_SNAPSHOT_NAME="snapshot.daily"
ES_CURL_BASE_URL="${ES_HOST}/_snapshot/${ES_SNAPSHOT_REPO}/${ES_SNAPSHOT_NAME}"
last_daily_raw=$(curl ${ES_CURL_COMMON_OPTIONS} --fail "${ES_CURL_BASE_URL}/" | jq ".snapshots[] | select(.snapshot | contains(\"${ES_SNAPSHOT_NAME}\")) | .end_time" | tr -d '"')
last_daily=$(date --iso-8601=date --date="${last_daily_raw:-"@0"}")
today=$(date --iso-8601=date)
if [ "${last_daily}" != "${today}" ]; then
# Don't display errors for the delete command
curl ${ES_CURL_COMMON_OPTIONS} -XDELETE "${ES_CURL_BASE_URL}" > /dev/null
curl ${ES_CURL_COMMON_OPTIONS} --fail --show-error -XPUT "${ES_CURL_BASE_URL}?wait_for_completion=true" > /dev/null
fi
~~~
### Restauration d'un _snapshot_
Le _snapshot_ doit être listé dans le dépôt de _snapshot_.