AI Hints
Home›Elasticsearch Tutorial›Data Streams, Snapshots and Security
Elasticsearch · Lesson 110 of 120

Snapshots

Backup and restore.

⏱ 2 min read▶ Video at 1:43:54🎓 Free
Watch this lesson in the Elasticsearch courseWatch on YouTube ↗Full Elasticsearch course

Replicas protect against a broken machine, not against mistakes. If someone deletes an index, every replica is gone too. Snapshots are real backups, saved outside the cluster.

  • Replicas ≠ backup
  • Oops, deleted
  • Snapshots

Back up, delete, restore

First, register a snapshot repository on disk. Take a snapshot of products. Then, oops, we delete the index. Restore brings it back from the snapshot. Run it. All forty nine products are back.

Dev Tools Consoletext
PUT _snapshot/backups?filter_path=acknowledged
{ "type": "fs", "settings": { "location": "backups" } }

PUT _snapshot/backups/snap-1?wait_for_completion=true&filter_path=snapshot.state
{ "indices": "products" }

DELETE products?filter_path=acknowledged

POST _snapshot/backups/snap-1/_restore?wait_for_completion=true&filter_path=snapshot.indices
{ "indices": "products" }

GET products/_count?filter_path=count
Output
# PUT _snapshot/backups 200 OK
{"acknowledged": true}

# PUT _snapshot/backups/snap-1 200 OK
{"snapshot": {"state": "SUCCESS"}}

# DELETE products 200 OK
{"acknowledged": true}

# POST _snapshot/backups/snap-1/_restore 200 OK
{"snapshot": {"indices": ["products"]}}

# GET products/_count 200 OK
{"count": 49}
Also uses _load
catalog

In production

Store snapshots in cloud storage, like S3, GCS or Azure. Snapshots are incremental, so frequent ones are cheap. Snapshot lifecycle management takes them on a schedule. And test a restore, before you need one.

keyvalue
WhereS3, GCS, Azure
Incrementalonly new data
SLMscheduled snapshots
Testpractise restores

Summary

Snapshots are real backups, and restore brings indices back after a mistake. Next, security basics.

Key takeaways
  • Repository
  • Snapshot
  • Restore
Next up: Security Basics — users, roles and keys