# Removing multiple snapshots using the API

**URL:** <https://discuss.elastic.co/t/removing-multiple-snapshots-using-the-api/21738>\
**Category:** Elasticsearch\
**Created:** [January 20, 2015, 9:19pm UTC](https://discuss.elastic.co/t/removing-multiple-snapshots-using-the-api/21738 "2015-01-20T21:19:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![abutalib\_zaidi](https://avatars.discourse-cdn.com/v4/letter/a/bcef8e/32.png) [@abutalib\_zaidi](https://discuss.elastic.co/u/abutalib_zaidi)\
**Post date:** [January 20, 2015, 9:19pm UTC](https://discuss.elastic.co/t/removing-multiple-snapshots-using-the-api/21738/1 "2015-01-20T21:19:38Z")

</div>

I am fairly new to ElasticSearch and was trying to do some backup and  
restore using the API. I wrote a shell script to remove snapshots older  
than certain days but it somehow removes the repo instead of the snapshots  
info stored in a variable. Any help would be appreciated:

#Remove snapshots older than 7 days  
cd /snapshot/directory

OLD\_BACKUP=`find snapshot-* -mtime +7`

OLD\_SNAPSHOT=`for filename in ${OLD_BACKUP}; do [-f "$filename"] || continue mv $filename ${filename//snapshot-/} done`

curl -XDELETE "[xyz.com:9200/\_snapshot/handoff\_backup/${OLD\_SNAPSHOT}](http://xyz.com:9200/_snapshot/handoff_backup/%24%7BOLD_SNAPSHOT%7D)  
[http://argentina.pdi.com:9200/\_snapshot/handoff\_backup/${OLD\_SNAPSHOT}](http://argentina.pdi.com:9200/_snapshot/handoff_backup/%24%7BOLD_SNAPSHOT%7D)  
"

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/3dd2e3bd-8733-428a-a329-55b0bed8c266%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/3dd2e3bd-8733-428a-a329-55b0bed8c266%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![bplsilva](https://avatars.discourse-cdn.com/v4/letter/b/4af34b/32.png) [@bplsilva](https://discuss.elastic.co/u/bplsilva)\
**Post date:** [January 21, 2015, 7:00pm UTC](https://discuss.elastic.co/t/removing-multiple-snapshots-using-the-api/21738/2 "2015-01-21T19:00:10Z")

</div>

You could everything through the API.

- list all the snapshots in the repository
- parse the JSON returned
- for each snapshot, if it's older than 7 days, delete the snapshot

Le mardi 20 janvier 2015 19:19:38 UTC-2, abutalib zaidi a écrit :

> I am fairly new to Elasticsearch and was trying to do some backup and  
> restore using the API. I wrote a shell script to remove snapshots older  
> than certain days but it somehow removes the repo instead of the snapshots  
> info stored in a variable. Any help would be appreciated:
> 
> #Remove snapshots older than 7 days  
> cd /snapshot/directory
> 
> OLD\_BACKUP=`find snapshot-* -mtime +7 `
> 
> OLD\_SNAPSHOT=`for filename in ${OLD_BACKUP}; do [-f "$filename"] || continue mv $filename ${filename//snapshot-/} done `
> 
> curl -XDELETE "[xyz.com:9200/\_snapshot/handoff\_backup/${OLD\_SNAPSHOT}](http://xyz.com:9200/_snapshot/handoff_backup/$%7BOLD_SNAPSHOT%7D)  
> [http://argentina.pdi.com:9200/\_snapshot/handoff\_backup/${OLD\_SNAPSHOT}](http://argentina.pdi.com:9200/_snapshot/handoff_backup/$%7BOLD_SNAPSHOT%7D)  
> "

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/da6a210c-3949-4e0d-aaa5-4e05ebf14248%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/da6a210c-3949-4e0d-aaa5-4e05ebf14248%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 12:37am UTC](https://discuss.elastic.co/t/removing-multiple-snapshots-using-the-api/21738/3 "2017-07-06T00:37:29Z")

</div>


