Add -if-replica-exists flag to restore
This commit adds a flag to change the exit code when restoring from a replica where there is no existing backup. When set, finding no backup will return a `0` exit code. The command will still fail if other errors occur.
This commit is contained in:
@@ -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.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user