Skip to content

How to BackUp a Database?

Emidio Piermarini edited this page Jan 25, 2018 · 11 revisions

WIP

The simplest way - dump:

Think of this as zipping a folder then moving it somewhere, then unzipping it somewhere else.

Step 1) Type cmd into your windows start menu to bring up the command line Step 2) Change the directory to where you'd like to dump the mongo database (see here for more info on changing directory) Step 3) Type 'mongodump'. Doing this will back up EVERYTHING in your mongo database on your local server. If you don't want to do everything and cherrypick databases and/or collections then its should be 'mongodump --db XXXXXX --collection YYYYY' where XXXXX is your preferred database name and YYYYY is your preferred collection.

This writes the 'zipped' verion of your mongo database to the dump folder:

Step 2) [Note: If you want to manually copy this dump folder to another machine to set up the exact same mongodatabase, you can do that at the beginning of this step. This is literally a simple copy and past]

Use 'mongorestore' command in the directory where the dump folder is located with a mongoshell open.

Then you should see your cmd window go all matrix like and show crazy numbers flying all over the place:

As you can see, I didn't delete my database, so its telling me over and over its trying to write a certain document, but that document already exists so its moving on. Note - this is an INSERT ONLY operation - guids that are already in the database are skipped, not overwritten.

Conclusion - a dump is a quick and easy way to make a copy of you mongo database either for backup or for copying and giving to another machine. Obviously, this comes at the risk of duplication of data, so other methodologies such as replica sets may be a more efficient way of doing this.

A bit more involved - Replica Sets:

WIP

Clone this wiki locally