Frequently Asked Question

MongoDB Backup and Restore within Containers
Last Updated 3 hours ago

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.

This website relies on temporary cookies to function, but no personal data is ever stored in the cookies.
OK
Powered by GEN UK CLEAN GREEN ENERGY

Loading ...