- Back Up and Restore Deployments >
- Restore MongoDB Deployments >
- Restore a Replica Set from a Backup
Restore a Replica Set from a Backup¶
On this page
Overview¶
When you restore a replica set from backup, Ops Manager provides you with a restore file for the selected restore point. For an overview of the restore process, please see Restore Overview.
Considerations¶
The BSON specification changed the
default subtype for the BSON binary datatype (BinData
) from 2
to 0
. Some binary data stored in a snapshot may be BinData
subtype 2. The Backup Agent automatically detects and converts snapshot
data in BinData
subtype 2 to BinData
subtype 0. If your
application code expects BinData
subtype 2, you must update your
application code to work with BinData
subtype 0.
See also
The notes on the BSON specification explain the particular specifics of this change.
Prerequisites¶
Oplog Size¶
To seed each replica set member, you will use the
seedSecondary.sh
or seedSecondary.bat
script included
in the backup restore file. When you run the script, you will provide
the replica set’s oplog size, in gigabytes.
See also
See the Check the Size of the Oplog section of the Troubleshoot Replica Sets if you do not have the size.
Client Requests During Restoration¶
You must ensure that the MongoDB deployment does not receive client requests during restoration. You must either:
- Restore to new systems with new hostnames and reconfigure your application code once the new deployment is running, or
- Ensure that the MongoDB deployment will not receive client requests while you restore data.
Secure Copy (SCP
) Delivery¶
Important
SCP
requires you to
generate a key pair
before attempting to transfer files. SCP
provides faster file
delivery than HTTP
.
Note
Microsoft Windows computers do not include SCP
and require
additional setup outside the scope of this manual.
Procedures¶
To have Ops Manager automatically restore the backup, perform the select the snapshot procedure.
To restore the backup manually, perform all the following procedures sequentially. If you restore to existing hardware, use a different data directory than used previously.
See also
See Restore a Replica Set from a Backup for alternative approaches to restoring replica sets.
Select the Snapshot¶
Select the Backup tab and then Overview page.¶
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.
Select whether to have Ops Manager restore the snapshot.¶
Yes | Ops Manager restores the snapshot for you. If you select this option, Ops Manager prompts to choose the replica set to which to restore. You can select an existing replica set or create a new one. Follow the prompts in the wizard. Important You can skip the remainder of this page. |
No, I’ll do it myself | Ops Manager provides you with the restore files for you to perform the restore manually. |
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. |
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 specfied. To verify that the files are complete, see how to validate a secure copy restore.
Copy the snapshot to each replica set member to restore.¶
Restore the Primary¶
You must have a copy of the snapshot on the server that provides the primary. Use this procedure only for manual restores.
Shut down the entire replica set.¶
Shut down the replica set’s mongod processes using one of the following methods, depending on your configuration:
Automated Deployment¶
If you use Ops Manager Automation to manage the replica set, you must shut down through the Ops Manager console. See Shut Down a MongoDB Process.
Non-Automated Deployment on MongoDB 2.6 or Later¶
Connect to each member of the set and issue the following:
Non-Automated Deployment on MongoDB 2.4 or earlier¶
Connect to each member of the set and issue the following:
Restore the snapshot data files to the primary.¶
Extract the data files to the location where the mongod
process will access them through the dbpath
setting. If you
are restoring to existing hardware, use a different data directory than
used previously. The following are example commands:
Start the primary with the new dbpath
.¶
For example:
Connect to the primary and initiate the replica set.¶
Connect using the mongo
shell and issue the rs.initiate()
command.
Restart the primary as a standalone, without the --replSet
option.¶
Shut down the process using one of the following methods:
Automated Deployment¶
Shut down through the Ops Manager console. See Shut Down a MongoDB Process.
Non-Automated Deployment on MongoDB 2.6 or Later¶
Non-Automated Deployment on MongoDB 2.4 or earlier¶
Restart the process as a standalone:
Run the seedSecondary
script on the primary.¶
Use the appropriate script for your operating system:
UNIX-based | seedSecondary.sh |
Windows | seedSecondary.bat |
This script recreates the oplog collection and seeds it with the timestamp of the snapshot’s creation. This tells the secondary to recreate all operations to the current time without requiring a full initial sync. Ops Manager customizes this script for this particular snapshot and includes it in the snapshot archive.
To run the script, issue the following command, where:
<alternatePort> |
The port of the mongod process |
<oplogSizeInGigabytes> |
The size of the replica set’s oplog |
<replicaSetName> |
The name of the replica set |
<primaryHost:primaryPort> |
The hostname:port combination for the replica set’s primary |
For UNIX-based systems:¶
For Windows-based systems:¶
Restart the primary as part of a replica set.¶
Use the following sequence:
Shut down the process using one of the following methods:
Automated Deployment:
Shut down through the Ops Manager console. See Shut Down a MongoDB Process.
Non-Automated Deployment on MongoDB 2.6 or Later:
Non-Automated Deployment on MongoDB 2.4 or earlier:
Restart the process as part of a replica set:
Restore Each Secondary¶
After you have restored the primary you can restore all secondaries. You must have a copy of the snapshot on all servers that provide the secondaries. Use this procedure only for manual restores.
Connect to the server where you will create the new secondary.¶
Restore the snapshot data files to the secondary.¶
Extract the data files to the location where the mongod
process will access them through the dbpath
setting. If you
are restoring to existing hardware, use a different data directory than
used previously. The following are example commands:
Start the secondary as a standalone, without the --replSet
option.¶
Shut down the process using one of the following methods:
Automated Deployment¶
Shut down through the Ops Manager console. See Shut Down a MongoDB Process.
Non-Automated Deployment on MongoDB 2.6 or Later¶
Non-Automated Deployment on MongoDB 2.4 or earlier¶
Restart the process as a standalone:
Run the seedSecondary.sh
script on the secondary.¶
Use the appropriate script for your operating system:
UNIX-based | seedSecondary.sh |
Windows | seedSecondary.bat |
This script recreates the oplog collection and seeds it with the timestamp of the snapshot’s creation. This tells the secondary to recreate all operations to the current time without requiring a full initial sync. Ops Manager customizes this script for this particular snapshot and includes it in the snapshot archive.
To run the script, issue the following command, where:
<alternatePort> |
The port of the mongod process |
<oplogSizeInGigabytes> |
The size of the replica set’s oplog |
<replicaSetName> |
The name of the replica set |
<primaryHost:primaryPort> |
The hostname:port combination for the replica set’s primary |
For UNIX-based systems:¶
For Windows-based systems:¶
Restart the secondary as part of the replica set.¶
Use the following sequence:
Shut down the process using one of the following methods:
Automated Deployment:
Shut down through the Ops Manager console. See Shut Down a MongoDB Process.
Non-Automated Deployment on MongoDB 2.6 or Later:
Non-Automated Deployment on MongoDB 2.4 or earlier:
Restart the process as part of a replica set:
Connect to the primary and add the secondary to the replica set.¶
Connect to the primary and use rs.add()
to add the secondary
to the replica set.
Repeat this operation for each member of the set.