Backup MongoDB Database
Backing up all MongoDB databases can be accomplished by running the following command.
mongodump
This will create a “dump” directory in the current working directory containing all available databases. Here is an example of a single database requiring user credentials being backed up.
mongodump -u username -p password -d mydatabase
The -p parameter without a password argument will prompt for the user password.
Restore MongoDB Database
Previously backed up databases can be restored by specifying the path to the existing “dump” directory.
mongorestore ./dump
A single database backup may need to be restored over an existing database and the existing collections automatically replaced. Use the –drop parameter with caution.
mongorestore --drop ./dump/my_database
Views: 2