none
Powershell Restore going to wrong drive letter RRS feed

  • Question

  • I'm working on a powershell script to do a weekly restore of data (will eventually turn it into a function).  I have the restore working fine with one exception.  When it goes to restore filesystem data the restoration path chooses the wrong drive letter.  However, when I use the same script to restore sql data the drive path is fine.  When restoring file data, instead of restoring to the G:\San Restores, it increments the drive letter and restores to H:\San Restores.  Any help would be appreciated.  Here is the current state of the script:

    Import-Module DataProtectionManager

    #Set Variables
    $DPMServerName = "%DPMServerName%"
    $RestoreSourceProtectionGroup = "%ProtectionGroupName%"
    $RestoreSourceComputer = "%SourceComputerName%"
    $RestoreDataType = "FileSystem"
    $RestoreDestinationServer = "%DestinationComputerName%"
    $RestoreDestination = "G:\San Restores\"

    #Get Protection Group to be Restored
    $RestoreProtectionGroup = Get-ProtectionGroup $DPMServerName | Where-Object {$_.FriendlyName -eq $RestoreSourceProtectionGroup}

    #Get the Data Sources for the $RestoreProtectionGroup
    $RestoreDatasource = Get-DataSource -ProtectionGroup $RestoreProtectionGroup | Where-Object {$_.ProductionServerName -eq $RestoreSourceComputer}

    #Set the Restore Destination Path

    $RestoreDestinationPath = $RestoreSourceComputer.Replace(".%LocalDomainName%","") + "\"
    $RestoreDestinationPath = $RestoreDestinationPath + $RestoreDataSource[0].name
    $RestoreDestinationPath = $RestoreDestinationPath.Replace(":\","") #Remove any potential drive letter format problems
    $RestoreDestinationPath = $RestoreDestination + $RestoreDestinationPath

    #Get Latest Recovery Point for the Data Source
    If ($RestoreDataType -eq "FileSystem")
        {
            $RecoveryPoints = Get-DPMRecoveryPoint -DataSource $RestoreDatasource[0]
            $RestorePoint = $RecoveryPoints[-1]
        }
        Elseif ($RestoreDataType -eq "SQL")
        {
            $RecoveryPoints = Get-DPMRecoveryPoint -DataSource $RestoreDataSource[0] | Where-Object {$_.HasFastRecoveryMarker}
            $RestorePoint = $RecoveryPoints[-1]
        }

    #Format the proper recovery option
    If ($RestoreDataType -eq "FileSystem")
        {
        $RecoveryOption = New-DPMRecoveryOption -TargetServer $RestoreDestinationServer -RecoveryLocation copytofolder -Filesystem -AlternateLocation $RestoreDestinationPath -OverwriteType overwrite -RecoveryType Restore
        }
        Elseif ($RestoreDataType -eq "SQL")
        {
        $RecoveryOption = New-DPMRecoveryOption -SQL -TargetServer $RestoreDestinationServer -RecoveryLocation copytofolder -RecoveryType Restore -TargetLocation $RestoreDestinationPath   
        }  
          
    #Restore the actual Data
    $RestoreJob = Restore-DPMRecoverableItem -RecoverableItem $RestorePoint -RecoveryOption $RecoveryOption

    Wednesday, July 17, 2013 7:39 PM

All replies

  • Works perfectly for me :\

    I tried restoring the E:\ drive of a fileserver to the C:\ drive of another server

    Other than that the only thing I changed was the $RestorePoint = $RecoveryPoints[-1] - I changed this to $RestorePoint = $RecoveryPoints[0] to grab the 1st disk recovery point. Thats just to suit my environment though and wont have affected anything.

    Are you sure the restoredestinationpath is being construced correctly on the server that is failing before it is used? I assume the FileSystem datatype is being used on a fileserver/folder etc and not on an exchange db/hyper-V/sql db etc

    Coming back to the driver better being incremented ...the drive letter that is actually chosen, is this the source drive letter of the protected datasource?

    Thursday, July 18, 2013 11:42 AM
  • I have verified everything out of this script line by line.

    1)  I have even run the script up to the restore job and verified that the $RecoveryOption has the correct values set. 

    2)  I have verified that I am restoring the correct datatype

    3)  I have changed the restore path different drive letters.

    4)  I have selected different recovery points for restoration.

    But when I actually run the restore job it goes to the next drive letter.  However, when I change the datatype to SQL (and obviously use a sql recovery point) the script works fine.  It seems to only behave this way when restore files/folders.

    If this script works for others, it makes me wonder if the problem is more of a machine problem than script problem.....Puzzling.....



    • Edited by Ian.Davies Thursday, July 18, 2013 3:03 PM edit
    Thursday, July 18, 2013 2:59 PM
  • I find it very strange that the drive letter increments! That is confusing.

    Bit of a long shot and I cant see how it would help but you can try swapping your Restore-DPMRecoverableItem cmdlet with Recover-RecoverableItem -RecoverableItem $RestorePoint -RecoveryOption $RecoveryOption

    Thursday, July 18, 2013 4:39 PM
  • I originally used Recover-RecoverableItem, however it just calls Restore-DPMRecoverableItem.

    I have fixed it temporarily by mounting the restore drive with the drive letter "Z".  At this point I'm going to work on finishing the script:

    1)  Finish adding the rest of the data types that I need to restore.

    2)  Turn script into a function so I can automate a restore schedule

    Once those items have been finished I will revisit the really weird drive letter issue.  I'm assuming it will pop its head up again.  If your interested I will post the completed script when I'm done.

    Thursday, July 18, 2013 4:54 PM
  • Yeah please post it. It'll be useful for others I am sure.

    The other thing you culd try and I'm not sure if it'll show anything or not ...sometimes it does but it might be worth turning on verbose logging on when you do your restore ...could give you a clue as to what is going on with the incrementing of drive letters.

    Cheers

    Friday, July 19, 2013 6:42 AM