# Agent failed to start

**URL:** <https://forums.percona.com/t/agent-failed-to-start/15276>\
**Category:** Percona Backup for MongoDB\
**Created:** [April 17, 2022, 9:53pm UTC](https://forums.percona.com/t/agent-failed-to-start/15276 "2022-04-17T21:53:05Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Seventh\_Son](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/seventh_son/32/6333_2.png) [@Seventh\_Son](https://forums.percona.com/u/Seventh_Son)\
**Post date:** [April 17, 2022, 9:53pm UTC](https://forums.percona.com/t/agent-failed-to-start/15276/1 "2022-04-17T21:53:05Z")

</div>

Hi! I have Mongo 5.0 cluster, so my URI:

```auto
PBM_MONGODB_URI="mongodb://pbmagent:password@ip-10-100-10-240.ap-southeast-1.compute.internal:27017,ip-10-100-10-28.ap-southeast-1.compute.internal:27017,ip-10-100-10-31.ap-southeast-1.compute.internal:27017/admin?replicaSet=myreplica"

```

agent restart fails with error:

```auto
pbm-agent[29828]: 2022/04/17 21:48:02 connect to the node: connect: create mongo client: a direct connection cannot be made if multiple hosts are specif

```

---

<div class="post-metadata">

**Author:** ![Ivan\_Groenewold](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/ivan_groenewold/32/6299_2.png) [@Ivan\_Groenewold](https://forums.percona.com/u/Ivan_Groenewold)\
**Post date:** [April 18, 2022, 2:51pm UTC](https://forums.percona.com/t/agent-failed-to-start/15276/2 "2022-04-18T14:51:09Z")

</div>

Hi, the pbm agent connection string on each node should be pointed to the local mongod process, do not use the replica set connection string in this case.  
For example use:

PBM\_MONGODB\_URI=“mongodb://pbagent:password@localhost:27017”

---

<div class="post-metadata">

**Author:** ![Seventh\_Son](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/seventh_son/32/6333_2.png) [@Seventh\_Son](https://forums.percona.com/u/Seventh_Son)\
**Post date:** [April 18, 2022, 3:00pm UTC](https://forums.percona.com/t/agent-failed-to-start/15276/3 "2022-04-18T15:00:39Z")

</div>

Hi.  
Thanks for reply, that was my #1 idea and I did it, but now pbm backup only admin DB and ignore mine. Could it be auth/permission issue? I applied pbmuser creation script from PBM guide and able to connect to Mongo as pbmuser and list all the DBs. Any ideas?  
On my same version 5.0 test cluster PBM works fine, but Mongo auth turned off there, so that is the only one stuff I suspect to be involved.

---

<div class="post-metadata">

**Author:** ![Ivan\_Groenewold](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/ivan_groenewold/32/6299_2.png) [@Ivan\_Groenewold](https://forums.percona.com/u/Ivan_Groenewold)\
**Post date:** [April 18, 2022, 3:06pm UTC](https://forums.percona.com/t/agent-failed-to-start/15276/4 "2022-04-18T15:06:36Z")

</div>

That sounds like a perms issue. Can you check that you created the backup role & user on each replica set (including CFG)?

```auto
db.getSiblingDB("admin").createRole({ "role": "pbmAnyAction",
      "privileges": [
         { "resource": { "anyResource": true },
           "actions": ["anyAction"]
         }
      ],
      "roles": []
   });

```

```auto
db.getSiblingDB("admin").createUser({user: "pbmuser",
       "pwd": "secretpwd",
       "roles" : [
          { "db" : "admin", "role" : "readWrite", "collection": "" },
          { "db" : "admin", "role" : "backup" },
          { "db" : "admin", "role" : "clusterMonitor" },
          { "db" : "admin", "role" : "restore" },
          { "db" : "admin", "role" : "pbmAnyAction" }
       ]
    });

```

---

<div class="post-metadata">

**Author:** ![Seventh\_Son](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/seventh_son/32/6333_2.png) [@Seventh\_Son](https://forums.percona.com/u/Seventh_Son)\
**Post date:** [April 18, 2022, 3:33pm UTC](https://forums.percona.com/t/agent-failed-to-start/15276/5 "2022-04-18T15:33:05Z")

</div>

Hi Ivan,  
failed to apply it on SECONDARY’s with the error:

```auto
uncaught exception: Error: not master

```

I tried to connect to /admin, /?replicaSet=xxxx, /?replSetName=xxxx, all the same.  
Of course I used only one host name in URI, not the whole cluster list.

---

<div class="post-metadata">

**Author:** ![Ivan\_Groenewold](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/ivan_groenewold/32/6299_2.png) [@Ivan\_Groenewold](https://forums.percona.com/u/Ivan_Groenewold)\
**Post date:** [April 18, 2022, 4:19pm UTC](https://forums.percona.com/t/agent-failed-to-start/15276/6 "2022-04-18T16:19:30Z")

</div>

What failed to apply? can you describe exactly the steps you are taking and where do you see this error?

---

<div class="post-metadata">

**Author:** ![Seventh\_Son](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/seventh_son/32/6333_2.png) [@Seventh\_Son](https://forums.percona.com/u/Seventh_Son)\
**Post date:** [April 18, 2022, 6:11pm UTC](https://forums.percona.com/t/agent-failed-to-start/15276/7 "2022-04-18T18:11:13Z")

</div>

Hi Ivan,

I ssh to SECONDARY, connect to Mongo node, not replicaSet, applied the script for role creation:

```auto
root@ip-10-100-10-145:/home/ubuntu# mongo "mongodb://pbmuser:password@localhost:27017"
MongoDB shell version v5.0.7
connecting to: mongodb://localhost:27017/?compressors=disabled&gssapiServiceName=mongodb
MongoDB server version: 5.0.7
mybd:SECONDARY> db.getSiblingDB("admin").createRole({ "role": "pbmAnyAction",
... "privileges": [
... { "resource": { "anyResource": true },
... "actions": ["anyAction"]
... }
... ],
... "roles": []
... });
uncaught exception: Error: not master :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DB.prototype.createRole@src/mongo/shell/db.js:1656:15
@(shell):1:1
mybd:SECONDARY>

```

how to apply the script and create pbm role/user on secondary nodes?

---

<div class="post-metadata">

**Author:** ![Ivan\_Groenewold](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/ivan_groenewold/32/6299_2.png) [@Ivan\_Groenewold](https://forums.percona.com/u/Ivan_Groenewold)\
**Post date:** [April 18, 2022, 6:28pm UTC](https://forums.percona.com/t/agent-failed-to-start/15276/8 "2022-04-18T18:28:45Z")

</div>

Hello, you only need to create the user on the primaries. It will be propagated via replication.

---

<div class="post-metadata">

**Author:** ![Seventh\_Son](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/seventh_son/32/6333_2.png) [@Seventh\_Son](https://forums.percona.com/u/Seventh_Son)\
**Post date:** [April 18, 2022, 11:54pm UTC](https://forums.percona.com/t/agent-failed-to-start/15276/9 "2022-04-18T23:54:28Z")

</div>

Hi Ivan,

ok, so why pbm-agent backup only admin DB now? how to debug the issue? logically, having access to admin DB, agent must be able to access all the others.

---

<div class="post-metadata">

**Author:** ![Ivan\_Groenewold](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/ivan_groenewold/32/6299_2.png) [@Ivan\_Groenewold](https://forums.percona.com/u/Ivan_Groenewold)\
**Post date:** [April 19, 2022, 11:01am UTC](https://forums.percona.com/t/agent-failed-to-start/15276/10 "2022-04-19T11:01:16Z")

</div>

If you already confirmed privileges are fine I suggest you should check pbm agent logs on all nodes for clues.

---

<div class="post-metadata">

**Author:** ![Seventh\_Son](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/seventh_son/32/6333_2.png) [@Seventh\_Son](https://forums.percona.com/u/Seventh_Son)\
**Post date:** [April 20, 2022, 12:05am UTC](https://forums.percona.com/t/agent-failed-to-start/15276/11 "2022-04-20T00:05:35Z")

</div>

Hi Ivan,

thanks, found the issue:

```auto
"The index specification for index 'hostname_1' contains invalid field names. The field 'safe' is not valid for an index specification. Specification: { v: 1, unique: true, key: { hostname: 1 }, name: \"hostname_1\", ns: \"mymongo.hostowner\", safe: null }. Run the 'collMod' command on the collection without any arguments to remove the invalid index options"

```

applied collMod for all the problematic collections and backup works for now.

---

<div class="post-metadata">

**Author:** ![Ivan\_Groenewold](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/ivan_groenewold/32/6299_2.png) [@Ivan\_Groenewold](https://forums.percona.com/u/Ivan_Groenewold)\
**Post date:** [April 20, 2022, 10:57am UTC](https://forums.percona.com/t/agent-failed-to-start/15276/12 "2022-04-20T10:57:15Z")

</div>

Glad you sorted it out. Thanks for letting us know what was the problem
