Skip to content

Commit 898ecd1

Browse files
authored
Make backup-restore an open source feature (#8067)
Open-source the backup and restore feature.
1 parent 3592353 commit 898ecd1

File tree

16 files changed

+985
-1091
lines changed

16 files changed

+985
-1091
lines changed

ee/backup/run.go renamed to backup/run.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
// +build !oss
2-
31
/*
4-
* Copyright 2018 Dgraph Labs, Inc. and Contributors
2+
* Copyright 2021 Dgraph Labs, Inc. and Contributors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
57
*
6-
* Licensed under the Dgraph Community License (the "License"); you
7-
* may not use this file except in compliance with the License. You
8-
* may obtain a copy of the License at
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
10-
* https://github.com/dgraph-io/dgraph/blob/master/licenses/DCL.txt
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
1115
*/
1216

1317
package backup

dgraph/cmd/root.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"strings"
3030
"unicode"
3131

32+
"github.com/dgraph-io/dgraph/backup"
3233
"github.com/dgraph-io/dgraph/dgraph/cmd/alpha"
3334
"github.com/dgraph-io/dgraph/dgraph/cmd/bulk"
3435
"github.com/dgraph-io/dgraph/dgraph/cmd/cert"
@@ -41,6 +42,7 @@ import (
4142
"github.com/dgraph-io/dgraph/dgraph/cmd/migrate"
4243
"github.com/dgraph-io/dgraph/dgraph/cmd/version"
4344
"github.com/dgraph-io/dgraph/dgraph/cmd/zero"
45+
"github.com/dgraph-io/dgraph/updatemanifest"
4446
"github.com/dgraph-io/dgraph/upgrade"
4547
"github.com/dgraph-io/dgraph/x"
4648

@@ -83,9 +85,10 @@ var rootConf = viper.New()
8385

8486
// subcommands initially contains all default sub-commands.
8587
var subcommands = []*x.SubCommand{
86-
&bulk.Bulk, &cert.Cert, &conv.Conv, &live.Live, &alpha.Alpha, &zero.Zero, &version.Version,
87-
&debug.Debug, &migrate.Migrate, &debuginfo.DebugInfo, &upgrade.Upgrade, &decrypt.Decrypt,
88-
&increment.Increment,
88+
&bulk.Bulk, &backup.LsBackup, &backup.ExportBackup, &cert.Cert, &conv.Conv, &live.Live,
89+
&alpha.Alpha, &zero.Zero, &version.Version, &debug.Debug, &migrate.Migrate,
90+
&debuginfo.DebugInfo, &upgrade.Upgrade, &decrypt.Decrypt, &increment.Increment,
91+
&updatemanifest.UpdateManifest,
8992
}
9093

9194
func initCmds() {

dgraph/cmd/root_ee.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,12 @@ package cmd
1515
import (
1616
acl "github.com/dgraph-io/dgraph/ee/acl"
1717
"github.com/dgraph-io/dgraph/ee/audit"
18-
"github.com/dgraph-io/dgraph/ee/backup"
19-
"github.com/dgraph-io/dgraph/ee/updatemanifest"
2018
)
2119

2220
func init() {
2321
// subcommands already has the default subcommands, we append to EE ones to that.
2422
subcommands = append(subcommands,
25-
&backup.LsBackup,
26-
&backup.ExportBackup,
2723
&acl.CmdAcl,
2824
&audit.CmdAudit,
29-
&updatemanifest.UpdateManifest,
3025
)
3126
}

graphql/admin/admin.go

Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,224 @@ const (
412412
response: AssignedIds
413413
}
414414
415+
input BackupInput {
416+
417+
"""
418+
Destination for the backup: e.g. Minio or S3 bucket.
419+
"""
420+
destination: String!
421+
422+
"""
423+
Access key credential for the destination.
424+
"""
425+
accessKey: String
426+
427+
"""
428+
Secret key credential for the destination.
429+
"""
430+
secretKey: String
431+
432+
"""
433+
AWS session token, if required.
434+
"""
435+
sessionToken: String
436+
437+
"""
438+
Set to true to allow backing up to S3 or Minio bucket that requires no credentials.
439+
"""
440+
anonymous: Boolean
441+
442+
"""
443+
Force a full backup instead of an incremental backup.
444+
"""
445+
forceFull: Boolean
446+
}
447+
448+
type BackupPayload {
449+
response: Response
450+
taskId: String
451+
}
452+
453+
input RestoreInput {
454+
455+
"""
456+
Destination for the backup: e.g. Minio or S3 bucket.
457+
"""
458+
location: String!
459+
460+
"""
461+
Backup ID of the backup series to restore. This ID is included in the manifest.json file.
462+
If missing, it defaults to the latest series.
463+
"""
464+
backupId: String
465+
466+
"""
467+
Number of the backup within the backup series to be restored. Backups with a greater value
468+
will be ignored. If the value is zero or missing, the entire series will be restored.
469+
"""
470+
backupNum: Int
471+
472+
"""
473+
All the backups with num >= incrementalFrom will be restored.
474+
"""
475+
incrementalFrom: Int
476+
477+
"""
478+
If isPartial is set to true then the cluster will be kept in draining mode after
479+
restore. This makes sure that the db is not corrupted by any mutations or tablet moves in
480+
between two restores.
481+
"""
482+
isPartial: Boolean
483+
484+
"""
485+
Path to the key file needed to decrypt the backup. This file should be accessible
486+
by all alphas in the group. The backup will be written using the encryption key
487+
with which the cluster was started, which might be different than this key.
488+
"""
489+
encryptionKeyFile: String
490+
491+
"""
492+
Vault server address where the key is stored. This server must be accessible
493+
by all alphas in the group. Default "http://localhost:8200".
494+
"""
495+
vaultAddr: String
496+
497+
"""
498+
Path to the Vault RoleID file.
499+
"""
500+
vaultRoleIDFile: String
501+
502+
"""
503+
Path to the Vault SecretID file.
504+
"""
505+
vaultSecretIDFile: String
506+
507+
"""
508+
Vault kv store path where the key lives. Default "secret/data/dgraph".
509+
"""
510+
vaultPath: String
511+
512+
"""
513+
Vault kv store field whose value is the key. Default "enc_key".
514+
"""
515+
vaultField: String
516+
517+
"""
518+
Vault kv store field's format. Must be "base64" or "raw". Default "base64".
519+
"""
520+
vaultFormat: String
521+
522+
"""
523+
Access key credential for the destination.
524+
"""
525+
accessKey: String
526+
527+
"""
528+
Secret key credential for the destination.
529+
"""
530+
secretKey: String
531+
532+
"""
533+
AWS session token, if required.
534+
"""
535+
sessionToken: String
536+
537+
"""
538+
Set to true to allow backing up to S3 or Minio bucket that requires no credentials.
539+
"""
540+
anonymous: Boolean
541+
}
542+
543+
type RestorePayload {
544+
"""
545+
A short string indicating whether the restore operation was successfully scheduled.
546+
"""
547+
code: String
548+
549+
"""
550+
Includes the error message if the operation failed.
551+
"""
552+
message: String
553+
}
554+
555+
input ListBackupsInput {
556+
"""
557+
Destination for the backup: e.g. Minio or S3 bucket.
558+
"""
559+
location: String!
560+
561+
"""
562+
Access key credential for the destination.
563+
"""
564+
accessKey: String
565+
566+
"""
567+
Secret key credential for the destination.
568+
"""
569+
secretKey: String
570+
571+
"""
572+
AWS session token, if required.
573+
"""
574+
sessionToken: String
575+
576+
"""
577+
Whether the destination doesn't require credentials (e.g. S3 public bucket).
578+
"""
579+
anonymous: Boolean
580+
581+
}
582+
583+
type BackupGroup {
584+
"""
585+
The ID of the cluster group.
586+
"""
587+
groupId: UInt64
588+
589+
"""
590+
List of predicates assigned to the group.
591+
"""
592+
predicates: [String]
593+
}
594+
595+
type Manifest {
596+
"""
597+
Unique ID for the backup series.
598+
"""
599+
backupId: String
600+
601+
"""
602+
Number of this backup within the backup series. The full backup always has a value of one.
603+
"""
604+
backupNum: UInt64
605+
606+
"""
607+
Whether this backup was encrypted.
608+
"""
609+
encrypted: Boolean
610+
611+
"""
612+
List of groups and the predicates they store in this backup.
613+
"""
614+
groups: [BackupGroup]
615+
616+
"""
617+
Path to the manifest file.
618+
"""
619+
path: String
620+
621+
"""
622+
The timestamp at which this backup was taken. The next incremental backup will
623+
start from this timestamp.
624+
"""
625+
since: UInt64
626+
627+
"""
628+
The type of backup, either full or incremental.
629+
"""
630+
type: String
631+
}
632+
415633
` + adminTypes + `
416634
417635
type Query {
@@ -421,6 +639,10 @@ const (
421639
state: MembershipState
422640
config: Config
423641
task(input: TaskInput!): TaskPayload
642+
"""
643+
Get the information about the backups at a given location.
644+
"""
645+
listBackups(input: ListBackupsInput!) : [Manifest]
424646
` + adminQueries + `
425647
}
426648
@@ -474,6 +696,16 @@ const (
474696
"""
475697
assign(input: AssignInput!): AssignPayload
476698
699+
"""
700+
Start a binary backup.
701+
"""
702+
backup(input: BackupInput!) : BackupPayload
703+
704+
"""
705+
Start restoring a binary backup.
706+
"""
707+
restore(input: RestoreInput!) : RestorePayload
708+
477709
` + adminMutations + `
478710
}
479711
`

graphql/admin/backup.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,7 @@ type backupInput struct {
3434
}
3535

3636
func resolveBackup(ctx context.Context, m schema.Mutation) (*resolve.Resolved, bool) {
37-
glog.Info("Got backup request")
38-
if !worker.EnterpriseEnabled() {
39-
err := fmt.Errorf("you must enable enterprise features first. " +
40-
"Supply the appropriate license file to Dgraph Zero using the HTTP endpoint.")
41-
return resolve.EmptyResult(m, err), false
42-
}
37+
glog.Info("Got a backup request")
4338

4439
input, err := getBackupInput(m)
4540
if err != nil {

0 commit comments

Comments
 (0)