- Reference >
- MongoDB Package Components >
mongooplog
mongooplog
¶
New in version 2.2.
Synopsis¶
mongooplog
is a simple tool that polls operations from
the replication oplog of a remote server, and applies
them to the local server. This capability supports certain classes of
real-time migrations that require that the source server remain online
and in operation throughout the migration process.
Typically this command will take the following form:
This command copies oplog entries from the mongod
instance
running on the host mongodb0.example.net
and duplicates
operations to the host mongodb1.example.net
. If you do not need
to keep the --from
host running during
the migration, consider using mongodump
and
mongorestore
or another backup operation, which may be better suited to
your operation.
Note
If the mongod
instance specified by the --from
argument is running with authentication
, then
mongooplog
will not be able to copy oplog entries.
See also
mongodump
, mongorestore
,
“Backup Strategies for MongoDB Systems”, “Oplog Internals Overview”, and “Replica Set Oplog Sizing”.
Options¶
-
mongooplog
¶
-
--help
¶
Returns a basic help and usage text.
-
--verbose
,
-v
¶
Increases the amount of internal reporting returned on the command line. Increase the verbosity with the
-v
form by including the option multiple times, (e.g.-vvvvv
.)
-
--version
¶
Returns the version of the
mongooplog
utility.
-
--host
<hostname><:port>
,
-h
¶
Specifies a resolvable hostname for the
mongod
instance to whichmongooplog
will apply oplog operations retrieved from the serve specified by the--from
option.mongooplog
assumes that all targetmongod
instances are accessible by way of port27017
. You may, optionally, declare an alternate port number as part of the hostname argument.You can always connect directly to a single
mongod
instance by specifying the host and port number directly.To connect to a replica set, you can specify the replica set seed name, and a seed list of set members, in the following format:
-
--port
¶
Specifies the port number of the
mongod
instance wheremongooplog
will apply oplog entries. Only specify this option if the MongoDB instance that you wish to connect to is not running on the standard port. (i.e.27017
) You may also specify a port number using the--host
command.
-
--ipv6
¶
Enables IPv6 support that allows
mongooplog
to connect to the MongoDB instance using an IPv6 network. All MongoDB programs and processes, includingmongooplog
, disable IPv6 support by default.
-
--username
<username>
,
-u
<username>
¶ Specifies a username to authenticate to the MongoDB instance, if your database requires authentication. Use in conjunction with the
--password
option to supply a password.
-
--password
<password>
,
-p
<password>
¶ Specifies a password to authenticate to the MongoDB instance. Use in conjunction with the
--username
option to supply a username.If you specify a
--username
without the--password
option,mongooplog
will prompt for a password interactively.
-
--dbpath
<path>
¶ Specifies a directory, containing MongoDB data files, to which
mongooplog
will apply operations from the oplog of the database specified with the--from
option. When used, the--dbpath
option enablesmongo
to attach directly to local data files and write data without a runningmongod
instance. To run with--dbpath
,mongooplog
needs to restrict access to the data directory: as a result, nomongod
can be access the same path while the process runs.
-
--directoryperdb
¶
Use the
--directoryperdb
in conjunction with the corresponding option tomongod
. This option allowsmongooplog
to write to data files organized with each database located in a distinct directory. This option is only relevant when specifying the--dbpath
option.
-
--journal
¶
Allows
mongooplog
operations to use the durability journal to ensure that the data files will remain in a consistent state during the writing process. This option is only relevant when specifying the--dbpath
option.
-
--fields
[field1[,field2]]
,
-f
[field1[,field2]]
¶ Specify a field or number fields to constrain which data
mongooplog
will migrate. All other fields will be excluded from the migration. Comma separate a list of fields to limit the applied fields.
-
--fieldFile
<file>
¶ As an alternative to “
--fields
” the--fieldFile
option allows you to specify a file (e.g.<file>
) that holds a list of field names to include in the migration. All other fields will be excluded from the migration. Place one field per line.
-
--seconds
<number>
,
-s
<number>
¶ Specify a number of seconds of operations for
mongooplog
to pull from theremote host
. Unless specified the default value is86400
seconds, or 24 hours.
-
--from
<host[:port]>
¶ Specify the host for
mongooplog
to retrieve oplog operations from.mongooplog
requires this option.Unless you specify the
--host
option,mongooplog
will apply the operations collected with this option to the oplog of themongod
instance running on the localhost interface connected to port27017
.
-
--oplogns
<namespace>
¶ Specify a namespace in the
--from
host where the oplog resides. The default value islocal.oplog.rs
, which is the where replica set members store their operation log. However, if you’ve copied oplog entries into another database or collection, use this option to copy oplog entries stored in another location.Namespaces take the form of
[database].[collection]
.
Usage¶
Consider the following prototype mongooplog
command:
Here, entries from the oplog of the mongod
running
on port 27017
. This only pull entries from the last 24 hours.
Use the --seconds
argument to capture
a greater or smaller amount of time. Consider the following example:
In this operation, mongooplog
captures 2 full days of
operations. To migrate 12 hours of oplog entries, use the
following form:
For the previous two examples, mongooplog
migrates entries
to the mongod
process running on the localhost interface
connected to the 27017
port. mongooplog
can also
operate directly on MongoDB’s data files if no mongod
is
running on the target host. Consider the following example:
Here, mongooplog
imports oplog operations from the
mongod
host connected to port 27017
. This migrates
operations to the MongoDB data files stored in the /srv/mongodb
directory. Additionally mongooplog
will use the durability
journal to ensure that the data files remain in a consistent
state.