49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
|
// Copyright (C) 2019 Storj Labs, Inc.
|
||
|
// See LICENSE for copying information.
|
||
|
|
||
|
package main
|
||
|
|
||
|
import (
|
||
|
"github.com/spf13/cobra"
|
||
|
"github.com/zeebo/errs"
|
||
|
"go.uber.org/zap"
|
||
|
|
||
|
"storj.io/storj/pkg/cfgstruct"
|
||
|
"storj.io/storj/pkg/process"
|
||
|
"storj.io/storj/satellite/metainfo"
|
||
|
)
|
||
|
|
||
|
var (
|
||
|
detectCmd = &cobra.Command{
|
||
|
Use: "detect",
|
||
|
Short: "Detects zombie segments in DB",
|
||
|
Args: cobra.OnlyValidArgs,
|
||
|
RunE: cmdDetect,
|
||
|
}
|
||
|
|
||
|
detectCfg struct {
|
||
|
DatabaseURL string `help:"the database connection string to use" default:"postgres://"`
|
||
|
From string `help:"begin of date range for detecting zombie segments" default:""`
|
||
|
To string `help:"end of date range for detecting zombie segments" default:""`
|
||
|
}
|
||
|
)
|
||
|
|
||
|
func init() {
|
||
|
rootCmd.AddCommand(detectCmd)
|
||
|
|
||
|
defaults := cfgstruct.DefaultsFlag(rootCmd)
|
||
|
process.Bind(detectCmd, &detectCfg, defaults)
|
||
|
}
|
||
|
|
||
|
func cmdDetect(cmd *cobra.Command, args []string) (err error) {
|
||
|
log := zap.L()
|
||
|
db, err := metainfo.NewStore(log.Named("pointerdb"), detectCfg.DatabaseURL)
|
||
|
if err != nil {
|
||
|
return errs.New("error connecting database: %+v", err)
|
||
|
}
|
||
|
defer func() {
|
||
|
err = errs.Combine(err, db.Close())
|
||
|
}()
|
||
|
return nil
|
||
|
}
|