Originally posted by: AilbheCashell
Looking for a granular restore operation for your MongoDB collections and databases? Look no further.
You can restore specific MongoDB databases or collections with a granular restore operation using IBM Spectrum Protect™ Plus. To restore at this granular level, first run a test restore job with IBM Spectrum Protect™ Plus; then run the appropriate MongoDB commands shown in this procedure.
Before you begin
Before you start, ensure that you allowed enough disk space and allocated dedicated volumes for the copying of files.
Tip: When you are restoring data to an alternative instance and the Overwrite existing databases option is not selected, the process fails if any data is found on the local database directory you are restoring to.
About this task
Important: If your MongoDB database runs on a port other than the default port (27017), a restore operation to the original location with the overwrite option restores the MongoDB database to port 27017. It does not restore the database to the same port that it ran on in the original instance. You can stop the restored instance and restart it with the MongoDB configuration file to run it on the original port.
Procedure
- In the navigation menu, expand Manage Protection > Applications > MongoDB > Restore.
- In the MongoDB Restore pane, click the instance that you want to restore. Expand ALL to show the restore points that are available for that instance.
- Click Options and choose Destination > Restore to alternate instance.
- Choose a Test Restore Type. In this mode, a database is created using the MongoDB data files directly from the vSnap repository. This option is available only when you are restoring to an alternative instance. Members of replica sets will not be reconfigured after the MongoDB server is started. The server is started as a single-node replica set.
- Select the target instance that you want to restore the data to. The original instance is not selectable as you cannot overwrite the original data when you select Restore to alternate instance. Instances on different versions levels cannot be selected. Other instances on the same host as the original instance, cannot be selected either.
- Optional: Rename the new database in the New Database Name field.
- Optional: Choose an alternative vSnap server for the restore operation when you are restoring a restore point that is not the most recent copy. Select Use alternate vSnap server for the restore job, and choose a server from the menu.
- Optional: Choose Overwrite existing databases during a restore operation to replace existing data during the recovery. If this option is not selected, the restore job fails when data with the same name is found during the restore process.
- Edit Advanced Options as follows:
- Run cleanup immediately on job failure to automatically clean up allocated resources as part of a restore operation in case the recovery fails.
- Allow session overwrite to replace existing databases with the same name during a restore operation. During an instance disk restore operation, the existing database is shut down and overwritten, and then the recovered database is restarted. If this option is not selected and a database with the same name is encountered, the restore operation fails with an error.
- Continue with restores of other selected databases even if one fails to continue the process is a database fails to restore. When this option is not selected, the restore job stops when the recovery of a resource fails.
- Protocol Priority, for instant access restore operations, specify a protocol priority by choosing iSCSI or Fibre Channel as the priority protocol to be used for the restore job.
- Mount Point Prefix for Instant Access restore operations, specify a mount point prefix for the path where the mount is to be directed.
- Optional: Define Scripts Settings as follows:
- Select Pre-script to select an uploaded script and an application or script server where the script will run. To select an application server where the script will run, clear the Use Script Server check box. Scripts and script servers are configured through the System Configuration > Script page
- Select Post-script to select an uploaded script and an application or script server where the script will run. To select an application server where the script will run, clear the Use Script Server check box. Scripts and script servers are configured through the System Configuration > Script page.
- Select Continue job/task on script error to continue running the job when the script associated with the job fails.
- When all the options are chosen, click Save.
- To run the job immediately, click Restore. To specify a schedule for repeated restore sessions, click Manage Jobs to define a trigger for the job. To cancel the job, navigate to Jobs and Operations and click the Policy and Job List tab. Find the restore job you want to cancel. Click Actions > Cancel.
- Log on to the MongoDB server to which the test restore job is directed.
- Run the MongoDB system command
ps -ef | grep mongod
to find the temporary recovery MongoDB instance location. - Run the MongoDB
mongodump
command to create a dump file of any specific database or collection.
Use one of these commands. The first command is for a database and the second command is for a collection:
mongodump --host <
hostname> --port <
port> --db <
dbname> <
dumpfolder>
Or,
mongodump --host <
hostname> --port <
port> --collection <
collectionname> <
dumpfolder>
16. Run the mongorestore command to restore the dump file into any MongoDB instance. Choose either the original MongoDB instance that the backup was created for, or any alternative instance.
Use one of these commands. The first command is for a database and the second command is for a collection:
mongorestore --host <
hostname> --port <
port> --db <
dbname> <
dumpfolder>\<
dbname>
Or,
mongorestore --host <
hostname> --port <
port> --collection <
collectionname> <
dumpfolder>\<
dbname>
17. When the database or collection restore operation finishes, go to Jobs and Operations > Active Resources.
18. Click Actions > Cancel Restore to end the granular restore procedure.