Merge pull request #131 from benbjohnson/if-replica-exists

Add `-if-replica-exists` flag to restore
This commit is contained in:
Ben Johnson
2021-03-21 08:09:57 -06:00
committed by GitHub

View File

@@ -27,6 +27,7 @@ func (c *RestoreCommand) Run(ctx context.Context, args []string) (err error) {
fs.StringVar(&opt.Generation, "generation", "", "generation name") fs.StringVar(&opt.Generation, "generation", "", "generation name")
fs.IntVar(&opt.Index, "index", opt.Index, "wal index") fs.IntVar(&opt.Index, "index", opt.Index, "wal index")
fs.BoolVar(&opt.DryRun, "dry-run", false, "dry run") fs.BoolVar(&opt.DryRun, "dry-run", false, "dry run")
ifReplicaExists := fs.Bool("if-replica-exists", false, "")
timestampStr := fs.String("timestamp", "", "timestamp") timestampStr := fs.String("timestamp", "", "timestamp")
verbose := fs.Bool("v", false, "verbose output") verbose := fs.Bool("v", false, "verbose output")
fs.Usage = c.Usage fs.Usage = c.Usage
@@ -74,7 +75,12 @@ func (c *RestoreCommand) Run(ctx context.Context, args []string) (err error) {
} }
// Return an error if no matching targets found. // Return an error if no matching targets found.
// If optional flag set, return success. Useful for automated recovery.
if opt.Generation == "" { if opt.Generation == "" {
if *ifReplicaExists {
fmt.Println("no matching backups found")
return nil
}
return fmt.Errorf("no matching backups found") return fmt.Errorf("no matching backups found")
} }
@@ -168,6 +174,9 @@ Arguments:
Prints all log output as if it were running but does Prints all log output as if it were running but does
not perform actual restore. not perform actual restore.
-if-replica-exists
Returns exit code of 0 if no backups found.
-v -v
Verbose output. Verbose output.