Ajout d'infos pour les sauvegardes

This commit is contained in:
gcolpart 2018-07-19 16:06:53 +02:00
parent 208d515ad8
commit c0af1da48b

View file

@ -294,29 +294,45 @@ $ curl -s -XDELETE "localhost:9200/_snapshot/foo/snapshot_test"
### Sauvegarde via snapshots
Il faut donc avoir une directive `path.repo: ["/home/backup-elasticsearch"]` prise en compte par Elasticsearch avec un répertoire existant.
Puis on crée
Créons un snapshot repository nommé `snaprepo` :
~~~
$ curl -XPUT 'http://localhost:9200/_snapshot/snaprepo' -d '{
"type": "fs",
"settings": {
"location": "/home/backup-elasticsearch",
"compress": true
}
}'
{"acknowledged":true}
~~~
On peut ainsi créer régulièrement des snapshots pour les sauvegardes.
Pour créer un snapshot toutes les heures, et en conserver 24 en permanence (notion de snapshots "roulants") :
~~~
$ date=$(date +%H)
$ curl -s -X DELETE "127.0.0.1:9200/_snapshot/foo/h${date}" | grep -v acknowledged..true
$ curl -s -X PUT "127.0.0.1:9200/_snapshot/foo/h${date}?wait_for_completion=true" -o /tmp/es_snapshot_h${date}.log
$ curl -s -X DELETE "127.0.0.1:9200/_snapshot/snaprepo/h${date}" | grep -v acknowledged..true
$ curl -s -X PUT "127.0.0.1:9200/_snapshot/snaprepo/h${date}?wait_for_completion=true" -o /tmp/es_snapshot_h${date}.log
~~~
Plus classiquement pour avoir un snapshot par jour :
~~~
$ date=$(date +%Y-%m-%d)
$ curl -s -XDELETE "localhost:9200/_snapshot/foo/snapshot_${date}" | grep -v acknowledged..true
$ curl -s -XPUT "localhost:9200/_snapshot/foo/snapshot_${date}?wait_for_completion=true" -o /tmp/es_snapshot_${date}.log
$ curl -s -XDELETE "localhost:9200/_snapshot/snaprepo/snapshot_${date}" | grep -v acknowledged..true
$ curl -s -XPUT "localhost:9200/_snapshot/snaprepo/snapshot_${date}?wait_for_completion=true" -o /tmp/es_snapshot_${date}.log
~~~
On peut ensuite purger les snapshots vieux de plus de 10 jours ainsi :
~~~
$ cd /home/backup-elasticsearch/foo
$ for i in $(ls -1d snapshot-* | head -n -10 | sed s'/snapshot-snapshot_//g'); do curl -s -XDELETE "localhost:9200/_snapshot/foo/snaps
$ cd /home/backup-elasticsearch/snaprepo
$ for i in $(ls -1d snapshot-* | head -n -10 | sed s'/snapshot-snapshot_//g'); do curl -s -XDELETE "localhost:9200/_snapshot/snaprepo/snaps
hot_${i}"; done
~~~