Starting HiveMQ in cluster mode with persistent data

When a HiveMQ node is started in cluster mode it will automatically move the contents of its existing data folder to the cluster-backup folder, effectively starting up the node without any data.
This is done on purpose. The logic behind this is that a running cluster always has the more relevant and consistent data than a restarted node. Even if the data present on the node is only a few minutes old it is likely that the persisted data for MQTT clients has changed a lot.

During specific scenarios such as maintenance windows or disaster recovery it can be useful or necessary to start up a HiveMQ node in cluster mode with persistent data. 

Instructions

HiveMQ provides a specific run script called recovery.sh that can be utilized for starting a HiveMQ node in cluster mode with persistent data

Startup via using the start up script

  1. Execute the the recovery.sh file in the HIVEMQ_HOME/bin folder.

    cd <your-hivemq-home-folder>/bin./recovery.sh

Start up HiveMQ as a service (init.d)

  1. Open the HiveMQ init.d start script

    vi /etc/init.d/hivemq
  2. Change the startup to using recovery.sh instead of run.sh at line 19

    ...
            failure $"HiveMQ start"
            echo; else
            echo -n Starting HiveMQ server
            su $HIVEMQ_USER -c "$HIVEMQ_HOME/bin/recovery.sh >/dev/null 2>&1 &"
            ### Create the lock file ###
            touch /var/lock/subsys/hivemq
            success $"HiveMQ server started"
    ...
  3. Start the HiveMQ Service

    /etc/init.d/hivemq start
  4. Make sure to revert the changes from step 2

Start up HiveMQ as a service (Debian based, using init.d)

  1. Open the HiveMQ init.d start script

    vi /etc/init.d/hivemq
  2. Change the startup to using recovery.sh instead of run.sh at line 19

    ...
    BASEDIR=/opt/hivemq
    NAME=hivemq
    DESC="MQTT Broker"
    DAEMON=/opt/hivemq/bin/recovery.sh
    DAEMON_USER=hivemq
    DAEMON_GROUP=hivemq
    PID_FILE="/var/run/${NAME}.pid"
    ...
  3. Start the HiveMQ Service

    /etc/init.d/hivemq start
  4. Make sure to revert the changes from step 2


Start up HiveMQ as a service (systemd)

  1. Open the HiveMQ systemd script

    vi /etc/systemd/system/hivemq.service
  2. Change the startup to using recovery.sh instead of run.sh at line 12

    ...
      ExecStart=/opt/hivemq/bin/recovery.sh
    ...
  3. Start the HiveMQ Service

    systemctl start hivemq
  4. Make sure to revert the changes from step 2


HiveMQ does not support the start up of more than 1 nodes in recovery mode.