From the web UI
While the broker runs, in one click. See From the UI.
We use cookies
We use cookies for site analytics, to remember the campaign or partner link you arrived from and, if you allow it, to load the site search from Google. Nothing optional is set until you choose. You can change your choice anytime in Your Privacy Choices at the bottom of every page. Cookie Policy
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.
While the broker runs, in one click. See From the UI.
While the broker runs, from a script or a scheduled job. See With the REST API.
With the broker stopped, in a helper container. See Back up a stopped broker.
Taken by the broker before an upgrade changes the store. See Restore a pre-upgrade checkpoint.
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:
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/backupThe 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:
docker stop tbmq-litedocker 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.gzdocker cp tbmq-lite-backup:/tmp/tbmq-lite-backup.tar.gz "tbmq-lite-backup-$(date +%F-%H%M%S).tar.gz"docker rm tbmq-lite-backupdocker start tbmq-liteThe 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.
Stop the broker.
docker stop tbmq-liteReplace 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:
BACKUP=tbmq-lite-backup-<date-time>.tar.gzdocker 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.gzdocker start -a tbmq-lite-restoredocker rm tbmq-lite-restoreStart the broker.
docker start tbmq-liteCheck the log.
docker logs tbmq-liteThe 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:
docker run --rm -v tbmq-lite:/data --entrypoint ls \ thingsboard/tbmq-lite:2.5.0-beta -l /data/backupsUntil 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:
docker stop tbmq-litedocker 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:
docker rm tbmq-litedocker 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.
Was this helpful?