Tutorial: Snapshot and Restore

edit

Ready to try Snapshot and Restore? In this tutorial, you’ll learn to:

  • Register a repository
  • Add snapshots to the repository
  • Create a snapshot lifecycle policy
  • Restore a snapshot

Before you begin

edit

This example shows you how to register a shared file system repository and store snapshots. Before you begin, you must register the location of the repository in the path.repo setting on your master and data nodes. You can do this in one of two ways:

  • Edit your elasticsearch.yml to include the path.repo setting.
  • Pass the path.repo setting when you start Elasticsearch.

    bin/elasticsearch -E path.repo=/tmp/es-backups

Register a repository

edit

Use Snapshot and Restore to register the repository where your snapshots will live.

  1. Open the main menu, then click Stack Management > Snapshot and Restore.
  2. Click Register a repository in either the introductory message or Repository view.
  3. Enter a name for your repository, for example, my_backup.
  4. Select Shared file system.

    Register repository

  5. Click Next.
  6. In File system location, enter the path to the snapshot repository, /tmp/es-backups.
  7. In Chunk size, enter 100mb so that snapshot files are not bigger than that size.
  8. Use the defaults for all other fields, and then click Register.

    Your new repository is listed on the Repositories view. The repository currently doesn’t have any snapshots.

Add a snapshot to the repository

edit

Use the snapshot API to create a snapshot.

  1. Open the main menu, click Dev Tools, then select Console.
  2. Create the snapshot:

    PUT /_snapshot/my_backup/2019-04-25_snapshot?wait_for_completion=true

    In this example, the snapshot name is 2019-04-25_snapshot. You can also use date math expression for the snapshot name.

    Create snapshot

  3. Return to Snapshot and Restore.

    Your new snapshot is available in the Snapshots view.

Create a snapshot lifecycle policy

edit

Now you’ll automate the creation and deletion of snapshots using the repository created in the previous example.

  1. Open the Policies view.
  2. Click Create a policy.

    Create policy wizard

  3. As you walk through the wizard, enter the following values:

    Logistics

    Policy name

    daily-snapshots

    Snapshot name

    <daily-snap-{now/d}>

    Schedule

    Every day at 1:30 a.m.

    Repository

    my_backup

    Snapshot settings

    Indices

    Select the indices to back up. By default, all indices, including system indices, are backed up.

    All other settings

    Use the defaults.

    Snapshot retention

    Expiration

    30 days

    Snapshots to retain

    Minimum count: 5, Maximum count: 50

  4. Review your input, and then click Create policy.

    Your new policy is listed in the Policies view, and you see a summary of its details.

Restore a snapshot

edit

Finally, you’ll restore indices from an existing snapshot.

  1. In the Snapshots view, find the snapshot you want to restore, for example 2019-04-25_snapshot.
  2. Click the restore icon in the Actions column.
  3. As you walk through the wizard, enter the following values:

    Logistics

    Indices

    Toggle to choose specific indices to restore, or leave in place to restore all indices.

    Rename indices

    Toggle to give your restored indices new names, or leave in place to restore under original index names.

    All other fields

    Use the defaults.

    Index settings

    Modify index settings

    Toggle to overwrite index settings when they are restored, or leave in place to keep existing settings.

    Reset index settings

    Toggle to reset index settings back to the default when they are restored, or leave in place to keep existing settings.

  4. Review your restore settings, and then click Restore snapshot.

    The operation loads for a few seconds, and then you’re navigated to Restore Status, where you can monitor the status of your restored indices.