PMB can not connect to Mongodb

I am following the setup for PBM from here for percona-server-for-mongodb:

And here for PBM:

export PBM_MONGODB_URI=“mongodb://pbmuser:secretpwd@localhost:27018/?authSource=admin”

When trying pbm status or any backup commands with pbm agent, it emitted a connection error.
For example:
pbm status

Error: connect to mongodb: create mongo connection: mongo ping: server selection error: server selection timeout, current topology: { Type: ReplicaSetNoPrimary, Servers: [{ Addr: 049bba6c2cc3:27017, Type: Unknown, Last error: dial tcp: lookup 049bba6c2cc3: Temporary failure in name resolution }, ] }

I can connect to the primary mongo node normally with:
mongo mongodb://pbmuser:secretpwd@localhost:27018/?authSource=admin

To confirm it is a replicaSet:
rs:PRIMARY> db.isMaster().primary

Please anyone help advise how to check further why it could not connect.

hey @Me1

are you running pbm-agent on the host machine or in a container? if in a container, try to run pbm status in the same container.

hi @Dmytro_Zghoba,
I am using pbm-agent in the host machine and PSMD in a container. It looks like pbm does not work the same way with other applications, such as mongo shell, when connecting to a containerised mongo server instance.

My setup only currently is using 1 PSMD node which is also the primary node for replica set ‘rs’.

With this usage scenario, is there any additional mappings or configuration needed so that PBM can connect properly?

in this case, set hostname for each PSMDB container. on the host’s “/etc/hosts” add alias each hostnames to and flush the DNS cache

btw do you run sharded cluster?
I see 049bba6c2cc3:27017 instance but URI localhost:27018 (with default port to shardsvr)

No. I just made a test PCMDB node like this:
podman run --rm -d --name rs101 -p 27018:27017 percona/percona-server-mongodb:4.4 --port=27017 --replSet rs
And then initialise the replica set and made it as the primary node within the container. I am not sure how or why PBM working that way when it mentioned the host as the container ID and port within the error.
I am going to start the container again with the alias hostname as advised to see how it will work.

hi @Dmytro_Zghoba,
I re-create the PSMBD node again with -hostname and added this host to the host’s /etc/hosts. But it still can not connect.
$ podman run --rm -d --name rs101 -p 27018:27017 --hostname=psmongo1 percona/percona-server-mongodb:4.4 --port=27017 --replSet rs

$ podman ps

07f7e9841c40 --port=27017 --re… 39 minutes ago Up 39 minutes>27017/tcp rs101

$ ping psmongo1
PING psmongo1 ( 56(84) bytes of data.
64 bytes from psmongo1 ( icmp_seq=1 ttl=64 time=0.008 ms
64 bytes from psmongo1 ( icmp_seq=2 ttl=64 time=0.013 ms

$ export PBM_MONGODB_URI=“mongodb://pbmuser:secretpwd@psmongo1:27018/?authSource=admin&replSet=rs”

$ pbm status
Error: connect to mongodb: create mongo connection: mongo ping: server selection error: server selection timeout, current topology: { Type: ReplicaSetNoPrimary, Servers: [ ] }

May be PBM does not support containers started by PodMan?
rs101_inspect.txt (12.3 KB)
rs.status.txt (2.8 KB)

PBM usually runs on the same host as mongod or on the same container, or in a sidecar (but with the same linux namespaces).

The error comes from the mongo driver. PBM should have the same hostname and port in the connection string as the replset deployed.
In short, psmongo1:27018 won’t work because MongoDB identifies itself as psmongo1:27017.

Thanks @Dmytro_Zghoba. Now that I am trying pbm with the local mongod instance. My storage config using the local filesystem storage (for testing):
type: filesystem
path: /home/user/local_backups

The permission on the folder:
drwxrwxr-x 2 user user 4096 Jun 9 12:50 /home/user/local_backups

But then running pbm status there is an error:

ERROR with storage: storage: no init file, attempt to create failed: create destination file </home/user/local_backups/.pbm.init>: open /home/user/local_backups/.pbm.init: permission denied

In this case, which permissions are set for the folder so pbm can write to?


Hi @Me1 ,

The above issue is related to ownership of storage path.

  1. Start the pbm-agent as the mongod user.
  2. Give mongod ownership to the storage path as well.