Skip to content

Cookie preferences

We use cookies for our own analytics, to see how our campaigns perform and, if you allow it, to load the site search from Google. We never sell your data. Necessary cookies keep the site working and cannot be switched off. See our Cookie Policy for details and our Privacy Policy for how we handle personal data.

Security, load balancing and remembering your cookie choice.

Show us which pages people read, how they find the site and where they get stuck, so we can improve it (Google Analytics).

Remember the campaign or partner link you arrived from, so we know which campaign or partner brought you when you sign up or contact us (partner program). We do not use it to build advertising profiles.

Load the site search from Google when you use it. Google sets its own cookies and shows ads in the search results.

776 Try for free Menu

TBMQ live demo

Try TBMQ in your browser

A free account on our public broker. Open the TBMQ UI and connect your MQTT clients. No credit card required.

Rather run it yourself? Install on your own servers

Backup and restore

Beta

TBMQ Lite keeps all its data in the store under /data/db: sessions and their queues, retained messages, credentials, providers, users, settings and statistics. A backup is a consistent copy of that store in one .tar.gz archive. The broker does not back itself up: schedule backups and keep them off the host.

From the web UI

While the broker runs, in one click. See From the UI.

With the REST API

While the broker runs, from a script or a scheduled job. See With the REST API.

A backup holds the BCrypt hashes of the client and user passwords and the broker’s token signing key. Store it like a secret.

The commands on this page use the container and the volume of the install guide, both named tbmq-lite; the Compose file names them the same. If the broker keeps its data in a bind mount, put the host directory in place of tbmq-lite in -v tbmq-lite:/data.

Sign in as the system administrator, go to Settings → General, and click Download backup on the Backup card.

GET /api/system/backup streams the same archive. It needs a system administrator’s token. One backup runs at a time; a second request while one runs is refused with 409. The example uses curl and jq:

Terminal window
TOKEN=$(curl -s -X POST http://localhost:8083/api/auth/login \
-H 'Content-Type: application/json' \
-d '{"username":"sysadmin@thingsboard.org","password":"<password>"}' | jq -r .token)
curl -f -o "tbmq-lite-backup-$(date +%F-%H%M%S).tar.gz" \
-H "X-Authorization: Bearer $TOKEN" \
http://localhost:8083/api/system/backup

The backup command opens the store itself, so it runs only while the broker is stopped. With the broker running it exits with code 2 and leaves the stored data as it is, but its attempt rotates the store’s log: the broker goes on logging to /data/db/LOG.old.<timestamp>, and a new /data/db/LOG is started. On a stopped broker it writes the same archive as the REST API:

Terminal window
docker stop tbmq-lite
docker run --name tbmq-lite-backup -v tbmq-lite:/data \
--entrypoint java thingsboard/tbmq-lite:2.5.0-beta \
-Djava.library.path=/usr/share/tbmq-lite/native --enable-native-access=ALL-UNNAMED \
-cp /usr/share/tbmq-lite/app/tbmq-lite.jar \
org.thingsboard.mqtt.broker.dao.rocksdb.backup.StoreBackupCommand \
--store-path /data/db --out /tmp/tbmq-lite-backup.tar.gz
docker cp tbmq-lite-backup:/tmp/tbmq-lite-backup.tar.gz "tbmq-lite-backup-$(date +%F-%H%M%S).tar.gz"
docker rm tbmq-lite-backup
docker start tbmq-lite

The command runs in a helper container, writes the archive inside it, and docker cp copies it to the current directory, named by the date and time. Exit code 0 means the archive is written.

The archive holds a db directory and a backup-manifest.json file with the version that wrote it. A backup from an older version is upgraded on start; one from a newer version is refused.

  1. Stop the broker.

    Terminal window
    docker stop tbmq-lite
  2. Replace the store with the archive’s db directory.

    Run this in the directory of the backup, with its file name in BACKUP. The helper container runs as root so that the restored files keep their owner, uid 799; it unpacks the archive before it removes the current store:

    Terminal window
    BACKUP=tbmq-lite-backup-<date-time>.tar.gz
    docker create --name tbmq-lite-restore --user 0:0 -v tbmq-lite:/data \
    --entrypoint bash thingsboard/tbmq-lite:2.5.0-beta -c 'set -e
    rm -rf /data/restore && mkdir /data/restore
    tar -xzf /tmp/backup.tar.gz -C /data/restore db
    rm -rf /data/db && mv /data/restore/db /data/db && rmdir /data/restore'
    docker cp "$BACKUP" tbmq-lite-restore:/tmp/backup.tar.gz
    docker start -a tbmq-lite-restore
    docker rm tbmq-lite-restore
  3. Start the broker.

    Terminal window
    docker start tbmq-lite
  4. Check the log.

    Terminal window
    docker logs tbmq-lite

    The log shows the broker starting on the restored store.

The restored store brings back the passwords and the token signing key of the backup, so sign in with the administrator password that was valid when the backup was taken.

Before an upgrade changes the store, the broker takes a checkpoint under /data/backups, named pre-upgrade-<from>-<to>. It is consistent and takes almost no space at first, because it shares files with the store. It protects against a failed upgrade, not against a damaged disk: the shared files are the same files.

List the checkpoints:

Terminal window
docker run --rm -v tbmq-lite:/data --entrypoint ls \
thingsboard/tbmq-lite:2.5.0-beta -l /data/backups

Until an upgrade takes a checkpoint, the listing is empty (total 0), or ls reports No such file or directory when no backup has run yet either.

To go back to one, replace the store with a copy of it. The checkpoint itself stays untouched:

Terminal window
docker stop tbmq-lite
docker run --rm -v tbmq-lite:/data -e CHECKPOINT=<checkpoint name> \
--entrypoint bash thingsboard/tbmq-lite:2.5.0-beta -c 'set -e
rm -rf /data/db.restore
cp -a "/data/backups/$CHECKPOINT" /data/db.restore
rm -rf /data/db && mv /data/db.restore /data/db'

Then start the broker on the version you want:

  • Upgrade again: docker start tbmq-lite. After an upgrade the container runs the new image, which upgrades the restored store again on start.

  • Stay on the old version: recreate the container with the image you upgraded from, with the options the broker was started with:

    Terminal window
    docker rm tbmq-lite
    docker run -d --name tbmq-lite --restart unless-stopped \
    -p 1883:1883 -p 8083:8083 -p 8084:8084 \
    -v tbmq-lite:/data thingsboard/tbmq-lite:<old version>

If the store is damaged, the broker refuses to start, and its log lists the checkpoints under /data/backups and these restore steps.