From eb64079846b888e991940f69b5df6904722ff988 Mon Sep 17 00:00:00 2001 From: Fernando Alvarez Date: Fri, 1 Jul 2016 18:10:53 +0200 Subject: [PATCH 1/2] Implement DeleteSnapshot and DeleteSnapshotRepository --- lib/snapshot.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/lib/snapshot.go b/lib/snapshot.go index 5b106d19..6d1dbcca 100644 --- a/lib/snapshot.go +++ b/lib/snapshot.go @@ -118,3 +118,47 @@ func (c *Conn) getSnapshots(repository, name string, args map[string]interface{} return retval, nil } + +// DeleteSnapshotRepository deletes a snapshot repository. When a repository is deleted, Elasticsearch +// only removes the reference to the location where the repository is storing the snapshots. +// The snapshots themselves are left untouched and in place. +// http://www.elastic.co/guide/en/elasticsearch/reference/1.3/modules-snapshots.html +func (c *Conn) DeleteSnapshotRepository(repository string) (BaseResponse, error) { + var url string + var retval BaseResponse + url = fmt.Sprintf("/_snapshot/%s", repository) + body, err := c.DoCommand("DELETE", url, nil, nil) + if err != nil { + return retval, err + } + if err == nil { + jsonErr := json.Unmarshal(body, &retval) + if jsonErr != nil { + return retval, jsonErr + } + } + + return retval, nil +} + +// DeleteSnapshot deletes a snapshot from a repository. Elasticsearch deletes all files that are +// associated with the deleted snapshot and not used by any other snapshots. +// http://www.elastic.co/guide/en/elasticsearch/reference/1.3/modules-snapshots.html +func (c *Conn) DeleteSnapshot(repository, name string) (BaseResponse, error) { + var url string + var retval BaseResponse + url = fmt.Sprintf("/_snapshot/%s/%s", repository, name) + body, err := c.DoCommand("DELETE", url, nil, nil) + if err != nil { + return retval, err + } + if err == nil { + fmt.Println(string(body)) + jsonErr := json.Unmarshal(body, &retval) + if jsonErr != nil { + return retval, jsonErr + } + } + + return retval, nil +} From 2f9d593fb3792c4b6e3328f469ebb0df62ac1ce2 Mon Sep 17 00:00:00 2001 From: Fernando Alvarez Date: Mon, 4 Jul 2016 11:37:11 +0200 Subject: [PATCH 2/2] Do not print body on DeleteSnapshot --- lib/snapshot.go | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/snapshot.go b/lib/snapshot.go index 6d1dbcca..52552ee7 100644 --- a/lib/snapshot.go +++ b/lib/snapshot.go @@ -153,7 +153,6 @@ func (c *Conn) DeleteSnapshot(repository, name string) (BaseResponse, error) { return retval, err } if err == nil { - fmt.Println(string(body)) jsonErr := json.Unmarshal(body, &retval) if jsonErr != nil { return retval, jsonErr