Skip to main content
First, it should be clarified how the backup will be performed. Commonly used methods are:
  1. 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.
    CON Both active and backup disks will continue to grow continuously.
    CON When there is a problem with the main disk, a reinstallation will be required to access the data on the backup disk.
  2. 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.
    CON Both active and backup disks will continue to grow continuously.
  3. 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.
    CON Both active and backup disks will continue to grow continuously.
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.
CON To access historical data, an application will need to be installed on the backup disk or backups will need to be transferred to a specific server to work.
CON Only the backup disk will continue to grow continuously.

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.
If this information was added to the configuration file later, the node must be restarted.

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.
If automatic backup will be performed, SLM Policy commands should be executed. If backup will be taken at desired times, Instant Backup commands should be executed.

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

Multiple values can be entered in the indices section of the command, or the wildcard value * can also be used.

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
The steps to be applied in the script are as follows:
  1. Repository will be checked
  2. Snapshot file name and address will be obtained
  3. Snapshot file will be sent to restore server
  4. Snapshot restore operation will be started
  5. Restore operation status will be checked

How It Works:

  1. 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.
  2. Give permission to the file to run with the command chmod +x ESMoveSnapshotAndRestore.sh.
  3. 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.
  4. If jq package is not available on the log server, install it. For Ubuntu use apt install jq, for Redhat use yum install jq command.
  5. Check the data.path and repo.path values in the config file for Elasticsearch on both servers.
  6. 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.
This operation can be done manually or can be repeated at certain intervals. To repeat it, this record must be entered into Linux cronjob settings.

CronJob Usage:

  1. Open the cron scheduler by running the following command in the terminal;
  1. Add a line to the opened editor according to how frequently you want to run your script.
For example, to run it on the 3rd day of every month at 23:00, you can write as follows:
To save the line you added, press Esc and type :wq and press Enter.
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.