Frequently Asked Question
We're going to assume here that the Docker container is called rocket-mongodb, which is the Rocket.Chat MongoDB container for this example, but this applies to all MongoDB containers.
You could
docker export rocket-mongodb -o mongobackup
and then transfer that somewhere safe. To restore, you would simply delete the current container and Docker import the backup.
A better and cleaner way would be to use the built‑in Mongo tools to do the backup.
docker exec rocket-mongodb sh -c 'mongodump --archive' > "/somepath/${date}_db.dump" This will create a dump file of the database; you could then compress it if you wish.
To restore:
docker exec -i rocket-mongodb sh -c 'mongorestore --drop --archive'
Assuming the dump to restore was 2024_04_27_db.dump.
Remember, the --drop option means that it will delete any current collections and restore those from a backup. Without --drop, it will try to merge the two, only adding missing data, which for a backup/restore is not what we want.
