Skip to content

Commit

Permalink
Force users to explicitly tell restore command to run without zero. (#…
Browse files Browse the repository at this point in the history
…5206)

The zero value passed to the command is optional, which can lead to
users forgetting about it and being surprised that the cluster does
not work (because the uid lease and the timestamp need to be updated
first).

This change makes the option not optional, unless the --force_zero
flag is set to false . Not passing a zero value can still be useful when only
the p directories need to be generated.
  • Loading branch information
martinmr committed Apr 14, 2020
1 parent e6d0936 commit 568a0e8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
12 changes: 10 additions & 2 deletions ee/backup/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var LsBackup x.SubCommand

var opt struct {
backupId, location, pdir, zero, keyfile string
forceZero bool
}

func init() {
Expand Down Expand Up @@ -106,6 +107,10 @@ $ dgraph restore -p . -l /var/backups/dgraph -z localhost:5080
"restore. If empty, it will restore the latest series.")
flag.StringVarP(&opt.keyfile, "keyfile", "k", "", "Key file to decrypt the backup. "+
"The same key is also used to re-encrypt the restored data.")
flag.BoolVarP(&opt.forceZero, "force_zero", "", true, "If false, no connection to "+
"a zero in the cluster will be required. Keep in mind this requires you to manually "+
"update the timestamp and max uid when you start the cluster. The correct values are "+
"printed near the end of this command's output.")
_ = Restore.Cmd.MarkFlagRequired("postings")
_ = Restore.Cmd.MarkFlagRequired("location")
}
Expand Down Expand Up @@ -168,8 +173,11 @@ func runRestoreCmd() error {
fmt.Println("Restoring backups from:", opt.location)
fmt.Println("Writing postings to:", opt.pdir)

// TODO: Remove this dependency on Zero. It complicates restore for the end
// user.
if opt.zero == "" && opt.forceZero {
return errors.Errorf("No Dgraph Zero address passed. Use the --force_zero option if you " +
"meant to do this")
}

if opt.zero != "" {
fmt.Println("Updating Zero timestamp at:", opt.zero)

Expand Down
2 changes: 1 addition & 1 deletion ee/backup/tests/encryption/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func runRestore(t *testing.T, lastDir string, commitTs uint64) map[string]string
t.Logf("--- Restoring from: %q", localBackupDst)
testutil.KeyFile = "../../../enc/enc-key"
argv := []string{"dgraph", "restore", "-l", localBackupDst, "-p", "data/restore",
"-k", testutil.KeyFile}
"-k", testutil.KeyFile, "--force_zero=false"}
cwd, err := os.Getwd()
require.NoError(t, err)
err = testutil.ExecWithOpts(argv, testutil.CmdOpts{Dir: cwd})
Expand Down
3 changes: 2 additions & 1 deletion ee/backup/tests/minio/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,8 @@ func runRestore(t *testing.T, lastDir string, commitTs uint64) map[string]string
require.NoError(t, os.RemoveAll(restoreDir))

t.Logf("--- Restoring from: %q", localBackupDst)
argv := []string{"dgraph", "restore", "-l", localBackupDst, "-p", "data/restore"}
argv := []string{"dgraph", "restore", "-l", localBackupDst, "-p", "data/restore",
"--force_zero=false"}
cwd, err := os.Getwd()
require.NoError(t, err)
err = testutil.ExecWithOpts(argv, testutil.CmdOpts{Dir: cwd})
Expand Down
9 changes: 6 additions & 3 deletions wiki/content/enterprise-features/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,12 @@ The `--postings` (`-p`) flag sets the directory to which the restored posting
directories will be saved. This directory will contain a posting directory for
each group in the restored backup.

The `--zero` (`-z`) optional flag specifies a Dgraph Zero address to update the
start timestamp using the restored version. Otherwise, the timestamp must be
manually updated through Zero's HTTP 'assign' endpoint.
The `--zero` (`-z`) flag specifies a Dgraph Zero address to update the start
timestamp and UID lease using the restored version. If no zero address is
passed, the command will complain unless you set the value of the
`--force_zero` flag to false. If do not pass a zero value to this command,
the timestamp and UID lease must be manually updated through Zero's HTTP
'assign' endpoint using the values printed near the end of the command's output.

The `--backup_id` optional flag specifies the ID of the backup series to
restore. A backup series consists of a full backup and all the incremental
Expand Down

0 comments on commit 568a0e8

Please sign in to comment.