Skip to main content
Question

mongoexport device configuration files

  • Feb 18, 2025 7:54 PM UTC
  • 7 replies
  • 136 views

How can I use mongoexport to download device configuration files?

7 replies

Forum|alt.badge.img+2
  • NetBrain Employee
  • Feb 18, 2025 9:14 PM UTC

Hi ​@tabordl ,

Thanks for your posts.

You may try to use the built-in plugin to export the configuration files, pls see below:

 

 

Hope it helps,

Thanks,

Gerry


  • Author
  • New Participant
  • Feb 18, 2025 9:52 PM UTC

This gives me some insight. I have code (below) in bash to do mongoexport of collection ‘Devices’ to get the list of devices. Was hoping to do the same for the config of devices as needed. Can I sftp to the netbrain DB server?

 

  # define the mongodb export
  mxcmd="mongoexport"
  mxcmd="${mxcmd} --quiet"
  mxcmd="${mxcmd} --host=${mongoh}"
  mxcmd="${mxcmd} --authenticationDatabase=${mongod}"
  mxcmd="${mxcmd} --authenticationMechanism=SCRAM-SHA-1"
  mxcmd="${mxcmd} --username=${mongou}"
  mxcmd="${mxcmd} --password=${mongop}"
  mxcmd="${mxcmd} --db=${mongod}"
  mxcmd="${mxcmd} --collection=${mongoc}"

  # do the mongodb export, parse with jq
  ${mxcmd} | ${jqcmd}
 


Forum|alt.badge.img+2
  • NetBrain Employee
  • Feb 18, 2025 10:10 PM UTC

For the Mongodb commands, assuming the default username is admin and password is Admin1.#, connect to database admin: 

Login Mongodb without SSL

# mongo -u admin -p Admin1.# --authenticationDatabase admin --authenticationMechanism SCRAM-SHA-256

Login Mongodb with SSL

# mongo -u admin -p Admin1.# -ssl --sslAllowInvalidCertificates --authenticationDatabase admin --authenticationMechanism SCRAM-SHA-256

 

Thanks


  • Author
  • New Participant
  • Feb 19, 2025 2:51 AM UTC

I am able to authenticate properly using mongoexport and get device details from the ‘Devices’ collection. I am having issues finding the proper collection(s) for exporting device configs.


Forum|alt.badge.img+2
  • NetBrain Employee
  • Feb 19, 2025 2:34 PM UTC

​@tabordl 

 

The config is in your domain database>DeviceDataCurr, type = config, see below:

 

 


  • Author
  • New Participant
  • Feb 19, 2025 3:04 PM UTC

Outstanding. Using mongoexport with ‘--collection=DeviceDataCurr’ gives me the configs for all devices. Looks like I need to include a query filter for the specific device ID or name. I’ll google that next. 

 

{
  "_id": "968349f8-1446-4ad8-b731-84b2458bdd48",
  "content": "na-us-271-nashville-srv01#show run all\r\r\n\r\n!Command: show running-config...
  "contentType": "text/plain",
  "devId": "2ff1b68b-72b1-40fc-ad36-6059494ee356",
  "devName": "na-us-271-nashville-srv01",
  "length": 129575,
  "md5": "e57fc83a2e24b64f6ce7ae1784881786",
  "operateInfo": {
    "opTime": {
      "$date": "2019-05-29T05:18:03Z"
    },
    "opUser": "admin"
  },
  "sourceId": "145a4a67-ed99-4742-8411-3220966bb65c",
  "sourceType": "benchmark task",
  "type": "config",
  "uploadDate": {
    "$date": "2025-02-19T07:53:28Z"
  },
  "name": "",
  "subName": null
}
 

 


  • Author
  • New Participant
  • Feb 19, 2025 4:56 PM UTC

Thanks for all your help.

mongoexport --host=${mongoh} --authenticationDatabase=${mongod} --authenticationMechanism=SCRAM-SHA-1 --username=${mongou} --password=${mongop} --db=${mongod} --collection=${mongoc} --query '{"devName":"na-us-271-nashville-srv01","type":"config"}' --type=csv --fields=content