Configuring Backup Repository
Navigate to the elasticsearch-6.2.2\config directory and modify the elasticsearch.yml configuration file. Add the following line at the end to specify the backup storage path:
path.repo: ["D:/backup_storage/elastic_backup"]
Create the designated folder at the specified location if it doesn't exist.
Creating Snapshot Repository
Using Command Line
curl -XPUT "http://localhost:9200/_snapshot/es_repository" -H "Content-Type: application/json" -d "{\"type\": \"fs\",\"settings\":{\"location\":\"D:/backup_storage/elastic_backup/snapshot_data\",\"compress\": \"true\",\"max_snapshot_bytes_per_sec\":\"50mb\",\"max_restore_bytes_per_sec\":\"50mb\"}}"
Using Kibana Dev Tools
PUT _snapshot/es_repository
{
"type": "fs",
"settings": {
"location": "D:/backup_storage/elastic_backup/snapshot_data",
"compress": true,
"max_snapshot_bytes_per_sec": "50mb",
"max_restore_bytes_per_sec": "50mb"
}
}
This creates a repository named "es_repository" with file system storage at the specified location.
Creating Snapshots
Command Line Method
curl -XPUT "http://localhost:9200/_snapshot/es_repository/daily_backup_001?wait_for_completion=true"
Kibana Dev Tools Method
PUT _snapshot/es_repository/daily_backup_001?wait_for_completion=true
Creates a snapshot named "daily_backup_001" in the es_repository repository.
Monitoring Snapshots
Command Line
curl -XGET "http://localhost:9200/_snapshot/es_repository/_all"
Kibana Dev Tools
GET _snapshot/es_repository/_all
Data Restoration Process
Backup Current Data
Before restoration, create a backup of the current ES data directory to prevent data loss.
Clear Existing Data
curl -XDELETE "http://localhost:9200/_all"
Expected response:
{"acknowledged": true}
Restore from Snapshot
curl -XPOST "http://localhost:9200/_snapshot/es_repository/daily_backup_001/_restore"
Successful restoration response:
{"accepted": true}
Snapshot Management
Deleting Snapshots
curl -XDELETE "http://localhost:9200/_snapshot/es_repository/daily_backup_001"
Automated Backup Scheduling
Backup Script Creation
Create es_backup.bat with the following content:
@echo off
for /f "tokens=2 delims==" %%I in ('wmic os get localdatetime /value') do set datetime=%%I
set current_year=%datetime:~0,4%
set current_month=%datetime:~4,2%
set current_day=%datetime:~6,2%
set backup_date=%current_year%-%current_month%-%current_day%
curl -XPUT "http://localhost:9200/_snapshot/es_repository/snapshot_%backup_date%?wait_for_completion=true"
Windows Task Schedluer Setup
Configure Windows Task Scheduler to execute the batch file at regular intervals, establishing automated Elasticsearch snapshot backups.