MCPcopy Index your code
hub / github.com/dgraph-io/dgraph / Backup

Method Backup

dgraphapi/cluster.go:318–368  ·  view source on GitHub ↗

Backup creates a backup of dgraph at a given path

(c Cluster, forceFull bool, backupPath string)

Source from the content-addressed store, hash-verified

316
317// Backup creates a backup of dgraph at a given path
318func (hc *HTTPClient) Backup(c Cluster, forceFull bool, backupPath string) error {
319 repoDir, err := c.GetRepoDir()
320 if err != nil {
321 return errors.Wrapf(err, "error getting repo directory")
322 }
323
324 // backup API was made async in the commit d3bf7b7b2786bcb99f02e1641f3b656d0a98f7f4
325 asyncAPI, err := IsHigherVersion(c.GetVersion(), "d3bf7b7b2786bcb99f02e1641f3b656d0a98f7f4", repoDir)
326 if err != nil {
327 return errors.Wrapf(err, "error checking incremental restore support")
328 }
329
330 var taskPart string
331 if asyncAPI {
332 taskPart = "taskId"
333 }
334
335 const queryFmt = `mutation backup($dest: String!, $ff: Boolean!) {
336 backup(input: {destination: $dest, forceFull: $ff}) {
337 response {
338 code
339 }
340 %v
341 }
342 }`
343 params := GraphQLParams{
344 Query: fmt.Sprintf(queryFmt, taskPart),
345 Variables: map[string]interface{}{"dest": backupPath, "ff": forceFull},
346 }
347 resp, err := hc.RunGraphqlQuery(params, true)
348 if err != nil {
349 return err
350 }
351
352 var backupResp struct {
353 Backup struct {
354 Response struct {
355 Code string `json:"code,omitempty"`
356 } `json:"response,omitempty"`
357 TaskID string `json:"taskId,omitempty"`
358 } `json:"backup,omitempty"`
359 }
360 if err := json.Unmarshal(resp, &backupResp); err != nil {
361 return errors.Wrap(err, "error unmarshalling backup response")
362 }
363 if backupResp.Backup.Response.Code != "Success" {
364 return fmt.Errorf("backup failed")
365 }
366
367 return hc.WaitForTask(backupResp.Backup.TaskID)
368}
369
370// WaitForTask waits for the task to finish
371func (hc *HTTPClient) WaitForTask(taskId string) error {

Callers

nothing calls this directly

Calls 6

RunGraphqlQueryMethod · 0.95
WaitForTaskMethod · 0.95
IsHigherVersionFunction · 0.70
GetRepoDirMethod · 0.65
GetVersionMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected