Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --fail flag to consistency command #9447

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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