diff --git a/agent/agent.go b/agent/agent.go index a68017780..0a68cb7bc 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -68,7 +68,12 @@ func (a *Agent) CanStart() error { return errors.New("mongos is not supported") } - return nil + ver, err := pbm.GetMongoVersion(context.Background(), a.pbm.Conn) + if err != nil { + return errors.WithMessage(err, "get mongo version") + } + + return pbm.FeatureSupport(ver).PBMSupport() } // Start starts listening the commands stream. diff --git a/cli/cli.go b/cli/cli.go index b104b414e..8b1fe760a 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -5,6 +5,7 @@ import ( "context" "encoding/json" "fmt" + stdlog "log" "os" "strings" "time" @@ -352,6 +353,14 @@ func Main() { exitErr(errors.Wrap(err, "connect to mongodb"), pbmOutF) } pbmClient.InitLogger("", "") + + ver, err := pbm.GetMongoVersion(ctx, pbmClient.Conn) + if err != nil { + stdlog.Fatalf("get mongo version: %v", err) + } + if err := pbm.FeatureSupport(ver).PBMSupport(); err != nil { + stdlog.Fatal(err.Error()) + } } switch cmd { diff --git a/pbm/version.go b/pbm/version.go index fac1d5fa8..e80d5a8e0 100644 --- a/pbm/version.go +++ b/pbm/version.go @@ -47,6 +47,20 @@ func GetMongoVersion(ctx context.Context, m *mongo.Client) (MongoVersion, error) type FeatureSupport MongoVersion +func (f FeatureSupport) PBMSupport() error { + v := MongoVersion(f) + + if v.Version[0] == 4 && v.Version[1] == 4 { + return nil + } + + if (v.Version[0] == 5 || v.Version[0] == 6) && v.Version[1] == 0 { + return nil + } + + return errors.New("Unsupported MongoDB version. PBM works with v4.4, v5.0, v6.0") +} + func (f FeatureSupport) FullPhysicalBackup() bool { // PSMDB 4.2.15, 4.4.6 v := MongoVersion(f)