I am running Home Assistant OS in a VM (2026.5.3) and I use the Mosquitto Broker App (7.1.0). I'm running into performance issues (long boot and it looks like apps are taking long to start up) so I'm going to reduce the number of Apps I'm running, or migrate some of the apps to separate VMs. I have another purpose for an MQTT broker outside of HomeAssistant, and as a result, it's one of the big ones I want to relocate.
I know the general rules for migrating mosquitto (from that project's documentation) however I am not finding where things like the DB are stored in home assistant; from the shell, I can't run "docker ps" or "docker exec" because it says the docker command is unknown.
How would I find the root directory for the mosquitto add on so I can attempt to migrate it elsewhere, there's no way it's writing to the main HA DB is there? It should be separate since it's an addon, and as such, it should have its own config file? Searching the filesystem for the word "mosquitto" didn't turn up much.
You need to enable developer access to SSH in the home assistant OS. The reason you don't see it now is because you're inside the core container, not the actual OS. Within the OS all the docker commands are available. There are multiple ways to make this work, but the easiest is this 🆕[add-on] HassOS SSH port 22222 Configurator
You may not need to "migrate" Mosquitto off of the HA VM.
Specifically most of the state in Mosquitto is fairly transient - only topics/messages specifically marked as Retain would survive a restart (Power Cycle) of Mosquitto anyway.
I would suggest just spinning up a new Mosquitto broker somewhere else and updating the configuration to point to it.
Most likely after you have turned every device you have on and off the Mosquitto state will be current.
TL;DR - Because Mosquitto state is fairly transient you can probably ignore any current state stored in the current broker.
PS For performance issues you may want to try docker rather than running HA in a VM.
Have not done what you're trying to do. This is the process that I would try.
I already have the HA App Advanced SSH & Web Terminal I use PuTTY running on my main computer (Windows) as my terminal emulator. I SSH into HA with "C:\Program Files\PuTTY\putty.exe" -ssh [HA username]@[IP address of HA] -pw [HA password] -P 22222
A google search will tell you that mosquitto.db, the mosquitto persistance file, is in the directory /var/lib/mosquitto Copy this file to the directory that is shared with the host. (I'll leave it up to you to set up your shared directory)
I installed my mosquitto broker on the host of my VM. (It can be installed on any computer on your network) It is started, stopped, etc. with systemctl Stop the mosquitto broker, make a backup of the existing mosquitto.db, copy the HA mosquitto.db to the host's /var/lib/mosquitto, then start the mosquitto broker.
Finally, reconfigure the MQTT integration to point the the new broker.
The gotchas in doing this are many, but I think this will work with minimal data loss (that will probably return once you're up and running again)
I am uncomfortable with this and that is why I write this little missive. I use a couple of disparate programs that rely on the mosquitto database for their operation and communication with HA. Fortunately, I have found that the mosquitto database is very resilient, having survived some pretty gnarly system crashes. Mosquitto is awesome in this regard.
Ok, thank you for the advice. I think I can back up the old database, but also I can just migrate my devices, and the refer to it if I need to and try to move things I've missed manually. I got MQTT Explorer working, so I can find missing data.