Navigation
  • Restoration >
  • Restore a Database or Collection from Queryable Backup

Restore a Database or Collection from Queryable Backup

On this page

Note

This feature is not available for M0 (Free Tier), M2, and M5 clusters. For more information, see Atlas M0 (Free Tier), M2, and M5 Limitations.

Overview

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 an Atlas-provided tunnel.

Procedure

1

Click Backup in the left navigation pane and click the Overview tab.

For the deployment whose backup you want to query, click the ellipsis in the Options column and select Query.

You can also click View All Snapshots to view its snapshots and click Query under the Actions column for the desired snapshot.

2

Open a Backup Tunnel to the Queryable Snapshot.

  1. Select the snapshot to query and click Next.

  2. Start the process to query a snapshot. You will be prompted to enter your Atlas password.

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

  4. Select your Platform.

  5. Click Download Backup Tunnel.

  6. Uncompress the downloaded file.

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

Use mongodump to export a single database or collection from the queryable backup.

To export the data from a database:

Include the following mongodump options to connect to the tunnel:

  • --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>

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

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

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

If mongodump is not in your $PATH, specify the path for the tool when running the command.

To export the data for a collection:

Include the following options to connect to the tunnel:

  • --port set to the port for the tunnel.

  • --db set to the name of the database to export.

  • --collection set to the name of the collection 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> --collection <collection-name> --out <data-dump-path>

For 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

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 the --drop option 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.
  • --collection set to the name of the destination collection.

Optionally, you can include the --drop option to drop the collection in the destination cluster if the collection already exists.

mongorestore --port <port> --db <destination-database> --collection <destination-collection> <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

Terminate the queryable instance.

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

  1. Click Backup in the left navigation pane and click the Restore History tab.
  2. Hover over the Status column for the target deployment item and click Cancel.
  3. Click Cancel Restore Job.
←   Restore a Cluster Billing  →