1

Is there any way to verify mosquitto.db data from database file?

I took backup of mosquitto.db file and copied into my desired backup location, but during restore of mosquitto.db is there way to verify backed up data using any cli or mqttx client?

  • 1
    From [the docs](https://mosquitto.org/man/mosquitto-conf-5.html) "The data will be written to disk when mosquitto closes and also at periodic intervals as defined by autosave_interval" so unless you are shutting Mosquitto down it's likely that the `.db` file is incomplete anyway. See [this answer](https://stackoverflow.com/a/14024101/11810946) from the author for more info - what do you intend to do with the backup?. – Brits Oct 19 '22 at 21:27

1 Answers1

2

The database is not intended to be human readable.

It holds the following information:

  • Inflight QOS 1/2 messages
  • including messages for offline clients with persistent sessions
  • Session information for clients

There is a tool included in the mosquitto source (but not build by default) that can open the file for the curious.

https://github.com/eclipse/mosquitto/tree/master/apps/db_dump

hardillb
  • 54,545
  • 11
  • 67
  • 105
  • Thanks for the quick prompt. Is there any way to verify database which we backed up (mosquitto.db) after restore (mosquitto.db) to persistent location of mosquitto ? – Harsh Gajjar Oct 19 '22 at 16:26
  • 1
    If the tool opens the file, then it's probably OK, but there is no other tests. IIRC mosquitto writes a new copy and renames when updating the file, so there shouldn't be a way to corrupt the file (assuming no disc space problems). – hardillb Oct 19 '22 at 16:29
  • Is there any other way to take backup of MQTT data in JSON file so later on can we import during restore or something ? – Harsh Gajjar Oct 19 '22 at 16:30
  • 1
    No, this is a pure binary dump of the internal state of the broker, as I said it is NOT intended to be human readable. – hardillb Oct 19 '22 at 16:31
  • It would be great if you can suggest other approach for backup and restore Mqtt.if you have any. – Harsh Gajjar Oct 19 '22 at 16:48