From ef2adf6c83cc0e0ce5c3a7860a66289bb9e52169 Mon Sep 17 00:00:00 2001 From: Martin Martinez Rivera Date: Tue, 14 Apr 2020 16:23:58 -0700 Subject: [PATCH] Force users to explicitly tell restore command to run without zero. (#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. --- ee/backup/run.go | 12 ++++++++++-- systest/backup/encryption/backup_test.go | 2 +- systest/backup/minio/backup_test.go | 3 ++- wiki/content/enterprise-features/index.md | 9 ++++++--- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/ee/backup/run.go b/ee/backup/run.go index 27493fc7321..d2f3fbf7eee 100644 --- a/ee/backup/run.go +++ b/ee/backup/run.go @@ -34,6 +34,7 @@ var LsBackup x.SubCommand var opt struct { backupId, location, pdir, zero, keyfile string + forceZero bool } func init() { @@ -107,6 +108,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") } @@ -169,8 +174,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) diff --git a/systest/backup/encryption/backup_test.go b/systest/backup/encryption/backup_test.go index e628762b719..9c4f9f2b277 100644 --- a/systest/backup/encryption/backup_test.go +++ b/systest/backup/encryption/backup_test.go @@ -273,7 +273,7 @@ func runRestore(t *testing.T, lastDir string, commitTs uint64) map[string]string t.Logf("--- Restoring from: %q", localBackupDst) testutil.KeyFile = "../../../ee/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}) diff --git a/systest/backup/minio/backup_test.go b/systest/backup/minio/backup_test.go index 5b8f99e011a..7a3ee55b443 100644 --- a/systest/backup/minio/backup_test.go +++ b/systest/backup/minio/backup_test.go @@ -295,7 +295,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}) diff --git a/wiki/content/enterprise-features/index.md b/wiki/content/enterprise-features/index.md index 5ac0ba2e377..92fc57e3375 100644 --- a/wiki/content/enterprise-features/index.md +++ b/wiki/content/enterprise-features/index.md @@ -181,9 +181,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