Start-VEMDBRestoreJob

Short Description

Restores MongoDB collections or the entire MongoDB instance.

Applies to

Veeam Backup & Replication

Product Edition: Enterprise Plus, Veeam Universal License

Syntax

This cmdlet provides parameter sets that allow you to:

  • Restore collections to a target MongoDB deployment.

Start-VEMDBRestoreJob [-Collections] <VEMDBCollectionRestoreOptions[]> [-InstancePort <Int32>] [-InstanceCredentials] <PSCredential> [-Server <String>][-SshPort <Int32>] -Credential <VEMDBLinuxCredentials> [-UseTLS] [-RestoreAdminDatabase] [-Force] [<CommonParameters>]

  • Restore an entire MongoDB instance to a target Linux machine with MongoDB.

Start-VEMDBRestoreJob [-Session] <VEMDBRestoreSession> [[-DataFolderPath] <String>] [-InstancePort <Int32>] [-Server <String>] [-SshPort <Int32>] -Credential <VEMDBLinuxCredentials> [-Force] [<CommonParameters>]

Detailed Description

This cmdlet restores backed-up MongoDB collections or the entire backed-up MongoDB instance. After you start a restore job, you can stop the restore process with the Stop-VEMDBRestoreJob cmdlet.

Parameters

Parameter

Description

Type

Required

Position

Accept Pipeline Input

Collections

For collections restore.

Specifies the collections and their restore options.

Accepts the VEMDBCollectionRestoreOptions[] object. To get this object, run the New-VEMDBCollectionRestoreOptions cmdlet.

True

0

False

Session

For instance restore.

Specifies a restore session initiated to perform operations with MongoDB.

Accepts the VEMDBRestoreSession object. To get this object, run the Get-VEMDBRestoreSession cmdlet.

True

0

False

InstanceCredentials

For collections restore.

Specifies the credentials for the target MongoDB instance.

Note: The user must have the root MongoDB role on the target replica set.

Accepts the PSCredential object. To get this object, run the Get-Credential cmdlet.

True

1

False

DataFolderPath

For instance restore.

Specifies the path to which the cmdlet will restore the MongoDB instance.

Note: If you do not specify this parameter, the instance will be restored to the original location.

String

False

1

False

Credential

Specifies credentials for authenticating to the primary node of the MongoDB deployment or the target MongoDB server.

Note: The user must have root privileges on the target server.

Accepts the VEMDBLinuxCredentials object. To get this object, run the New-VEMDBLinuxCredentials cmdlet.

True

Named

False

Force

Defines that the cmdlet will overwrite existing MongoDB data with data from the backup.

Note: The cmdlet will show no prompt before executing the command.

SwitchParameter

False

Named

False

InstancePort

Specifies the port of the target MongoDB instance.

Default: 27017

Int

False

Named

False

RestoreAdminDatabase

For collections restore.

Defines that the cmdlet will restore the admin database.

SwitchParameter

False

Named

False

Server

Specifies the DNS name or IP address of the primary node of the target MongoDB deployment or the target MongoDB server.

String

False

Named

False

SshPort

Specifies the SSH port number that the cmdlet will use to connect to the Linux machine.

Default: 22

Int

False

Named

False

UseTLS

For collections restore.

Defines that the cmdlet will connect to the target MongoDB deployment using a secure TLS protocol.

SwitchParameter

False

Named

False

<CommonParameters>

This cmdlet supports Microsoft PowerShell common parameters. For more information on common parameters, see the About CommonParameters section of Microsoft Docs.

Output Object

The cmdlet returns the VEMDBRestore object, that contains information about the status of the MongoDB restore job.

Examples

Start-VEMDBRestoreJobExample 1. [For Collections Restore] Restoring Specific Collection With Default Settings

This example shows how to restore a MongoDB collection to the original location. The collection will retain the original name. This example will also restore the admin database to the original location.

$session = Get-VEMDBRestoreSession

$database = Get-VEMDBDatabase -Session $session[0] -Name "employees"

$collection = Get-VEMDBCollection -Database $database

$restoreoptions = New-VEMDBCollectionRestoreOptions -Collection $collection[0] -NewCollectionName "home office"

$instancecreds = Get-Credential

$securepassword = Read-Host -Prompt "Enter password" -AsSecureString

$servercreds = New-VEMDBLinuxCredentials -Account "root" -Password $securepassword

$restore = Start-VEMDBRestoreJob -Collections $restoreoptions -InstanceCredentials $instancecreds -Server mongodb02 -Credential $servercreds -RestoreAdminDatabase

Perform the following steps:

  1. Run the Get-VEMDBRestoreSession cmdlet. Save the result to the $session variable.

The cmdlet will return an array of active restore sessions. Note the ordinal number of the necessary restore session. In our example, it is the first restore session in the array.

  1. Run the Get-VEMDBDatabase cmdlet. Set the $session variable as the Session parameter value and select the necessary session. Specify the Name parameter value. Save the result to the $database variable.
  2. Run the Get-VEMDBCollection cmdlet. Set the $database variable as the Database parameter value. Save the result to the $collection variable.
  3. Run the New-VEMDBCollectionRestoreOptions cmdlet. Set the $collection variable as the Collection parameter value and specify the necessary collection. Specify the NewCollectionName parameter value. Save the result to the $restoreoptions variable.
  4. Run the Get-Credential cmdlet to specify the credentials to authenticate to the MongoDB replica set. Save the result to the $instancecreds variable.
  5. Run the Read-Host cmdlet. Specify the Prompt parameter value. Provide the AsSecureString parameter. Save the result to the $securepassword variable.
  6. Run the New-VEMDBLinuxCredentials cmdlet. Specify the Account parameter value. Set the $securepassword variable as the Password parameter value. Save the result to the $servercreds variable.
  7. Run the Start-VEMDBRestoreJob cmdlet. Specify the following settings:
  • Set the $restoreoptions variable as the Collections parameter value.
  • Set the $instancecreds variable as the InstanceCredentials parameter value.
  • Specify the Server parameter value.
  • Set the $servercreds variable as the Credential parameter value.
  • Provide the RestoreAdminDatabase parameter.

Save the result to the $restore variable to be able to use it with other cmdlets.

Start-VEMDBRestoreJobExample 2. [For Collections Restore] Restoring All Collections in a Replica Set With Default Settings

This example shows how to restore all MongoDB collections in the replica set to the original location. Each collection will be restored with the original name, to the same database as on the backup. If any of the collections exist on the target server, the cmdlet will overwrite them without issuing a prompt.

$session = Get-VEMDBRestoreSession

$collections = Get-VEMDBCollection -Session $session[0]

$restoreoptionsarray = @()

foreach ($collection in $collections) {

   $restoreoption = New-VEMDBCollectionRestoreOptions -Collection $collection

   $restoreoptionsarray += $restoreoption

}

$instancecreds = Get-Credential

$securepassword = Read-Host -Prompt "Enter password" -AsSecureString

$servercreds = New-VEMDBLinuxCredentials -Account "root" -Password $securepassword

$restore = Start-VEMDBRestoreJob -Collections $restoreoptionsarray -InstanceCredentials $instancecreds -Server mongodb02 -Credential $servercreds -Force

Perform the following steps:

  1. Run the Get-VEMDBRestoreSession cmdlet. Save the result to the $session variable.

The cmdlet will return an array of restore sessions. Note the ordinal number of the necessary restore session. In our example, it is the first restore session in the array.

  1. Run the Get-VEMDBCollection cmdlet. Set the $session variable as the Session parameter value and select the necessary restore session. Save the result to the $collections variable.
  2. Declare the $restoreptionsarray variable. Assign an empty array to this variable.
  3. Run the New-VEMDBCollectionRestoreOptions cmdlet and set the $collection variable as the Collection parameter value. Use the ForEach statement to apply the same restore options to each collection in the $collections variable.
  4. Run the Get-Credential cmdlet to specify the credentials to authenticate to the MongoDB replica set. Save the result to the $instancecreds variable.
  5. Run the Read-Host cmdlet. Specify the Prompt parameter value. Provide the AsSecureString parameter. Save the result to the $securepassword variable.
  6. Run the New-VEMDBLinuxCredentials cmdlet. Specify the Account parameter value. Set the $securepassword variable as the Password parameter value. Save the result to the $servercreds variable.
  7. Run the Start-VEMDBRestoreJob cmdlet. Specify the following settings:
  • Set the $restoreoptionsarray variable as the Collections parameter value.
  • Set the $instancecreds variable as the InstanceCredentials parameter value.
  • Specify the Server parameter value.
  • Set the $servercreds variable as the Credential parameter value.
  • Provide the Force parameter.

Save the result to the $restore variable to be able to use it with other cmdlets.

Start-VEMDBRestoreJobExample 3. [For Collections Restore] Restoring Collections With Custom Restore Options

This example shows how to restore specific MongoDB collections to another location. The collections will be restored with different names, to a new database. This example uses a custom SSH port to connect to the target server and it will use the TLS protocol to connect to the target MongoDB deployment.

$session = Get-VEMDBRestoreSession

$database = Get-VEMDBDatabase -Session $session[0] -Name "locations"

$collections = Get-VEMDBCollection -Database $database

$restoreoption1 = New-VEMDBCollectionRestoreOptions -Collection $collections[0] -NewCollectionName "kyoto" -NewDatabaseName "users"

$restoreoption2 = New-VEMDBCollectionRestoreOptions -Collection $collections[1] -NewCollectionName "sydney" -NewDatabaseName "users"

$restoreoptionsarray = @($restoreoption1, $restoreoption2)

$instancecreds = Get-Credential

$securepassword = Read-Host -Prompt "Enter password" -AsSecureString

$servercreds = New-VEMDBLinuxCredentials -Account "root" -Password $securepassword

$restore = Start-VEMDBRestoreJob -Collections $restoreoptionsarray -InstanceCredentials $instancecreds -Server "srv18" -Credential $servercreds -InstancePort 27017 -SshPort 23 -UseTLS

Perform the following steps:

  1. Run the Get-VEMDBRestoreSession cmdlet. Save the result to the $session variable.

The cmdlet will return an array of active restore sessions. Note the ordinal number of the necessary restore session. In our example, it is the first restore session in the array.

  1. Run the Get-VEMDBDatabase cmdlet. Set the $session variable as the Session parameter value and select the necessary session. Specify the Name parameter value.
  2. Run the Get-VEMDBCollection cmdlet. Set the $database variable as the Database parameter value.
  3. Run the New-VEMDBCollectionRestoreOptions cmdlet. Set the $collection variable as the Collection parameter value and specify the necessary collection. Specify the NewCollectionName parameter value. Save the result to the $restoreoptions1 variable to use it with other cmdlets.
  4. Run the New-VEMDBCollectionRestoreOptions cmdlet. Set the $collection variable as the Collection parameter value and specify the necessary collection. Specify the NewCollectionName parameter value. Save the result to the $restoreoptions2 variable to use it with other cmdlets.
  5. Declare the $restoreptionsarray variable. Assign the $restoreoptions1 and $restoreoptions2 variables to this variable.
  6. Run the Get-Credential cmdlet to specify the credentials to authenticate to the MongoDB replica set. Save the result to the $instancecreds variable.
  7. Run the Read-Host cmdlet. Specify the Prompt parameter value. Provide the AsSecureString parameter. Save the result to the $securepassword variable.
  8. Run the New-VEMDBLinuxCredentials cmdlet. Specify the Account parameter value. Set the $securepassword variable as the Password parameter value. Save the result to the $servercreds variable.
  9. Run the Start-VEMDBRestoreJob cmdlet. Specify the following settings:
  • Set the $restoreoptionsarray variable as the Collections parameter value.
  • Set the $instancecreds variable as the InstanceCredentials parameter value.
  • Specify the Server parameter value.
  • Set the $servercreds variable as the Credential parameter value.
  • Specify the InstancePort parameter value.
  • Specify the SshPort parameter value.
  • Provide the UseTLS parameter.

Save the result to the $restore variable to be able to use it with other cmdlets.

Start-VEMDBRestoreJobExample 4. [For Instance Restore] Restoring Entire MongoDB Instance

This example shows how to restore the entire instance to a target Linux machine with MongoDB. If the specified path on the target server is not empty, the cmdlet will overwrite its contents without issuing a prompt.

$session = (Get-VEMDBRestoreSession)[0]

$securepassword = Read-Host -Prompt "Enter password" -AsSecureString

$servercreds = New-VEMDBLinuxCredentials -Account "root" -Password $securepassword

$restore = Start-VEMDBRestoreJob -Session $session -DataFolderPath "/var/lib/mongodb" -InstancePort 27018 -Server "mongodb01" -SshPort 23 -Credential $servercreds -Force

Perform the following steps:

  1. Run the Get-VEMDBRestoreSession cmdlet. Select the necessary restore session returned by this command and save it to the $session variable. In our example, it is the first session in the array.
  1. Run the Read-Host cmdlet. Specify the Prompt parameter value. Provide the AsSecureString parameter. Save the result to the $securepassword variable.
  2. Run the New-VEMDBLinuxCredentials cmdlet. Specify the Account parameter value. Set the $securepassword variable as the Password parameter value. Save the result to the $servercreds variable.
  3. Run the Start-VEMDBRestoreJob cmdlet. Specify the following settings:
  • Set the $session variable as the Session parameter value.
  • Specify the DataFolderPath parameter value.
  • Specify the InstancePort parameter value.
  • Specify the Server parameter value.
  • Specify the SshPort parameter value.
  • Set the $servercreds variable as the Credential parameter value.
  • Provide the Force parameter.

Save the result to the $restore variable to be able to use it with other cmdlets.

Related Commands

Page updated 8/14/2024

Page content applies to build 12.2.0.334