- Back Up and Restore Deployments >
- Restore MongoDB Deployments >
- Restore a Single Database
Restore a Single Database¶
Overview¶
Backup snapshots contain a complete copy of your mongod data 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.
Note
As of MongoDB 3.0, mongodump and mongorestore
no longer support the --dbpath
option. These tools now
must connect to a running mongod instance.
Considerations¶
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.
Restore Type | Description | Action |
---|---|---|
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. Example If you select |
Select a Date and Time. |
Oplog Timestamp | Creates a custom snapshot based on the timestamp of an
oplog entry (its The oplog entry’s |
Type the following:
|
Click Next.
Choose how to receive the restore files.¶
Select the restore method, format and destination.
Pull Via Secure HTTP |
Important You can skip the remainder of this procedure. |
Push Via Secure Copy | Direct Ops Manager to copy the restore files to your server via
Important
Note Microsoft Windows computers do not include |
Format | 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
the restoreInfo.txt
file.
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:
27017
as the port for a running MongoDB instance that receives the restored backup.27018
as 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 server.
For example:
Start a new, temporary MongoDB process on a new port using the extracted backup snapshot as the dbpath
.¶
Ensure the user executing the mongod can read, write and
execute code in the directory specified with dbpath
.
For example:
Use the mongodump
command to export a single database or collection from the temporary running mongod
process.¶
Specify the single database name using --db
and, if needed, a --collection
for a single collection.
The --out
option specifies where the
mongodump extracts the target database. Choose an empty
directory the user executing mongodump can access.
It also possible to export only a single collection:
Use the mongorestore
command to import the single database or collection.¶
Restore the single database to the desired instance using this mongorestore command:
If you are restoring a single collection, be sure to designate the collection:
Any existing databases matching the name given for the --db
option should be dropped using the --drop
option. If you
choose not to use the --drop
option,
the restore may produce errors for any documents with duplicate _id
fields.
Shutdown the temporary MongoDB instance and remove the temporary database.¶
Start the
mongo
shell.Drop the database and shutdown the process.
Delete the temporary database directory