MongoDB Backup and Restore

Prev Next

Maintaining backups of your workspace data is a very important practice. These data backups can act as a safety measure where data can be recovered or restored in case of an emergency.

Rocket.Chat uses MongoDB as its database. With MongoDB, you have multiple built-in backup options depending on the deployment method.

In this guide, we are going to focus on how to:

  1. Perform a backup of your Rocket.Chat workspace data

  2. Restore your Rocket.Chat workspace data

MongoDB backup with mongodump

mongodump allows you to create backups from standalone, replica sets or sharded cluster deployments.

From MongoDB server 4.4, you need to install the mongodump utility separately. Visit the official documentation for more details.

Backup a MongoDB standalone instance

To backup a simple MongoDB standalone instance, use:

mongodump <options> <connection-string>
  • Running mongodump without any options assumes the database is running on localhost at port 27017 with no authentication.

  • When the backup completes, a /dump directory is created in your current working directory.

Backup a remote MongoDB instance

Backing up a remote MongoDB instance can be done with the following command:

mongodump --uri="mongodb://<host URL/IP>:<Port>" [additional options]

You can include additional authentication or configuration options depending on your environment. For the complete list of supported options, refer to the official documentation.

You should see something like the image below when the command is running:

mongodump command executing

MongoDB Restore with mongorestore

mongorestore restores data from a backup created with mongodump. You can restore an entire database, selected collections, or specific BSON dump files into a MongoDB instance.

Before restoring, drop any existing database schema that shares the same name as the one you are restoring. Failing to do so may result in data conflicts.

  • The syntax for the mongorestore command is as follows:

mongorestore <options> <connection-string> <directory or file to restore>
  • To restore from a dump directory to a local mongod instance running on port 27017, run:

mongorestore  dump/
  • To restore data to a remote MongoDB deployment, run:

mongorestore --uri="mongodb://<host URL/IP>:<Port>" /dump

You can also restore a specific collection or collections from the dump/ directory. Visit the official documentation for more details.

In a successful command execution, you should see a screen like the one below:

mongorestore command executed

As a workspace user, you can also download your personal data on the workspace as HTML or export it as JSON. Refer to Manage Your Account Settings for more details.