none
How to force offline VM backup? RRS feed

  • Question

  • Really simple question:

    I have a HyperV vm, which hosts a rather complex application, and I do not trust that application to support consistent online backup. Fortunately I have no problem with a bit of nightly downtime, so I simply want DPM to take backups with the vm in its shutdown state.

    How do I accomplish that?

    Can I instruct DPM to instruct the vm to shut down before backup and start up again after?

    Or will I have to script the shutdown and startup actions (no problem)? If so: How to assure that the scripts run at the appropriate times.

    And more fundamentally: Does DPM event support offline VM backups. I mean: I tried just manually shutting down a protected VM and DPM still created the recovery point without failing, but what will happen if I try to restore it?

    Environment:

    Windows Server 2008 R2 sp1 for DPM Server, Hyper-V hosts and VMs, DPM 2012, 2 node failover cluster on Equallogic SAN without hardware VSS provider

    Thursday, July 5, 2012 1:40 PM

Answers

  • Hi,

    Thanks for the clarification, so you can use pre and post backup scripts to shutdows / start the VM at the time of the backup.

    Leveraging these two sources, you should be able to make that happen.

    Using Pre-Backup and Post-Backup Scripts
    http://technet.microsoft.com/en-us/library/bb808870.aspx

    <?xml version="1.0" encoding="utf-8"?>
    <ScriptConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns="http://schemas.microsoft.com/2003/dls/ScriptingConfig.xsd">
    <DatasourceScriptConfig DataSourceName="Backup Using Child Partition Snapshot\VM_Name_Here">     
    <PreBackupScript>C:\Stop.cmd </PreBackupScript>
    <PostBackupScript>C:\Start.cmd </PostBackupScript>
    <TimeOut>30</TimeOut>
    </DatasourceScriptConfig>
    </ScriptConfiguration>

    stop.cmd
    cscript mystopscript.vbs

    start.cmd
    cscript mystartscript.vbs

    http://blogs.msdn.com/b/virtual_pc_guy/archive/2008/01/29/starting-a-hyper-v-virtual-machine.aspx


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. Regards, Mike J. [MSFT] This posting is provided "AS IS" with no warranties, and confers no rights.

    • Marked as answer by ThomasIsr Sunday, July 8, 2012 12:10 PM
    Friday, July 6, 2012 12:04 AM
    Moderator
  • Hello,

    I had the same problem and discovered that for some reason DPM is looking for the VM ComponentName, not the datasource name like it does for other workloads. 

    Open SQL Management Studio and connect to the DPM instance, and then run one of the following SQL Queries.

    Use dpmdb
    select Componentname,Caption from tbl_RM_RecoverableObject
    where Caption like cast ('%Backup Using Child Partition Snapshot\VMNAME%' as ntext)

    -OR-

    use dpmdb
    select ComponentName,caption from tbl_RM_RecoverableObject
    where Caption like cast ('%Backup Using%' as ntext)
    order by cast (Caption as nvarchar)

    <SAMPLE OUTPUT>
    ComponentName                                             caption
    6AD686AB-FA27-4C50-8691-EF32331D95D2    Backup Using Child Partition Snapshot\OpenManage

    Then use the ComponentName for the desired VM in the ScriptingConfig.xml like in my sample below.

    <?xml version="1.0" encoding="utf-8"?>
    <ScriptConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema"
     xmlns="http://schemas.microsoft.com/2003/dls/ScriptingConfig.xsd">
     <DatasourceScriptConfig DataSourceName="6AD686AB-FA27-4C50-8691-EF32331D95D2">
      <PreBackupScript>c:\StopTFS.cmd </PreBackupScript>
      <PostBackupScript>c:\StartTFS.cmd </PostBackupScript>
      <TimeOut>10</TimeOut>
     </DatasourceScriptConfig>
    </ScriptConfiguration>


     


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. Regards, Mike J. [MSFT] This posting is provided "AS IS" with no warranties, and confers no rights.

    • Marked as answer by ThomasIsr Sunday, July 8, 2012 12:10 PM
    Friday, July 6, 2012 11:25 PM
    Moderator
  • That did the trick. I got it working.

    It took a lot of trial and error though. In the end I went with powershell scripts againt the Hyper-V WMI stuff. Initially I tried with the much friendlier native powershell cmdlets from SCVMM, but they need to run under an account which can access the SCVMM server, and the DPM scripts run as localsystem. So that was a no go.

    Also: I couldn't get relative paths to work anywhere, so it's just full paths everywhere.

    I used this article for startup and graceful shutdown of vms: http://social.technet.microsoft.com/wiki/contents/articles/2237.hyper-v-powershell-and-wmi-en-us.aspx, as I think the simpler shutdown method in the article quoted above does a brutal "turn off".

    For reference, here are the full components of the solution.

    In "C:\Program Files\Microsoft Data Protection Manager\DPM\Scripting\ScriptingConfig.xml" on both hosts in my cluster:

    <?xml version="1.0" encoding="utf-8"?>
    <ScriptConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema"
     xmlns="http://schemas.microsoft.com/2003/dls/ScriptingConfig.xsd">
    	<DatasourceScriptConfig DataSourceName="F37ED547-57A3-482B-891E-26E1949D4AAF">
    		<PreBackupScript>C:\Program Files\Microsoft Data Protection Manager\DPM\Scripting\StopTFS.cmd </PreBackupScript>
    		<PostBackupScript>"C:\Program Files\Microsoft Data Protection Manager\DPM\Scripting\StartTFS.cmd "</PostBackupScript>
    		<TimeOut>2</TimeOut>
    	</DatasourceScriptConfig>
    </ScriptConfiguration>

    StopTFS.cmd:

    powershell.exe -File "C:\Program Files\Microsoft Data Protection Manager\DPM\Scripting\stopTFS.ps1" >> "C:\Program Files\Microsoft Data Protection Manager\DPM\Scripting\StopLog.txt"

    stopTFS.ps1:

    $vmName = "TFS2010"
    
    write-host "Shutting down $vm for system maintenance"  
     
    # Get the VM by name and request state to change to Enabled   
    $vm = gwmi -namespace root\virtualization Msvm_ComputerSystem -filter "ElementName='$vmName'"   
        
    # Get the associated Shutdown Component   
    $shutdown = gwmi -namespace root\virtualization  -query "Associators of {$vm} where ResultClass=Msvm_ShutdownComponent"   
    
    if (! $shutdown ) 
    {
       write-host "Virtual machine $vmName is already shut down."  
    } 
    else 
    {
      # Initiate a forced shutdown with simple reason string, return resulting error code   
      return $shutdown.InitiateShutdown($true,"Backup") 
    }

    StartTFS.cmd:

    powershell.exe -File "C:\Program Files\Microsoft Data Protection Manager\DPM\Scripting\startTFS.ps1" >> "C:\Program Files\Microsoft Data Protection Manager\DPM\Scripting\StartLog.txt"

    startTFS.ps1:

    $vmName = "TFS2010"
      
    $vm = gwmi -namespace root\virtualization Msvm_ComputerSystem -filter "ElementName='$vmName' " 
     
    if ( $vm.EnabledState -eq 2 ) 
    {  
      write-host "The virtual machine $vmName is already running."  
    } 
    else 
    {   
      $vm.RequestStateChange(2)  
    }  

    In the DPM Protection group I made sure that it absolutely only executes the Express Full Backup once per night. No sync'ing and no consistency checks, which would also force the scipts to run. The scripts were in place as DPM created the initial replica and did their thing.

    All I have to do now is a trial restore.

    Thanks for all your help Mike!

    • Edited by ThomasIsr Sunday, July 8, 2012 12:09 PM
    • Marked as answer by ThomasIsr Sunday, July 8, 2012 12:11 PM
    Sunday, July 8, 2012 12:05 PM

All replies

  • Hi,

    Yes, DPM does support offline backups of VM (VM's in a saved or off state).  You can force saved state backups simply by unchecking the Intergration Services setting called (backup (volume snapshot) in the settings of that VM.  All future backups will put the machine in a saved state for  the DPM backup snapshot and then immediatly bring the machine back online.  The application inside will not know anything happened.


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. Regards, Mike J. [MSFT] This posting is provided "AS IS" with no warranties, and confers no rights.

    Thursday, July 5, 2012 9:39 PM
    Moderator
  • Mike: Thanks for the quick reply.

    I am actually aware of the saved state option - I guess I should have made that clear.

    My understanding though is that "saved state" is not really offline. The VM will still be live (although unavailable to clients - but it will not really know that) since the saved state will include a snapshot of VM memory.

    Hence, I am a bit worried about what would happen if I - at some point in time - restore a saved state snapshot. For example: Maybe that VM was in the middle of some complex authetication operation with a domain controller when its state was saved. And maybe that domain controller has been decommissioned in the mean time or maybe it is just being serviced or whatever.

    That is why my post focused on getting the vm fully shut down.

    Thomas

    Thursday, July 5, 2012 10:46 PM
  • Hi,

    Thanks for the clarification, so you can use pre and post backup scripts to shutdows / start the VM at the time of the backup.

    Leveraging these two sources, you should be able to make that happen.

    Using Pre-Backup and Post-Backup Scripts
    http://technet.microsoft.com/en-us/library/bb808870.aspx

    <?xml version="1.0" encoding="utf-8"?>
    <ScriptConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns="http://schemas.microsoft.com/2003/dls/ScriptingConfig.xsd">
    <DatasourceScriptConfig DataSourceName="Backup Using Child Partition Snapshot\VM_Name_Here">     
    <PreBackupScript>C:\Stop.cmd </PreBackupScript>
    <PostBackupScript>C:\Start.cmd </PostBackupScript>
    <TimeOut>30</TimeOut>
    </DatasourceScriptConfig>
    </ScriptConfiguration>

    stop.cmd
    cscript mystopscript.vbs

    start.cmd
    cscript mystartscript.vbs

    http://blogs.msdn.com/b/virtual_pc_guy/archive/2008/01/29/starting-a-hyper-v-virtual-machine.aspx


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. Regards, Mike J. [MSFT] This posting is provided "AS IS" with no warranties, and confers no rights.

    • Marked as answer by ThomasIsr Sunday, July 8, 2012 12:10 PM
    Friday, July 6, 2012 12:04 AM
    Moderator
  • Thanks! will try.

    Do I just place the script files next to ScriptingConfig.xml?

    Also: Any special considerations for failover Hyper-V clusters? I figure I would just create identical scripts and xml files on both cluster nodes.

    Friday, July 6, 2012 1:36 PM
  • Hi,

    Yes, you can place them there - you can try this and if that doesn't work provide full path.

    <PreBackupScript>.\Stop.cmd </PreBackupScript>
    <PostBackupScript>.\Start.cmd </PostBackupScript>

    Yes, the files need to be on all nodes in the same location.


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. Regards, Mike J. [MSFT] This posting is provided "AS IS" with no warranties, and confers no rights.

    Friday, July 6, 2012 2:18 PM
    Moderator
  • OK. I have built my scripts and verified that they work if I just run them from a command prompt. I have also put together ScriptingConfig.xml. And I have distributed everything on both cluster nodes.

    But when I kick off a manual recovery point for the protected VM, it just does it's usual live backup - as if it is completely ignoring ScriptingConfig.xml

    Here is ScriptingConfig.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <ScriptConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema"
     xmlns="http://schemas.microsoft.com/2003/dls/ScriptingConfig.xsd">
    	<DatasourceScriptConfig DataSourceName="Backup Using Child Partition Snapshot\OpenManage">
    		<PreBackupScript>c:\StopTFS.cmd </PreBackupScript>
    		<PostBackupScript>c:\StartTFS.cmd </PostBackupScript>
    		<TimeOut>10</TimeOut>
    	</DatasourceScriptConfig>
    </ScriptConfiguration>

    Any ideas as to why it isn't working?
    • Edited by ThomasIsr Saturday, July 7, 2012 10:55 AM typo
    Friday, July 6, 2012 6:45 PM
  • Hello,

    I had the same problem and discovered that for some reason DPM is looking for the VM ComponentName, not the datasource name like it does for other workloads. 

    Open SQL Management Studio and connect to the DPM instance, and then run one of the following SQL Queries.

    Use dpmdb
    select Componentname,Caption from tbl_RM_RecoverableObject
    where Caption like cast ('%Backup Using Child Partition Snapshot\VMNAME%' as ntext)

    -OR-

    use dpmdb
    select ComponentName,caption from tbl_RM_RecoverableObject
    where Caption like cast ('%Backup Using%' as ntext)
    order by cast (Caption as nvarchar)

    <SAMPLE OUTPUT>
    ComponentName                                             caption
    6AD686AB-FA27-4C50-8691-EF32331D95D2    Backup Using Child Partition Snapshot\OpenManage

    Then use the ComponentName for the desired VM in the ScriptingConfig.xml like in my sample below.

    <?xml version="1.0" encoding="utf-8"?>
    <ScriptConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema"
     xmlns="http://schemas.microsoft.com/2003/dls/ScriptingConfig.xsd">
     <DatasourceScriptConfig DataSourceName="6AD686AB-FA27-4C50-8691-EF32331D95D2">
      <PreBackupScript>c:\StopTFS.cmd </PreBackupScript>
      <PostBackupScript>c:\StartTFS.cmd </PostBackupScript>
      <TimeOut>10</TimeOut>
     </DatasourceScriptConfig>
    </ScriptConfiguration>


     


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. Regards, Mike J. [MSFT] This posting is provided "AS IS" with no warranties, and confers no rights.

    • Marked as answer by ThomasIsr Sunday, July 8, 2012 12:10 PM
    Friday, July 6, 2012 11:25 PM
    Moderator
  • That did the trick. I got it working.

    It took a lot of trial and error though. In the end I went with powershell scripts againt the Hyper-V WMI stuff. Initially I tried with the much friendlier native powershell cmdlets from SCVMM, but they need to run under an account which can access the SCVMM server, and the DPM scripts run as localsystem. So that was a no go.

    Also: I couldn't get relative paths to work anywhere, so it's just full paths everywhere.

    I used this article for startup and graceful shutdown of vms: http://social.technet.microsoft.com/wiki/contents/articles/2237.hyper-v-powershell-and-wmi-en-us.aspx, as I think the simpler shutdown method in the article quoted above does a brutal "turn off".

    For reference, here are the full components of the solution.

    In "C:\Program Files\Microsoft Data Protection Manager\DPM\Scripting\ScriptingConfig.xml" on both hosts in my cluster:

    <?xml version="1.0" encoding="utf-8"?>
    <ScriptConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema"
     xmlns="http://schemas.microsoft.com/2003/dls/ScriptingConfig.xsd">
    	<DatasourceScriptConfig DataSourceName="F37ED547-57A3-482B-891E-26E1949D4AAF">
    		<PreBackupScript>C:\Program Files\Microsoft Data Protection Manager\DPM\Scripting\StopTFS.cmd </PreBackupScript>
    		<PostBackupScript>"C:\Program Files\Microsoft Data Protection Manager\DPM\Scripting\StartTFS.cmd "</PostBackupScript>
    		<TimeOut>2</TimeOut>
    	</DatasourceScriptConfig>
    </ScriptConfiguration>

    StopTFS.cmd:

    powershell.exe -File "C:\Program Files\Microsoft Data Protection Manager\DPM\Scripting\stopTFS.ps1" >> "C:\Program Files\Microsoft Data Protection Manager\DPM\Scripting\StopLog.txt"

    stopTFS.ps1:

    $vmName = "TFS2010"
    
    write-host "Shutting down $vm for system maintenance"  
     
    # Get the VM by name and request state to change to Enabled   
    $vm = gwmi -namespace root\virtualization Msvm_ComputerSystem -filter "ElementName='$vmName'"   
        
    # Get the associated Shutdown Component   
    $shutdown = gwmi -namespace root\virtualization  -query "Associators of {$vm} where ResultClass=Msvm_ShutdownComponent"   
    
    if (! $shutdown ) 
    {
       write-host "Virtual machine $vmName is already shut down."  
    } 
    else 
    {
      # Initiate a forced shutdown with simple reason string, return resulting error code   
      return $shutdown.InitiateShutdown($true,"Backup") 
    }

    StartTFS.cmd:

    powershell.exe -File "C:\Program Files\Microsoft Data Protection Manager\DPM\Scripting\startTFS.ps1" >> "C:\Program Files\Microsoft Data Protection Manager\DPM\Scripting\StartLog.txt"

    startTFS.ps1:

    $vmName = "TFS2010"
      
    $vm = gwmi -namespace root\virtualization Msvm_ComputerSystem -filter "ElementName='$vmName' " 
     
    if ( $vm.EnabledState -eq 2 ) 
    {  
      write-host "The virtual machine $vmName is already running."  
    } 
    else 
    {   
      $vm.RequestStateChange(2)  
    }  

    In the DPM Protection group I made sure that it absolutely only executes the Express Full Backup once per night. No sync'ing and no consistency checks, which would also force the scipts to run. The scripts were in place as DPM created the initial replica and did their thing.

    All I have to do now is a trial restore.

    Thanks for all your help Mike!

    • Edited by ThomasIsr Sunday, July 8, 2012 12:09 PM
    • Marked as answer by ThomasIsr Sunday, July 8, 2012 12:11 PM
    Sunday, July 8, 2012 12:05 PM