Restore performs restore on Dgraph cluster from the given path to backup
(c Cluster, backupPath string, backupId string, incrFrom, backupNum int)
| 411 | |
| 412 | // Restore performs restore on Dgraph cluster from the given path to backup |
| 413 | func (hc *HTTPClient) Restore(c Cluster, backupPath string, |
| 414 | backupId string, incrFrom, backupNum int) error { |
| 415 | repoDir, err := c.GetRepoDir() |
| 416 | if err != nil { |
| 417 | return errors.Wrapf(err, "error getting repo directory") |
| 418 | } |
| 419 | |
| 420 | // incremental restore was introduced in commit 8b3712e93ed2435bea52d957f7b69976c6cfc55b |
| 421 | incrRestoreSupported, err := IsHigherVersion(c.GetVersion(), "8b3712e93ed2435bea52d957f7b69976c6cfc55b", repoDir) |
| 422 | if err != nil { |
| 423 | return errors.Wrapf(err, "error checking incremental restore support") |
| 424 | } |
| 425 | if !incrRestoreSupported && incrFrom != 0 { |
| 426 | return errors.New("incremental restore is not supported by the cluster") |
| 427 | } |
| 428 | |
| 429 | encKey, err := c.GetEncKeyPath() |
| 430 | if err != nil { |
| 431 | return errors.Wrapf(err, "error getting encryption key path") |
| 432 | } |
| 433 | |
| 434 | var varPart, queryPart string |
| 435 | if incrRestoreSupported { |
| 436 | varPart = "$incrFrom: Int, " |
| 437 | queryPart = " incrementalFrom: $incrFrom," |
| 438 | } |
| 439 | query := fmt.Sprintf(`mutation restore($location: String!, $backupId: String, |
| 440 | %v$backupNum: Int, $encKey: String) { |
| 441 | restore(input: {location: $location, backupId: $backupId,%v |
| 442 | backupNum: $backupNum, encryptionKeyFile: $encKey}) { |
| 443 | code |
| 444 | message |
| 445 | } |
| 446 | }`, varPart, queryPart) |
| 447 | vars := map[string]interface{}{"location": backupPath, "backupId": backupId, |
| 448 | "backupNum": backupNum, "encKey": encKey} |
| 449 | if incrRestoreSupported { |
| 450 | vars["incrFrom"] = incrFrom |
| 451 | } |
| 452 | |
| 453 | params := GraphQLParams{ |
| 454 | Query: query, |
| 455 | Variables: vars, |
| 456 | } |
| 457 | resp, err := hc.RunGraphqlQuery(params, true) |
| 458 | if err != nil { |
| 459 | return err |
| 460 | } |
| 461 | |
| 462 | var restoreResp struct { |
| 463 | Restore struct { |
| 464 | Code string |
| 465 | Message string |
| 466 | } |
| 467 | } |
| 468 | if err := json.Unmarshal(resp, &restoreResp); err != nil { |
| 469 | return errors.Wrap(err, "error unmarshalling restore response") |
| 470 | } |
nothing calls this directly
no test coverage detected