- Back Up and Restore Deployments >
- Restore MongoDB Deployments >
- Restore a Single Database or Collection
Restore a Single Database or Collection¶
To restore a single database or a collection (or specific documents) from a snapshot, you can use the Queryable Backup to export a single database or collection to restore to the target deployment.
Considerations¶
Before you attempt a restore, ensure the host for your target deployment has sufficient storage space for the restore files and the restored database, plus additional space for dataset growth. Use db.stats() to find the current database size.
Restore a Database or Collection from Queryable Backup¶
You can use a queryable backup snapshot to export data for a database or a collection and restore to the target deployment. The following procedure connects to the queryable backup instance via Cloud Manager-provided tunnel [1].
Go to Backup view and click the Overview tab.¶
For the deployment whose backup you want to query, click Options column then select Query.
underYou can also click the deployment to view its snapshots and click the Query button under the Actions column.
Open a Backup Tunnel to the Queryable Snapshot.¶
Select the snapshot to query and click Next.
Start the process to query a snapshot. You will be prompted for 2-factor verification.
Select Backup Tunnel as the connection method to the queryable snapshot. [1]
Select your Platform and download.
Uncompress the downloaded file.
Open a terminal or command prompt and go to the uncompressed <tunnel> directory. Run the executable to start the tunnel.
The default port for the tunnel is
27017
. To change the port, use the--local
flag, as in the following example:Note
If you change the port, you must include the port information when connecting.
Use mongodump
to export a single database or collection from the queryable backup.¶
- To export the data for a database,
Include the following
mongodump
options to connect to the tunnel [1]:- To export the data for a collection,
include the following options to connect to the tunnel [1]:
--port
set to the port for the tunnel.--db
set to the name of the database to export.--collection
for a single collection.--out
set to an empty directory to output the data dump.Important
Ensure that the user running
mongodump
can write to the specified directory.
Example
To connect to a tunnel running on port
27020
to dump out data from therestaurants
collection fromtest
database to/mydata/restoredata/
directory:mongodump
outputs therestaurants
collection data into the/mydata/restoredata/test/restaurants.bson
file.
Use mongorestore
to restore the single database or collection.¶
- To restore a single database,
Include the following
mongorestore
options:--port
set to the port of the destination cluster.--db
set to the name of the destination database.
Optionally, you can include
--drop
to drop the database in the destination cluster if the database already exists.
For example, to restore from the /mydata/restoredata/test
directory to a new database restoredTest
:
The example assumes that the destination replica set’s primary or
the destination sharded cluster’s mongos
listens on port
27017
.
- To restore a single collection,
Include the following
mongorestore
options:--port
set to the port of the destination cluster.--db
set to the name of the destination database.
Optionally, you can include
--drop
to drop the collection in the destination cluster if the collection already exists.
For example, to restore from the
/mydata/restoredata/test/restaurants.bson
data file to a new
collection rest2
in the test2
database:
The example assumes that the destination replica set’s primary or
the destination sharded cluster’s mongos
listens on port
27017
.
Terminate the queryable instance.¶
Once you have finished, you can terminate the queryable instance:
- Go to the Restore History and hover over the Status column for the deployment item.
- Click Cancel.
[1] | (1, 2, 3, 4, 5, 6, 7) Alternatively, instead of connecting via the tunnel, you can connect directly to the queryable backup, using the X.509 PEM files provided. If connecting directly to the queryable backup, you must specify the hostname and port, the TLS/SSL option, and the X.509 certificates. |
Rotate Master Key after Restoring Snapshots Encrypted with AES256-GCM
If you restore an encrypted snapshot that Cloud Manager encrypted with AES256-GCM, rotate your master key after completing the restore.