-
The path.data address written in Elasticsearch’s configuration file can be backed up incrementally or at certain intervals as is by system administrators.
PRO Access to historical data will always continue with the same ease.
-
The server where Elasticsearch is located can be backed up using Raid-0 method or at certain intervals as is.
PRO Access to historical data will always continue with the same ease.PRO When there is a problem with the main disk, the backup disk can be started immediately with network routing.
-
Elasticsearch data can be dumped using Elasticsearch Snapshot API. By setting a snapshot policy, these backup files can be extracted to a specific system address, and then these backup files should be backed up separately to a different server.
PRO Access to historical data will always continue with the same ease.
RECOMMENDATION Regardless of which method above is used, after regular backup is set up, backed up logs can be set to automatically delete with Elasticsearch ILM or can be manually deleted as desired using Elasticsearch API.
PRO Work will continue with much lower disk resources on the active server.
Elasticsearch Manual Backup and Restore
This section explains how to create the Snapshot Lifecycle Management (SLM) policy created for automatic backup of logs on Elasticsearch through cron definition and methods for instant backup and restore.Variables
Dynamic values and their descriptions in the requests are shown in the table below.Specifying Backup File Location
By adding the path.repo field to the elasticsearch.yml configuration file of all nodes in the cluster, the file location where backup files will be stored is written.Defining Snapshot Repository Information
Repository holds information about where files to be backed up in snapshot operations will be stored.Repository Verification Request (Verify Location)
It should be checked whether Elasticsearch has access to the file.If verification is successful, the list of nodes using the repository is returned. If verification fails, an error is returned from the request.
Creating SLM Policy
Creating Snapshot Policy Request
Manually Executing Policy Request
Viewing Snapshot Records
Generally, backups (snapshots) made in organizations are kept in the same environment where indexing takes place. Later, these snapshots may be required to be stored in a different environment. In Elasticsearch, data is not automatically thrown into another Elasticsearch cluster just by file transfer. In addition to file transfer, the snapshot structure must also be moved in the same way. Moving only files can both break the structure within the snapshot and prevent the backup from being restored.When moving a snapshot to another cluster, the repository must be created first, then the snapshot.
When the snapshot operation is completed, the backed up indices are not deleted. If the delete phase is activated in the index’s ILM policy, it is deleted.
Instant Backup
Creating Snapshot Request
Restoring All/Part of Indices in Snapshot Request
Elasticsearch Snapshot Transfer and Restore Script
This script transfers snapshot files created at a specific address after the Snapshot policy is set up to the backup server, restores them there, and keeps them ready to read. There are certain requirements for the script to run:- Log and backup servers must be running on a Linux server that supports shell scripts.
- An Elasticsearch server running the same or supported version as the current Elasticsearch server must be running on the backup server.
- Communication must be possible between the log server and backup server through protocols such as ssh, scp.
- The log server must support crontab (available by default in many popular Linux distributions).
- Basic Linux shell knowledge
- Repository will be checked
- Snapshot file name and address will be obtained
- Snapshot file will be sent to restore server
- Snapshot restore operation will be started
- Restore operation status will be checked
How It Works:
- Save it as a file with a name like “ESMoveSnapshotAndRestore.sh” to an appropriate address on your Log server. The script can be copied through editors like vi, nano on Linux shell, or saved to a file from a Windows server and transferred via sftp using applications like winscp, mobaxterm.
-
Give permission to the file to run with the command
chmod +x ESMoveSnapshotAndRestore.sh. -
To avoid password prompts and enable automatic connection with scp, use scp’s ssh key authentication feature.
- Create a key on the log server with ssh-keygen. This key is sent to the backup server with the ssh-copy-id command.
-
If jq package is not available on the log server, install it. For Ubuntu use
apt install jq, for Redhat useyum install jqcommand. - Check the data.path and repo.path values in the config file for Elasticsearch on both servers.
-
Variables in the script are set according to your environments.
- ELASTICSEARCH_SERVER
- ELASTICSEARCH_BACKUP_SERVER
- LOG_KEY
- BACKUP_PATH_REPO
Usage:
Enter your own information into Elasticsearch variables before running the script.CronJob Usage:
- Open the cron scheduler by running the following command in the terminal;
- Add a line to the opened editor according to how frequently you want to run your script.
In both methods, when the script is run, the operations inside it will be written to a file named “logfile<DATE>.log” in the same folder as the script.

