Restore a Single Database¶
Backup snapshots contain a complete copy of your
directory. There may be occasions when you want to restore only part of
the data in a snapshot. To restore a single database instead of all
databases in the snapshot, load the snapshot first to a temporary
mongod instance and then export from this instance the
single database. Use the export of the single database to restore to
the target deployment.
As of MongoDB 3.0,
no longer support the
--dbpath option. These tools now
must connect to a running
Before you attempt a restore, ensure your target storage has sufficient space for the restore files and the restored database, plus additional space for dataset growth. Use db.stats() to find the current database size.
Select and Download a Snapshot¶
Click Backup, then the Overview tab.¶
Click the deployment’s ellipsis icon and select Restore.¶
Select the restore point.¶
Choose the point from which you want to restore your backup.
|Snapshot||Allows you to choose one stored snapshot.||Select an existing snapshot to restore.|
|Point In Time||
Creates a custom snapshot that includes all operations up to but not including the selected time.
If you select
|Select a Date and Time.|
Creates a custom snapshot based on the timestamp of an
oplog entry (its
The oplog entry’s
Type the following:
Choose how to receive the restore files.¶
Select the restore method, format and destination.
|Pull Via Secure HTTP||
You can skip the remainder of this procedure.
|Push Via Secure Copy||
Direct Ops Manager to copy the restore files to your server via
Microsoft Windows computers do not include
Select the format in which you want to receive the restore files:
|SCP Host||Type the hostname of the server to receive the files.|
|SCP Port||Type the port of the server to receive the files.|
|SCP User||Type the username used to access to the server.|
|Auth Method||Select whether to use a username and password or an SSH certificate to authenticate to the server.|
|Password||Type the user password used to access to the server.|
|Passphrase||Type the SSH passphrase used to access to the server.|
|Target Directory||Type the absolute path to the directory on the server to which to copy the restore files.|
If the snapshot is encrypted, the restore panel displays the KMIP
master key id and the KMIP server information. You can also find
the information when you view the snapshot itself as well as in
Click Finalize Request.
Retrieve the snapshot.¶
- If you selected Pull Via Secure HTTP:
Ops Manager creates a link to the snapshot. By default, this link is available for an hour and can be used just once. To download the snapshot:
- Click Backup, then the Restore History tab.
- When the restore job completes, select the download link next to the snapshot.
- If you selected Push Via Secure Copy:
- The files are copied to the server directory you specified. To verify that the files are complete, see how to validate a secure copy restore.
Restore the Database¶
The following examples use:
27017as the port for a running MongoDB instance that receives the restored backup.
27018as the port for the temporary MongoDB instance that uses the snapshot to export the single database.
Restore the snapshot data files to the server.¶
Extract the snapshot archive to a temporary location where a temporary
mongod process will access the archive contents. Use a
different data directory than any other database running on the
tar -xvf <backupRestoreName>.tar.gz mv <backupRestoreName> <temp-database-path>
Start a new, temporary MongoDB process on a new port using the extracted backup snapshot as the
Ensure the user executing the
mongod can read, write and
execute code in the directory specified with
mongod --port 27018 --dbpath <temp-database-path> --logpath <temp-database-path>/mongodb.log --fork
mongodump command to export a single database or collection from the temporary running
Specify the single database name using
--db and, if needed, a
--collection for a single collection.
--out option specifies where the
mongodump extracts the target database. Choose an empty
directory the user executing
mongodump can access.
mongodump --port 27018 --db <single-database> --out <new-database-path>
It also possible to export only a single collection:
mongodump --port 27018 --db <single-database> --collection <collection-name> --out <new-database-path>
mongorestore command to import the single database or collection.¶
Restore the single database to the desired instance using this
mongorestore --port 27017 --db <single-database> <temp-database-path> --drop
If you are restoring a single collection, be sure to designate the collection:
mongorestore --port 27017 --db <single-database> --collection <collection-name> <temp-database-path> --drop
Any existing databases matching the name given for the
option should be dropped using the
--drop option. If you
choose not to use the
the restore may produce errors for any documents with duplicate _id
Shutdown the temporary MongoDB instance and remove the temporary database.¶
Drop the database and shutdown the process.
admin = db.getSiblingDB("admin") admin.shutdownServer() exit
Delete the temporary database directory
rm -rf <temp-database-path>