Skip to content

Commit

Permalink
Merge pull request #9447 from kobergj/ConsistencyFailFlag
Browse files Browse the repository at this point in the history
Add `--fail` flag to consistency command
  • Loading branch information
kobergj committed Jun 24, 2024
2 parents 20e3037 + aa9ea12 commit abcd6fc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/consistency-fail-flag.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: Add fail flag to consistency check

We added a `--fail` flag to the `ocis backup consistency` command. If set to true, the command will return a non-zero exit code if any inconsistencies are found. This allows you to use the command in scripts and CI/CD pipelines to ensure that backups are consistent.

https://github.com/owncloud/ocis/pull/9447
8 changes: 5 additions & 3 deletions ocis/pkg/backup/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func NewConsistency() *Consistency {
}

// CheckProviderConsistency checks the consistency of a space
func CheckProviderConsistency(storagepath string, lbs ListBlobstore) error {
func CheckProviderConsistency(storagepath string, lbs ListBlobstore, fail bool) error {
fsys := os.DirFS(storagepath)

p := NewProvider(fsys, storagepath, lbs)
Expand All @@ -71,7 +71,7 @@ func CheckProviderConsistency(storagepath string, lbs ListBlobstore) error {
c := NewConsistency()
c.GatherData(p.Events)

return c.PrintResults(storagepath)
return c.PrintResults(storagepath, fail)
}

// GatherData gathers and evaluates data produced by the DataProvider
Expand Down Expand Up @@ -134,7 +134,7 @@ func (c *Consistency) GatherData(events <-chan interface{}) {
}

// PrintResults prints the results of the evaluation
func (c *Consistency) PrintResults(discpath string) error {
func (c *Consistency) PrintResults(discpath string, fail bool) error {
if len(c.Nodes) != 0 {
fmt.Println("\n🚨 Inconsistent Nodes:")
}
Expand All @@ -161,6 +161,8 @@ func (c *Consistency) PrintResults(discpath string) error {
}
if len(c.Nodes) == 0 && len(c.LinkedNodes) == 0 && len(c.Blobs) == 0 && len(c.BlobReferences) == 0 {
fmt.Printf("💚 No inconsistency found. The backup in '%s' seems to be valid.\n", discpath)
} else if fail {
os.Exit(1)
}
return nil

Expand Down
6 changes: 5 additions & 1 deletion ocis/pkg/command/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ func ConsistencyCommand(cfg *config.Config) *cli.Command {
Usage: "the blobstore type. Can be (none, ocis, s3ng). Default ocis",
Value: "ocis",
},
&cli.BoolFlag{
Name: "fail",
Usage: "exit with non-zero status if consistency check fails",
},
},
Action: func(c *cli.Context) error {
basePath := c.String("basepath")
Expand Down Expand Up @@ -83,7 +87,7 @@ func ConsistencyCommand(cfg *config.Config) *cli.Command {
fmt.Println(err)
return err
}
if err := backup.CheckProviderConsistency(basePath, bs); err != nil {
if err := backup.CheckProviderConsistency(basePath, bs, c.Bool("fail")); err != nil {
fmt.Println(err)
return err
}
Expand Down

0 comments on commit abcd6fc

Please sign in to comment.