Docs Menu
Docs Home
/
MongoDB Ops Manager
/ /

Restore a Single Database or Collection

On this page

  • Considerations
  • Restore a Database or Collection from Queryable Backup

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.

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.

Important

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 Ops Manager-provided tunnel [1].

Note

If the Daemon runs without access to the internet, see Configure Deployment to Have Limited Internet Access to install the appropriate binaries.

1

For the deployment whose backup you want to query, click under Options column then select Query.

You can also click the deployment to view its snapshots and click the Query button under the Actions column.

2
  1. Select the snapshot to query and click Next.

  2. Start the process to query a snapshot. You will be prompted for 2-factor verification.

  3. Select Backup Tunnel as the connection method to the queryable snapshot. [1]

  4. Select your Platform and download.

  5. Uncompress the downloaded file.

    Note

    Wait for the Queryable Snapshot to mount before you continue. Snapshot mount time depends on the size of the snapshot. Verify the snapshot is mounted by navigating to Continuous Backup and selecting the Restore History tab. When the snapshot is mounted, the Status column reports the date and time of the mount operation.

  6. 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:

    ./<tunnel executable> --local localhost:27020

    Note

    If you change the port, you must include the port information when connecting.

3
To export the data for a database,

Include the following mongodump 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

  • --out set to an empty directory to output the data dump.

    Important

    Ensure that the user running mongodump can write to the specified directory.

mongodump --port <port for tunnel> --db <single-database> --out <data-dump-path>

Example

To connect to a tunnel running on port 27020 to dump out data from the test database to /mydata/restoredata/ directory:

mongodump --port 27020 --db test --out /mydata/restoredata/

mongodump outputs the test database files into the /mydata/restoredata/test/ directory.

If the mongodump is not in your PATH, specify the path for the tool.

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.

mongodump --port <port for tunnel> \
--db <single-database> \
--collection <collection-name> \
--out <data-dump-path>

Example

To connect to a tunnel running on port 27020 to dump out data from the restaurants collection from test database to /mydata/restoredata/ directory:

mongodump --port 27020 \
--db test \
--collection restaurants \
--out /mydata/restoredata/

mongodump outputs the restaurants collection data into the /mydata/restoredata/test/restaurants.bson file.

4
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.

mongorestore --port <port> --db <destination database> <data-dump-path/database> --drop

For example, to restore from the /mydata/restoredata/test directory to a new database restoredTest:

mongorestore --port 27017 --db restoredTest /mydata/restoredata/test --drop

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.

mongorestore --port <port> --db <destination database> --collection <collection-name> <data-dump-path/dbname/collection.bson> --drop

For example, to restore from the /mydata/restoredata/test/restaurants.bson data file to a new collection rest2 in the test2 database:

mongorestore --port 27017 --db test2 --collection rest2 /mydata/restoredata/test/restaurants.bson --drop

The example assumes that the destination replica set's primary or the destination sharded cluster's mongos listens on port 27017.

5

Once you have finished, you can terminate the queryable instance:

  1. Go to the Restore History and hover over the Status column for the deployment item.

  2. Click Cancel.

[1](1, 2, 3, 4) 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.

Important

Rotate Master Key after Restoring Snapshots Encrypted with AES256-GCM

If you restore an encrypted snapshot that Ops Manager encrypted with AES256-GCM, rotate your master key after completing the restore.

Back

Query a Backup Snapshot