Video Transcript (English)
Welcome! In this first lesson, you’ll learn how to use `mongodump` and `mongorestore` to back up and restore a free tier, or M0, cluster on MongoDB Atlas.
`mongodump` is a command-line tool to create a backup of your cluster. This ensures you’ll have a copy of your data if you need to move it to a new cluster or restore your cluster to a previous state.
`mongorestore` is a command-line tool that uses the backup of your data to set up a new cluster or restore it to a previous state.
Because `mongodump` and `mongorestore` are command-line tools, they must be run from your operating system’s command line, not from the MongoDB Shell.
Because mongodump has to read and uncompress all data via the mongod process, system resources will be limiting factors in performance. mongorestore has to rebuild all of the indexes, which is also resource-intensive. If you need to backup and restore a large amount of data fast, you may want to explore other backup options.
`mongodump` is a part of the MongoDB Database Tools package. Check the MongoDB documentation for more information on how to install the MongoDB Database Tools for your operating system.
To use `mongodump`, navigate to the Database Deployments page of Atlas to locate the cluster.
Next, we’ll navigate to Command Line Tools by clicking here.
This page includes instructions for using various Command Line Tools.
We’ll go to the section on Binary Import and Export Tools to find instructions for using `mongodump` and `mongorestore`. Copy the command for `mongodump`.
Now let’s navigate to our terminal and paste the command. Remove the <PASSWORD> placeholder so that you will be prompted to enter your password. Then delete the <DATABASE> placeholder to back up all the databases in the cluster. Press Enter.
When `mongodump` finishes, the output confirms that all databases have been backed up successfully to corresponding folders in the directory that’s specified in the `mongodump` command. If we don’t specify a directory, the folders will be placed in the `./dump/` directory in the current path.
Now that we have a backup of our databases in our cluster, let’s explore how we might use it.
Let’s say we want to create a new cluster with data from our existing cluster. Because we’re creating a new cluster, our database deployment screen is empty. We’ll use `mongorestore` to restore the databases from the backup files on our local machine.
The `mongorestore` utility restores a binary backup that was created by `mongodump`. By default, it searches for a database backup in the `dump/` directory. If you specified a different folder in the mongodump command, specify that same folder in the `mongorestore` command.
Now we’ll navigate to the Command Line Tools in Atlas and copy the `mongorestore` command.
In the terminal, we’ll paste the command and replace the <PASSWORD> placeholder accordingly, then press Enter.
The output shows the number of documents that were successfully restored as well as the number that failed to restore.
To confirm that our databases have been successfully restored, we’ll navigate to Atlas and refresh our collections. This shows that the restore was successful, and all documents have been restored.
Well done! Now you know how to use the command-line tools mongodump and mongorestore to back up and restore an M0 cluster.