Search code examples
elasticsearchelasticsearch-snapshot

How to delete a snapshot data in Elasticsearch?


When a repository is unregistered, Elasticsearch only removes the reference to the location where the repository is storing the snapshots. The snapshots themselves are left untouched and in place.

So Elasticsearch DELETE /_snapshot/my_backup won't delete the data itself.

I ls the backup directory and see these files, which files should I delete to delete snapshots? (suppose I can delete all snapshots)

-rw-rw-r--   1 mainserver mainserver  18K 12월 31 18:53 index-0
-rw-rw-r--   1 mainserver mainserver    8 12월 31 18:53 index.latest
drwxrwxr-x 185 mainserver mainserver  12K 12월 31 15:33 indices
-rw-rw-r--   1 mainserver mainserver  86K 12월 31 15:33 meta-NLs9MkZ2R9GYyNPViJzeDA.dat
-rw-rw-r--   1 mainserver mainserver 4.5K 12월 31 18:53 snap-NLs9MkZ2R9GYyNPViJzeDA.dat

Solution

  • Registering and unregistering a repository will not touch the individual snapshots in that repository. This is simply to make Elasticsearch aware of the repository that you then can use to create snapshots or restore from snapshots. Elasticsearch will know about the snapshots available in your repository (so it's never a good idea to manually fiddle around omg filesystem level for directories "managed" by Elasticsearch.

    When a repository is no longer needed, you should first unregister it and then you could wipe the whole directory.

    Elasticsearch's snapshot restore mechanism is creating incremental snapshots. The "unit" for incremental backups/snapshots is a Lucene segment. For efficiency purposes, subsequent snapshots simply point to segments already existing from an earlier snapshot, requiring only new segments to be copied into the repository.

    If you want to remove a particular snapshot from your repository, execute DELETE /_snapshot/<my_snapshot>. This will remove all Lucene segments that are longer referenced by any other snapshot. If your other snapshots are still using those segments, nothing will get removed from disk.