Elasticsearch Snapshots - ubtue/ub_tools GitHub Wiki
Für eine konsistente Sicherung der Volltextindices bietet Elasticsearch eine Snapshot-Funktionalität
Setup
Voraussetzung ist die Konfiguration eines Repositories. Für muss in der Configdatei elasticsearch.yml path.repo gesetzt werden:
path.repo: ["/usr/local/es_backup"]
Danach erfolgt das Anlegen des Snapshot-Repositories in Elasticsearch
curl -g -XPUT -H "Content-Type: application/json" 'http://localhost:9200/_snapshot/es_backup' -d '{ "type": "fs",
"settings": {
"location": "/usr/local/es_backup"
}}'
Erstellung und Restore
Ein Snapshot kann manuell erzeugt werden:
curl -g -s -XPUT -H "Content-Type: application/json" 'http://localhost:9200/_snapshot/es_backup/<SNAPSHOT_NAME>?wait_for_completion=true' -d '{ "indices" : ["full_text_cache", "full_text_cache_html", "full_text_cache_urls" ] }'
Eine Wiederherstellung erfolgt durch:
curl -g -s -XPOST -H "Content-Type: application/json" 'http://localhost:9200/_snapshot/es_backup/<SNAPSHOT_NAME>/_restore' -d '{ "indices" : ["full_text_cache", "full_text_cache_html", "full_text_cache_urls" ] }'
SLM ("Scheduled Lifecycle Management")
Elasticsearch bietet einer Art internen Cronjob für die regelmäßige inkrementelle Erstellung von Snapshots. Die Zeit ist dabei immer UTC und muss entsprechend angepasst werden
curl -g -s -XPUT -H "Content-Type: application/json" http://localhost:9200/_slm/policy/fulltext-snapshots -d '{ "schedule": "0 0 19 * * ?", "name": "<fulltext-snap-{now/d{yyMMdd}}>", "repository": "es_backup", "config" : { "indices" : [ "full_text_cache", "full_text_cache_html", "full_text_cache_urls" ] }, "retention": { "expire_after": "10d", "min_count": 7, "max_count": 10 } }'
Nach dem Anlegen kann eine unmittelbare Ausführung getriggert werden:
curl -g -s -XPOST -H "Content-Type: application/json" 'http://localhost:9200/_slm/policy/fulltext-snapshots/_execute'
Informationen über den SLM-Zustand bekommt man mit:
curl -g -s -XGET -H "Content-Type: application/json" 'http://localhost:9200/_slm/policy/fulltext-snapshots?human'
Löschen einer SLM-Policy
curl -g -s -XDELETE -H "Content-Type: application/json" 'http://localhost:9200/_slm/policy/fulltext-snapshots'
Fixing nach dem Umkopieren
Beim Umkopieren des Index bei Migrationen kann ein inkonsistenter Zustand entstehen, wenn das Bakcupverzeichnis nicht mitübertragen wird. Ein konsistenter Zustand kann dann durch durch Löschen und Wiederanlegen von Policy und Repository erfolgen:
curl -g -s -XDELETE -H "Content-Type: application/json" 'http://localhost:9200/_slm/policy/fulltext-snapshots'
curl -X DELETE "localhost:9200/_snapshot/es_backup?pretty"
curl -g -XPUT -H "Content-Type: application/json" 'http://localhost:9200/_snapshot/es_backup' -d '{ "type": "fs", "settings":
"location": "/usr/local/es_backup" } }'
curl -g -s -XPUT -H "Content-Type: application/json" http://localhost:9200/_slm/policy/fulltext-snapshots -d '{ "schedule": "0 0 19 * * ?", "name": "<fulltext-snap-{now/d{yyMMdd}}>", "repository": "es_backup", "config" : { "indices" : [ "full_text_cache", "full_text_cache_html", "full_text_cache_urls" ] }, "retention": { "expire_after": "10d", "min_count": 7, "max_count": 10 } }'