Skip to content

Commit 9af71df

Browse files
Merge #560
560: Add method to create snapshot r=curquiza a=Ja7ad # Pull Request ## Related issue Fixes #501 ## What does this PR do? - Add a new method for creating snapshots ## PR checklist Please check if your PR fulfills the following requirements: - [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? - [x] Have you read the contributing guidelines? - [x] Have you made sure that the title is accurate and descriptive of the changes? Thank you so much for contributing to Meilisearch! Co-authored-by: Javad <[email protected]>
2 parents ad4b0b2 + fe05f78 commit 9af71df

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

.code-samples.meilisearch.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# the documentation on build
44
# You can read more on https://github.com/meilisearch/documentation/tree/master/.vuepress/code-samples
55
---
6+
create_snapshot_1: |-
7+
client.CreateSnapshot()
68
get_one_index_1: |-
79
client.GetIndex("movies")
810
list_all_indexes_1: |-

meilisearch.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@ type ServiceManager interface {
155155
// IsHealthy checks if the Meilisearch server is healthy.
156156
IsHealthy() bool
157157

158+
// CreateSnapshot create database snapshot from meilisearch
159+
CreateSnapshot() (*TaskInfo, error)
160+
161+
// CreateSnapshotWithContext create database snapshot from meilisearch and support parent context
162+
CreateSnapshotWithContext(ctx context.Context) (*TaskInfo, error)
163+
158164
// Close closes the connection to the Meilisearch server.
159165
Close()
160166
}
@@ -726,6 +732,28 @@ func (m *meilisearch) HealthWithContext(ctx context.Context) (*Health, error) {
726732
return resp, nil
727733
}
728734

735+
func (m *meilisearch) CreateSnapshot() (*TaskInfo, error) {
736+
return m.CreateSnapshotWithContext(context.Background())
737+
}
738+
739+
func (m *meilisearch) CreateSnapshotWithContext(ctx context.Context) (*TaskInfo, error) {
740+
resp := new(TaskInfo)
741+
req := &internalRequest{
742+
endpoint: "/snapshots",
743+
method: http.MethodPost,
744+
withRequest: nil,
745+
withResponse: resp,
746+
acceptedStatusCodes: []int{http.StatusAccepted},
747+
contentType: contentTypeJSON,
748+
functionName: "CreateSnapshot",
749+
}
750+
751+
if err := m.client.executeRequest(ctx, req); err != nil {
752+
return nil, err
753+
}
754+
return resp, nil
755+
}
756+
729757
func (m *meilisearch) IsHealthy() bool {
730758
res, err := m.HealthWithContext(context.Background())
731759
return err == nil && res.Status == "available"

meilisearch_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2109,3 +2109,10 @@ func TestClient_MultiSearch(t *testing.T) {
21092109
})
21102110
}
21112111
}
2112+
2113+
func Test_CreateSnapshot(t *testing.T) {
2114+
c := setup(t, "")
2115+
task, err := c.CreateSnapshot()
2116+
require.NoError(t, err)
2117+
testWaitForTask(t, c.Index("indexUID"), task)
2118+
}

0 commit comments

Comments
 (0)