NunDb How to backup one or all databases

NunDB is an in-memory database that means we store all the data mainly in memory for speed (this helps keep NunDb fast). The obvious drawback is that if you are hosting your own NunDb and you have a server restart or need to stop it for any reason, you may lose what is in memory.

To solve that problem and at the same time keep NunDb as fast as possible, we created the command Snapshot to save to disk the current state of the database. Snapshots are heavy operations, and you should not perform them at every command. It will run asynchronously. Once you send the snapshot command a few seconds later, the database will save it to disk. NunDb reads the snapshots at startup time. From that point, all operations are executed in memory.

How to backup one database?

To back up only one database, all you need to do is to execute the command snapshot in the db instance. With that, db will do a snapshot in all cluster instances.

How to backup all databases with one single command

With a simple combination of commands, you can backup all the databases. Here we list the databases from the $admin database using the keys command, filter it with grep and tail, then use xargs to call the backup for each database.

Written on March 14, 2021