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
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.