Databases Reference
In-Depth Information
Because it is not safe in general to copy the data directory while MongoDB is running,
one option for taking a backup is to shut down the MongoDB server and then copy the
data directory. Assuming the server is shut down safely (see the section “Starting and
Stopping MongoDB” on page 111 ), the data directory will represent a safe snapshot of
the data stored when it was shut down. That directory can be copied as a backup before
restarting the server.
Although shutting down the server and copying the data directory is an effective and
safe method of taking backups, it is not ideal. In the remainder of this chapter, we'll
look at techniques for backing up MongoDB without requiring any downtime.
mongodump and mongorestore
One method for backing up a running instance of MongoDB is to use the mongodump
utility that is included with all MongoDB distributions. mongodump works by querying
against a running MongoDB server and writing all of the documents it contains to disk.
Because mongodump is just a regular client, it can be run against a live instance of
MongoDB, even one handling other requests and performing writes.
Because mongodump operates using the normal MongoDB query mecha-
nism, the backups it produces are not necessarily point-in-time snap-
shots of the server's data. This is especially evident if the server is actively
handling writes during the course of the backup.
Another consequence of the fact that mongodump acts through the normal
query mechanism is that it can cause some performance degradation for
other clients throughout the duration of the backup.
Like most of the command-line tools included with MongoDB, we can see the options
available for mongodump by running with the --help option:
$ ./mongodump --help
options:
--help produce help message
-v [ --verbose ] be more verbose (include multiple times for more
verbosity e.g. -vvvvv)
-h [ --host ] arg mongo host to connect to ("left,right" for pairs)
-d [ --db ] arg database to use
-c [ --collection ] arg collection to use (some commands)
-u [ --username ] arg username
-p [ --password ] arg password
--dbpath arg directly access mongod data files in the given path,
instead of connecting to a mongod instance - needs
to lock the data directory, so cannot be used if a
mongod is currently accessing the same path
--directoryperdb if dbpath specified, each db is in a separate
directory
-o [ --out ] arg (=dump) output directory
 
Search WWH ::




Custom Search