Recover SQL Databse from Shell from specific date RRS feed

  • Question

  • Hi everyone!

    I am working on this for hours now - I want to restore the data from a protection group with the management shell. This works fine with recoverableitems and searchoptions for exchange and files, but not for SQL. If I try to do exactly the same as I do for Exchange, PS exits with a nullpointerexception. Here some code:

    if($"Exchange")) {
                    Write-Host "Trying to recover an  Exchange Database"
                    $RecoveryOption = New-RecoveryOption -TargetServer $DestinationServer -RecoveryType Restore -RecoveryLocation CopyToFolder -E14Datasource -ExchangeOperationType NoOperation -TargetLocation $DestinationLocation
                    $SearchOption = New-SearchOption -location $ -FromRecoveryPoint $searchFrom -ToRecoveryPoint $searchTo -SearchDetail MailboxByDisplayName -SearchType contains -SearchString "Mailbox" -recursive
                    $RecoverAbleItem = Get-RecoverableItem -Datasource $DataSourceItem -SearchOption $SearchOption
                } elseif ($"Volume")) {
                    Write-Host "Trying to recover a fileshare"
                    $RecoveryOption = New-RecoveryOption -TargetServer $DestinationServer -AlternateLocation $DestinationLocation -RecoveryLocation CopyToFolder -OverwriteType overwrite -FileSystem -RecoveryType Restore
                    $SearchOption = New-SearchOption -location $ -FromRecoveryPoint $searchFrom -ToRecoveryPoint $searchTo -SearchDetail filesfolders -SearchType contains -SearchString ".docx" -recursive
                    $RecoverAbleItem = Get-RecoverableItem -Datasource $DataSourceItem -SearchOption $SearchOption
                if ($RecoverAbleItem) {
                    $RestoreJob = Recover-RecoverableItem -RecoverableItem $RecoverAbleItem -RecoveryOption $RecoveryOption
                } else {Write-Host "No recoverable item could be found"}

    If I add a similar part for SQL, ps quits at the creation of the recoverableitem. Has anyone a clue hot to restore a specifyable point in time? I can sort the recoverypoints and take the first or last one - no problem, but I want to enter a date and the recover this specific RP.

    Thx a lot for your help ppl!


    Sunday, January 30, 2011 3:51 PM

All replies

  • Hi Andreas,

    Some things to remember for SQL - following cmdlets cannot be used for SQL restore -  Get-RecoverableItem and New-SearchOption

    Following is a snippet about SQL restore ps script should look like -

    $rstemp = @(Get-RecoveryPoint -Datasource $dsList[0]) ; $RecoverAbleItem = $rstemp[0] 
    #Sample values for parameters : $targetserver= $psname, $recoveryLocation = OriginalServer ,  $restoreType = "Recover", $library = #=$null, $altDBDetails = $null, $targetLocation = "H:\temp",  $RestoreSecurity = $false, $rollForwardRecovery = #$false, $leaveDBInRestoringState = $false, $copyLogFiles = $false, $logFilesCopyLocation = "F:\Temp"
    $RecoveryOption = New-RecoveryOption -TargetServer $targetserver -RecoveryLocation $recoveryLocation -SQL `
      -AlternateDatabaseDetails $altDBDetails -RestoreSecurity:$RestoreSecurity `
      -RecoveryType $restoreType -TargetLocation $targetLocation `
    $j = Recover-RecoverableItem -RecoverableItem $RecoverAbleItem -RecoveryOption $RecoveryOption

    Hope this helps


    Thanks, Hitesh “This posting is provided "AS IS" with no warranties, and confers no rights.”
    • Proposed as answer by Hitesh S Sharma Thursday, February 10, 2011 9:05 AM
    Thursday, February 10, 2011 9:04 AM
  • Hi ND82,


    Did the post from Hitesh answered your question?

    Thanks, Wilson Souza - MSFT This posting is provided "AS IS" with no warranties, and confers no rights
    Friday, May 20, 2011 9:55 PM