none
Powershell Restoring VM's to different hyper-v server but the same folder each time RRS feed

  • Question

  • hi, is there a way to get the vhd's restored to the same location each time without having the time and date on it.

     

    basically on our secondary dpm server i want to run a powershell script will restore all the vm's i have to a standby hyper-v server, the hyper-v server will have all the virtual machines created already and configured etc... all i need to do is restore the latest vhd's once a month, and then i can restore the latest application data into it....

    i cant seem to figure a way out of this, other than restoring and then use the move-item command in dpm to move the vhds once restored....

    any advice greatly appreciated!

     

    if not can we find the variable to where the recovery location is stored so i can process it with the move-item command...?

     

     


    John
    Monday, October 4, 2010 4:04 PM

Answers

  • John,

    I'm afraid the move-item workaround currently is the only way


    \R2 This posting is provided "AS IS" with no warranties, and confers no rights
    Thursday, October 7, 2010 6:38 PM

All replies

  • John,

    I'm afraid the move-item workaround currently is the only way


    \R2 This posting is provided "AS IS" with no warranties, and confers no rights
    Thursday, October 7, 2010 6:38 PM
  • If the above suggested answer do not help in resolving the thread please re-open it.
    Cheers, Tyler F [MSFT] - This posting is provided "AS IS" with no warranties, and confers no rights.
    Friday, October 8, 2010 5:07 PM
    Moderator
  • Hi, I don't know if this can help you, but here what I use to dump every VHD/VM/systemState from my DPM server to a folder on a network drive (for tape export purpose)

    this will create a folder for each VM, you will have to play with this folder in order to copy the VHD to the correct destination folder

    -------------

    Add-PSSnapin Microsoft.DataProtectionManager.PowerShell
    
    # ================== 
    #Variables 
    # ================== 
    $DPMServerName = "SVRDPM" 
    $DestinationServerName = "SVRBKP"
    $DestinationDrive="D"
    $DVHD="\dump-VHD\"
    $WaitUntilFinish = $true
    $objtypeVHD = "Hyper-V"
    
    Start-transcript -path c:\TEMP\dpm.txt
    
    $destinationVHD=$DestinationDrive + ":" + $DVHD
    
    if (!(Connect-DPMServer $DPMServerName)) 
    { 
     Write-Error "Le serveur $DPMServerName n'est pas disponible" 
     exit 1 
    }
    
    #Récupération des groupes de protection
    $pgroup = Get-ProtectionGroup $DPMServerName 
    
    if(!$pgroup) 
    { 
     Write-Host "Ce serveur ne contient pas de groupe de protections" 
     exit 1 
    }
    
    foreach ($pg in $pgroup)
    {
    write-host "Analyse du groupe de récupération : " $pg.Friendlyname
    
    $ds = Get-Datasource $pg
    
    if(!$ds) 
    { 
     Write-Host "Erreur!!!" 
     exit 1 
    }
    
    foreach ($datasource in $ds) 
    
    {  
     Write-Host $datasource.type.name 
     Write-Host $datasource.name 
     if ($datasource.type.name -eq $objtypeVHD)
     { 
      foreach ($rp in @(Get-RecoveryPoint -Datasource $datasource | sort -Property RepresentedPointInTime -Descending)) 
      { 
        foreach ($rsl in $rp.RecoverySourceLocations) 
        { 
         if ($rsl -is [Microsoft.Internal.EnterpriseStorage.Dls.UI.ObjectModel.OMCommon.ReplicaDataset]) 
         { 
    
     		if ($datasource.type.name -eq $objtypeVHD) 
    			{
          		 $recoveryOption = New-RecoveryOption -HyperVDatasource -TargetServer $DestinationServerName -RecoveryLocation CopyToFolder -TargetLocation $DestinationVHD -RecoveryType Restore
          		}
    	  
          $restoreJob = Recover-RecoverableItem -RecoverableItem $rp -RecoveryOption $recoveryOption -RecoveryPointLocation $rsl
          
          break 
         } 
        }
     
       if ($restoreJob) 
       { 
        break 
       } 
      }
    
      if ($restoreJob) 
      { 
       if ($WaitUntilFinish)
       {
        while (!$restoreJob.HasCompleted) 
        { 
         Write-Host "." -NoNewLine 
         sleep 3 
        }
       }
      } 
      else 
      { 
       Write-Error "Restauration impossible ($($datasource.LogicalPath))" 
      }
     
     }
    }
    }
    
    Stop-transcript
    -------------

    this script serve my purpose, in your case I would advise to check out this line :

    -------------

    $recoveryOption = New-RecoveryOption -HyperVDatasource -TargetServer $DestinationServerName -RecoveryLocation CopyToFolder -TargetLocation $DestinationVHD -RecoveryType Restore

    -------------

    I think you can modify the "Recovery Location" parameters and set it up with the second Hyper-V

     

    you can also play with line, instead of doing a foreach, you can get the first entry of Get-RecoveryPoint with the descending sort order

    -------------
        foreach ($rp in @(Get-RecoveryPoint -Datasource $datasource | sort -Property RepresentedPointInTime -Descending))
    -------------

    hope that helps

    Christophe

    Tuesday, October 12, 2010 1:18 PM