Snapshot and restore lets you save a copy of your Elasticsearch data and bring it back later. It helps keep your data safe and move it between clusters.
Snapshot and restore in Elasticsearch
Start learning this pattern below
Jump into concepts and practice - no test required
PUT /_snapshot/{repository}/{snapshot}
{
"indices": "index1,index2",
"ignore_unavailable": true,
"include_global_state": false
}repository is the name of the backup location you set up.
snapshot is the name you give to this backup copy.
snapshot_1 in the my_backup repository for two indexes: logs-2023 and users.PUT /_snapshot/my_backup/snapshot_1
{
"indices": "logs-2023,users",
"ignore_unavailable": true,
"include_global_state": false
}logs-2023 index from snapshot_1 and renames it to restored-logs-2023.POST /_snapshot/my_backup/snapshot_1/_restore
{
"indices": "logs-2023",
"rename_pattern": "logs-(.+)",
"rename_replacement": "restored-logs-$1"
}This example first creates a snapshot repository called my_backup that saves backups to a folder on disk. Then it takes a snapshot of the test-index. Finally, it restores that snapshot but renames the index to restored-test-index.
PUT /_snapshot/my_backup
{
"type": "fs",
"settings": {
"location": "/mnt/backups/elasticsearch"
}
}
PUT /_snapshot/my_backup/snapshot_1
{
"indices": "test-index",
"ignore_unavailable": true,
"include_global_state": false
}
POST /_snapshot/my_backup/snapshot_1/_restore
{
"indices": "test-index",
"rename_pattern": "test-(.+)",
"rename_replacement": "restored-test-$1"
}You must create a snapshot repository before taking snapshots.
Snapshots are incremental, so only new or changed data is saved after the first snapshot.
Restoring can rename indexes to avoid overwriting existing data.
Snapshot and restore help protect your Elasticsearch data by saving and recovering it.
You create a repository, take snapshots, and restore them when needed.
Snapshots can include specific indexes and be renamed on restore.
Practice
Solution
Step 1: Understand snapshot purpose
A snapshot in Elasticsearch is used to save a backup of your data at a point in time.Step 2: Compare options
Options B, C, and D describe other Elasticsearch features, not snapshot backup.Final Answer:
To save a backup of your data for recovery later -> Option AQuick Check:
Snapshot = Backup [OK]
- Confusing snapshots with index templates
- Thinking snapshots speed up searches
- Assuming snapshots delete data
Solution
Step 1: Identify correct HTTP method for creating repository
Creating a snapshot repository uses the PUT method to define or update it.Step 2: Check other methods
POST is for creating snapshots, GET is for retrieving info, DELETE is for removing repositories.Final Answer:
PUT /_snapshot/my_backup {"type": "fs", "settings": {"location": "/mount/backups"}} -> Option BQuick Check:
Repository creation = PUT [OK]
- Using POST instead of PUT for repository creation
- Confusing GET with creation commands
- Trying to delete instead of create repository
POST /_snapshot/my_backup/snapshot_1/_restore
{
"indices": "index1,index2",
"rename_pattern": "index(.*)",
"rename_replacement": "restored_index$1"
}What will be the name of the restored index originally named
index2?Solution
Step 1: Understand rename_pattern and rename_replacement
The pattern "index(.*)" captures the part after "index". The replacement "restored_index$1" adds "restored_index" plus the captured part.Step 2: Apply to index2
For "index2", the captured part is "2", so the new name is "restored_index2".Final Answer:
restored_index2 -> Option AQuick Check:
Rename pattern + replacement = restored_index2 [OK]
- Ignoring rename_pattern and keeping original name
- Adding extra 'index' in the replacement
- Misplacing the captured group in new name
repository_missing_exception. What is the most likely cause?Solution
Step 1: Understand repository_missing_exception meaning
This error means Elasticsearch cannot find the snapshot repository to access snapshots.Step 2: Check other options
Snapshot name errors cause different exceptions; corrupted indices cause restore failures but not repository missing; version mismatch causes other errors.Final Answer:
The snapshot repository does not exist or is not registered -> Option CQuick Check:
repository_missing_exception = missing repository [OK]
- Assuming snapshot name typo causes repository_missing_exception
- Blaming corrupted indices for repository errors
- Ignoring repository setup before restore
{
"indices": "logs-2023,metrics-2023",
"rename_pattern": "(.*)-2023",
"rename_replacement": "$1-restore"
}Solution
Step 1: Analyze indices and rename_pattern
Indices "logs-2023" and "metrics-2023" match the pattern "(.*)-2023" capturing "logs" and "metrics".Step 2: Apply rename_replacement
Replacement "$1-restore" changes names to "logs-restore" and "metrics-restore".Step 3: Confirm only specified indices restored
Only indices listed in "indices" are restored, renamed as specified.Final Answer:
Restores logs-2023 and metrics-2023 as logs-restore and metrics-restore -> Option DQuick Check:
Indices filtered + renamed correctly = Restores logs-2023 and metrics-2023 as logs-restore and metrics-restore [OK]
- Restoring all snapshot indices ignoring filter
- Not using rename_pattern correctly
- Expecting renamed indexes to exist before restore
