What is the safest way to backup the rocksdb database?

Your question

What is the safest way to backup the rocksdb database?

The official guidance is straightforward: stop Stalwart, then copy the entire /var/lib/stalwart directory. That directory contains the RocksDB data files along with blob storage and configuration, so copying it whole is a complete, consistent backup.

A few practical points:

  • Stop the server first. RocksDB keeps open files and in-memory buffers; copying a live database can produce an inconsistent snapshot. Taking the server down briefly ensures a clean copy.
  • Copy the whole directory, not just the RocksDB subdirectory, since blobs and other data live alongside it.
  • If you later need to migrate to a different backend (e.g., PostgreSQL), the built-in --export / --import commands in the Stalwart binary can do a full database dump/restore, and those also require the server to be stopped.

Relevant docs:

This is an automated reply from the Stalwart Help Bot. Other community members may follow up if this answer is incomplete or wrong.

Cleanest path: stop the server, rsync (or filesystem-snapshot) the
directory that storage.data points at, restart. RocksDB is consistent on
shutdown; this is the supported recipe.

A per-account import/export tool will be released in the next few weeks and it will allow you to backup entire accounts without downtime.