# Server Selection Error timeout

**URL:** <https://forums.percona.com/t/server-selection-error-timeout/24127>\
**Category:** Percona Backup for MongoDB\
**Created:** [August 2, 2023, 8:50am UTC](https://forums.percona.com/t/server-selection-error-timeout/24127 "2023-08-02T08:50:44Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pjotz](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/pjotz/32/12032_2.png) [@Pjotz](https://forums.percona.com/u/Pjotz)\
**Post date:** [August 2, 2023, 8:50am UTC](https://forums.percona.com/t/server-selection-error-timeout/24127/1 "2023-08-02T08:50:44Z")

</div>

Hi,  
Im trying to setup Percona backup for Mongodb, and its not as easy as i thought.

The setup is quite simple

1x mongodb docker container  
1x percona backup for mongodb container

Mongodb server is running, and is working, started pbm container with: docker run --name percona\_backup\_master -e PBM\_MONGODB\_URI=“mongodb://172.25.0.7:27017” --network trax\_repox\_mongo\_net -d percona/percona-backup-mongodb:latest’

after 20-30 sec the container exits with the logs entries below:

```auto
user@perconatest:/tmp$ docker logs -f percona_backup_master
+ '[' pbm-agent = pbm-agent ']'
++ mktemp
+ OUT=/tmp/tmp.uWEMOOzj6p
++ mktemp
+ OUT_CFG=/tmp/tmp.FwoQ7lhGzc
+ timeout=5
+ for i in {1..10}
+ '[' '' ']'
+ set +o xtrace
1
+ exit_status=0
++ grep -E '^([0-9]+)$' /tmp/tmp.uWEMOOzj6p
+ rs_size=1
+ [[0 == 0]]
+ [[1 -ge 1]]
+ break
+ rm /tmp/tmp.uWEMOOzj6p
+ exec pbm-agent
2023/08/02 08:40:36 Exit: connect to PBM: create mongo connection: mongo ping: server selection error: server selection timeout, current topology: { Type: ReplicaSetNoPrimary, Servers: [{ Addr: 127.0.0.1:27017, Type: Unknown, Last error: dial tcp 127.0.0.1:27017: connect: connection refused },] }

```

What i dont get, is why its trying to connect to 127.0.0.1? and not the mongodb://172.25.0.7:27017?

Please help, i´m pretty stuck here, and have to get this working on a sharded cluster, if this POC is working 🙂

/Morten

---

<div class="post-metadata">

**Author:** ![Corrado\_Pandiani](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/corrado_pandiani/32/1459_2.png) [@Corrado\_Pandiani](https://forums.percona.com/u/Corrado_Pandiani)\
**Post date:** [August 2, 2023, 9:55am UTC](https://forums.percona.com/t/server-selection-error-timeout/24127/2 "2023-08-02T09:55:59Z")

</div>

Hi Pjotz and welcome to the Percona Community.

It looks like you have a standalone MongoDB instance. PBM does not work against a standalone server, it works only if the Replica Sert is configured.

The thing you can do is restarting the container setting the ReplSetName configuration option and then running rs.initiate() on the node. This way you will get a 1-node Replica Set and sp PBM should work.

---

<div class="post-metadata">

**Author:** ![Pjotz](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/pjotz/32/12032_2.png) [@Pjotz](https://forums.percona.com/u/Pjotz)\
**Post date:** [August 8, 2023, 10:23am UTC](https://forums.percona.com/t/server-selection-error-timeout/24127/3 "2023-08-08T10:23:06Z")

</div>

Thanks for the reply, will have a look at it tomorrow. and return to you 🙂

---

<div class="post-metadata">

**Author:** ![Parag\_Bhayani](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/parag_bhayani/32/3710_2.png) [@Parag\_Bhayani](https://forums.percona.com/u/Parag_Bhayani)\
**Post date:** [August 18, 2023, 6:20pm UTC](https://forums.percona.com/t/server-selection-error-timeout/24127/6 "2023-08-18T18:20:11Z")

</div>

Hi @Pjotz ,

For a sharded cluster, run any pbm related commands on Config Server ReplSet since it contains the metadata of the whole cluster.

 ![image](https://us1.discourse-cdn.com/flex019/uploads/percona1/original/2X/4/445dca013e9114579207fff95a053145b3ffaaa5.png)

Ref.: [Configuration file - Percona Backup for MongoDB](https://docs.percona.com/percona-backup-mongodb/reference/config.html)

Regards,  
Parag

---

<div class="post-metadata">

**Author:** ![Pjotz](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/pjotz/32/12032_2.png) [@Pjotz](https://forums.percona.com/u/Pjotz)\
**Post date:** [August 21, 2023, 6:43am UTC](https://forums.percona.com/t/server-selection-error-timeout/24127/7 "2023-08-21T06:43:14Z")

</div>

Thanks for the reply, tried to run everything from one of the cfg servers:

 ![image](https://us1.discourse-cdn.com/flex019/uploads/percona1/original/2X/8/8eeacd27ef262befb7e71444afd0fd3ec36645f9.jpeg)

sorry its a screenshot, but im working with airgapped, so only way i could get it out at this point 🙂

---

<div class="post-metadata">

**Author:** ![Parag\_Bhayani](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/parag_bhayani/32/3710_2.png) [@Parag\_Bhayani](https://forums.percona.com/u/Parag_Bhayani)\
**Post date:** [August 21, 2023, 9:55am UTC](https://forums.percona.com/t/server-selection-error-timeout/24127/8 "2023-08-21T09:55:39Z")

</div>

Hi @Pjotz ,

Kindly share the below details -

1. pbm status output.
2. MongoDB connection URI for `pbm CLI` (PBM\_MONGODB\_URI).
3. pbm logs.

Regards,  
Parag

---

<div class="post-metadata">

**Author:** ![Pjotz](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/pjotz/32/12032_2.png) [@Pjotz](https://forums.percona.com/u/Pjotz)\
**Post date:** [August 28, 2023, 8:52am UTC](https://forums.percona.com/t/server-selection-error-timeout/24127/9 "2023-08-28T08:52:45Z")

</div>

Thanks for the swift reply,  
I´m a lot closer now, have gotten the backup running and everything is almost good 🙂

Only issue I´m facing now, is that I´m running percona mongodb server, in my dockerfile i install the pbm-agent. Created a shell script, that starts the pbm-agent, and put it in /docker-entrypoint-initdb.d and mounted the backup folder via docker-compose.  
Everything on the config servers are running like a charm. but the data nodes aint running the entrypoint script, because the database is initialised (i can see in the entrypoint.sh script that is the case).  
So how is it intended to start the pbm-agent inside the containers when they start up?

/Morten
