MongoDB provides multiple ways to perform backups and restores.
MongoDB provides command-line tools mongodump and mongorestore for logical database backups and restores.
It is recommended to perform backups during periods of low activity to avoid inconsistencies.
To create a logical backup of the MongoDB database, the following command can be used:
mongodump \
--host <host> \
--port <port> \
--username <user> \
--password <password> \
--authenticationDatabase admin \
--db <database> \
--out /path/for/backup/mongodb_backup
To restore the backup, the following command can be used:
mongorestore \
--host <host> \
--port <port> \
--username <user> \
--password <password> \
--authenticationDatabase admin \
--db <database> \
--drop \
/path/for/backup/mongodb_backup/<database>
Alternatively, a filesystem-level backup of MongoDB data can be performed by archiving the data directory. This approach requires that MongoDB is stopped before copying files to ensure data consistency. If running a replica set, backups can be performed from a secondary node without stopping the primary.
systemctl stop mongod
cd /var/lib/xbat/mongodb
tar -czvf /path/for/backup/mongodb_backup.tar.gz *
systemctl start mongod
To restore from a filesystem backup:
systemctl stop mongod
tar -xzvf mongodb_backup.tar.gz -C /var/lib/xbat/mongodb
chown -R mongodb:mongodb /var/lib/xbat/mongodb
systemctl start mongod
In addition to using CLI tools or filesystem-level backups, MongoDB backups and restores can also be performed via the xbat user interface or the REST API.
Administrators can trigger a full MongoDB backup directly from the UI menu, or by using the following REST API endpoint:
POST /api/v1/benchmarks/backup
The response will return a .tgz file containing the backup. Example response header:
Content-Disposition: attachment; filename="MongoDB_backup_<timestamp>.tgz"
Check the MongoDB documentation and the xbat REST API documentation for further details.
It is recommended to put QuestDB into checkpoint mode before performing a backup. Head to <host>:7000/questdb/ and execute CHECKPOINT CREATE. When the backup is done execute CHECKPOINT RELEASE to revert QuestDB to normal operation.
QuestDB does not provide a dedicated backup mechanism, but instead relies on the user to cp or rsync the files to a backup location. The following command can be used to backup the QuestDB data directory:
cd /var/lib/xbat/questdb
tar -czvf /path/for/backup/questdb_backup.tar.gz *
To restore the backup, the following command can be used:
tar -xzvf questdb_backup.tar.gz -C /var/lib/xbat/questdb
Check the QuestDB documentation for further details.
Deleting benchmarks in xbat removes them from the MongoDB database. However, since QuestDB does not support the DELETE operation, there is no direct way of removing data within the constraints of xbat. Administrators can manually trigger a purge of deleted benchmarks from QuestDB by clicking Purge QuestDB in the xbat interface (Overview > Actions). To avoid any issues with running jobs, this action should only be performed when certain that no xbat jobs are currently running (e.g. when cluster is in drain/maintenance). It is recommended to restart xbat after purging QuestDB data to rebuild database indexes.