Backing Up and Restoring Data
Last updated
Last updated
Atlas backups are not available for M0 (Free Tier) clusters. You may use mongodump to back up your M0 cluster data and mongorestore to restore that data. To learn how to manually back up your data, see Command Line Tools.
Atlas provides instructions for connecting to an Atlas cluster using select MongoDB command line tools in the Command Line Tools tab.
Navigate to the Clusters page for your project.
Choose Command Line Tools for your desired cluster.
Download the CLI for Ubuntu/Debian and put the .deb file in your home directory.
Execute the following to install it: sudo dpkg -i mongocli_1.16.0_linux_x86_64.deb
Also install mongo-tools with sudo apt install mongo-tools
mongodump | creates a binary export of the contents of a database
cd ~
mkdir mongdb-backups
cd mogodb-backups
mkdir 2021-06-12-303pm
mongodump --uri mongodb+srv://<mongodb_user>:<mongodb_password>@cluster0.cwrqa.mongodb.net/rm_production --forceTableScan -o /home/cburleson/mongodb-backups/2021-06-12-303pm
--forceTableScan
is there because of an error, Unrecognized field 'snapshot'
. Solution was to include this parameter. See: https://dba.stackexchange.com/questions/215534/mongodump-unrecognized-field-snapshot
-o
is the target directory
The mongorestore program loads data from either a binary database dump created by mongodump or the standard input into a mongod or mongos instance.
Delete the preview database (it will be recreated automatically in the next step). Execute the following commands to recreate the preview database and restore each collection.
mongorestore --uri="mongodb+srv://<user>:<password>@cluster0.cwrqa.mongodb.net/?authSource=admin" --db=rm_preview --collection=categories /home/cburleson/mongodb-backups/2021-06-12-303pm/rm_production/categories.bson
mongorestore --uri="mongodb+srv://<user>:<password>@cluster0.cwrqa.mongodb.net/?authSource=admin" --db=rm_preview --collection=documents /home/cburleson/mongodb-backups/2021-06-12-303pm/rm_production/documents.bson
mongorestore --uri="mongodb+srv://<user>:<password>@cluster0.cwrqa.mongodb.net/?authSource=admin" --db=rm_preview --collection=images /home/cburleson/mongodb-backups/2021-06-12-303pm/rm_production/images.bson
mongoexport is a command-line tool that produces a JSON or CSV export of data stored in a MongoDB instance.
See: mongoexport
mongoexport --uri="mongodb+srv://<user>:<password>@cluster0.cwrqa.mongodb.net/rm_preview" --collection=documents --out=documents.json --forceTableScan --pretty
The mongoimport tool imports content from an Extended JSON, CSV, or TSV export created by mongoexport, or potentially, another third-party export tool.
See: mongoimport
mongoimport --uri="mongodb+srv://<user>:<password>@cluster0.cwrqa.mongodb.net/rm_preview" --collection=documents --file=documents.json